summaryrefslogtreecommitdiff
path: root/ethtool.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2009-03-06 06:12:13 -0500
committerJeff Garzik <jgarzik@redhat.com>2009-03-06 06:12:13 -0500
commita97a2ece26d1e88171d7b2f0824686fcd4a15a0c (patch)
tree3982211e653b72c17ebb31569a267626937ee2fe /ethtool.c
parentb161802dd86ecb417f5464c588620d1910a64f93 (diff)
downloadethtool-a97a2ece26d1e88171d7b2f0824686fcd4a15a0c.tar.gz
Merge several minor changes from Debian.
Namely, wrap ioctl send so that Debian can more easily support kernels older than 2.4.x. We don't support that, but they wish to. Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'ethtool.c')
-rw-r--r--ethtool.c90
1 files changed, 49 insertions, 41 deletions
diff --git a/ethtool.c b/ethtool.c
index 1ec560d..1b14091 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -37,10 +37,12 @@
#include <string.h>
#include <errno.h>
#include <net/if.h>
+#include <sys/utsname.h>
#include <linux/sockios.h>
#include "ethtool-util.h"
+
#ifndef SIOCETHTOOL
#define SIOCETHTOOL 0x8946
#endif
@@ -75,6 +77,7 @@ static char *unparse_rxfhashopts(u64 opts);
static int dump_rxfhash(int fhash, u64 val);
static int do_srxclass(int fd, struct ifreq *ifr);
static int do_grxclass(int fd, struct ifreq *ifr);
+static int send_ioctl(int fd, struct ifreq *ifr);
static enum {
MODE_HELP = -1,
@@ -1461,7 +1464,7 @@ static int dump_rxfhash(int fhash, u64 val)
fprintf(stdout, " use these fields for computing Hash flow key:\n");
fprintf(stdout, "%s\n", unparse_rxfhashopts(val));
-
+
return 0;
}
@@ -1534,7 +1537,7 @@ static int do_gdrv(int fd, struct ifreq *ifr)
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr->ifr_data = (caddr_t)&drvinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get driver information");
return 71;
@@ -1550,7 +1553,7 @@ static int do_gpause(int fd, struct ifreq *ifr)
epause.cmd = ETHTOOL_GPAUSEPARAM;
ifr->ifr_data = (caddr_t)&epause;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
err = dump_pause();
if (err)
@@ -1598,7 +1601,7 @@ static int do_spause(int fd, struct ifreq *ifr)
epause.cmd = ETHTOOL_GPAUSEPARAM;
ifr->ifr_data = (caddr_t)&epause;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot get device pause settings");
return 77;
@@ -1613,7 +1616,7 @@ static int do_spause(int fd, struct ifreq *ifr)
epause.cmd = ETHTOOL_SPAUSEPARAM;
ifr->ifr_data = (caddr_t)&epause;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device pause parameters");
return 79;
@@ -1628,7 +1631,7 @@ static int do_sring(int fd, struct ifreq *ifr)
ering.cmd = ETHTOOL_GRINGPARAM;
ifr->ifr_data = (caddr_t)&ering;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot get device ring settings");
return 76;
@@ -1643,7 +1646,7 @@ static int do_sring(int fd, struct ifreq *ifr)
ering.cmd = ETHTOOL_SRINGPARAM;
ifr->ifr_data = (caddr_t)&ering;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device ring parameters");
return 81;
@@ -1660,7 +1663,7 @@ static int do_gring(int fd, struct ifreq *ifr)
ering.cmd = ETHTOOL_GRINGPARAM;
ifr->ifr_data = (caddr_t)&ering;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
err = dump_ring();
if (err)
@@ -1681,7 +1684,7 @@ static int do_gcoalesce(int fd, struct ifreq *ifr)
ecoal.cmd = ETHTOOL_GCOALESCE;
ifr->ifr_data = (caddr_t)&ecoal;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
err = dump_coalesce();
if (err)
@@ -1700,7 +1703,7 @@ static int do_scoalesce(int fd, struct ifreq *ifr)
ecoal.cmd = ETHTOOL_GCOALESCE;
ifr->ifr_data = (caddr_t)&ecoal;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot get device coalesce settings");
return 76;
@@ -1716,7 +1719,7 @@ static int do_scoalesce(int fd, struct ifreq *ifr)
ecoal.cmd = ETHTOOL_SCOALESCE;
ifr->ifr_data = (caddr_t)&ecoal;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device coalesce parameters");
return 81;
@@ -1735,7 +1738,7 @@ static int do_goffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_GRXCSUM;
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err)
perror("Cannot get device rx csum settings");
else {
@@ -1745,7 +1748,7 @@ static int do_goffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_GTXCSUM;
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err)
perror("Cannot get device tx csum settings");
else {
@@ -1755,7 +1758,7 @@ static int do_goffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_GSG;
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err)
perror("Cannot get device scatter-gather settings");
else {
@@ -1765,7 +1768,7 @@ static int do_goffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_GTSO;
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err)
perror("Cannot get device tcp segmentation offload settings");
else {
@@ -1831,7 +1834,7 @@ static int do_soffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_SRXCSUM;
eval.data = (off_csum_rx_wanted == 1);
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device rx csum settings");
return 84;
@@ -1843,7 +1846,7 @@ static int do_soffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_STXCSUM;
eval.data = (off_csum_tx_wanted == 1);
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device tx csum settings");
return 85;
@@ -1855,7 +1858,7 @@ static int do_soffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_SSG;
eval.data = (off_sg_wanted == 1);
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device scatter-gather settings");
return 86;
@@ -1867,7 +1870,7 @@ static int do_soffload(int fd, struct ifreq *ifr)
eval.cmd = ETHTOOL_STSO;
eval.data = (off_tso_wanted == 1);
ifr->ifr_data = (caddr_t)&eval;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err) {
perror("Cannot set device tcp segmentation offload settings");
return 88;
@@ -1949,7 +1952,7 @@ static int do_gset(int fd, struct ifreq *ifr)
ecmd.cmd = ETHTOOL_GSET;
ifr->ifr_data = (caddr_t)&ecmd;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
err = dump_ecmd(&ecmd);
if (err)
@@ -1961,7 +1964,7 @@ static int do_gset(int fd, struct ifreq *ifr)
wolinfo.cmd = ETHTOOL_GWOL;
ifr->ifr_data = (caddr_t)&wolinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
err = dump_wol(&wolinfo);
if (err)
@@ -1973,7 +1976,7 @@ static int do_gset(int fd, struct ifreq *ifr)
edata.cmd = ETHTOOL_GMSGLVL;
ifr->ifr_data = (caddr_t)&edata;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
fprintf(stdout, " Current message level: 0x%08x (%d)\n",
edata.data, edata.data);
@@ -1984,7 +1987,7 @@ static int do_gset(int fd, struct ifreq *ifr)
edata.cmd = ETHTOOL_GLINK;
ifr->ifr_data = (caddr_t)&edata;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err == 0) {
fprintf(stdout, " Link detected: %s\n",
edata.data ? "yes":"no");
@@ -2009,7 +2012,7 @@ static int do_sset(int fd, struct ifreq *ifr)
ecmd.cmd = ETHTOOL_GSET;
ifr->ifr_data = (caddr_t)&ecmd;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get current device settings");
} else {
@@ -2044,7 +2047,7 @@ static int do_sset(int fd, struct ifreq *ifr)
/* Try to perform the update. */
ecmd.cmd = ETHTOOL_SSET;
ifr->ifr_data = (caddr_t)&ecmd;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0)
perror("Cannot set new settings");
}
@@ -2069,7 +2072,7 @@ static int do_sset(int fd, struct ifreq *ifr)
wol.cmd = ETHTOOL_GWOL;
ifr->ifr_data = (caddr_t)&wol;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get current wake-on-lan settings");
} else {
@@ -2087,7 +2090,7 @@ static int do_sset(int fd, struct ifreq *ifr)
/* Try to perform the update. */
wol.cmd = ETHTOOL_SWOL;
ifr->ifr_data = (caddr_t)&wol;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0)
perror("Cannot set new wake-on-lan settings");
}
@@ -2105,7 +2108,7 @@ static int do_sset(int fd, struct ifreq *ifr)
edata.cmd = ETHTOOL_SMSGLVL;
edata.data = msglvl_wanted;
ifr->ifr_data = (caddr_t)&edata;;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0)
perror("Cannot set new msglvl");
}
@@ -2121,7 +2124,7 @@ static int do_gregs(int fd, struct ifreq *ifr)
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr->ifr_data = (caddr_t)&drvinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get driver information");
return 72;
@@ -2135,7 +2138,7 @@ static int do_gregs(int fd, struct ifreq *ifr)
regs->cmd = ETHTOOL_GREGS;
regs->len = drvinfo.regdump_len;
ifr->ifr_data = (caddr_t)regs;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get register dump");
free(regs);
@@ -2158,7 +2161,7 @@ static int do_nway_rst(int fd, struct ifreq *ifr)
edata.cmd = ETHTOOL_NWAY_RST;
ifr->ifr_data = (caddr_t)&edata;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0)
perror("Cannot restart autonegotiation");
@@ -2173,7 +2176,7 @@ static int do_geeprom(int fd, struct ifreq *ifr)
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr->ifr_data = (caddr_t)&drvinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get driver information");
return 74;
@@ -2194,7 +2197,7 @@ static int do_geeprom(int fd, struct ifreq *ifr)
eeprom->len = geeprom_length;
eeprom->offset = geeprom_offset;
ifr->ifr_data = (caddr_t)eeprom;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get EEPROM data");
free(eeprom);
@@ -2220,7 +2223,7 @@ static int do_seeprom(int fd, struct ifreq *ifr)
edata.eeprom.magic = seeprom_magic;
edata.data = seeprom_value;
ifr->ifr_data = (caddr_t)&edata.eeprom;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot set EEPROM data");
return 87;
@@ -2238,7 +2241,7 @@ static int do_test(int fd, struct ifreq *ifr)
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr->ifr_data = (caddr_t)&drvinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get driver information");
return 72;
@@ -2257,7 +2260,7 @@ static int do_test(int fd, struct ifreq *ifr)
else
test->flags = 0;
ifr->ifr_data = (caddr_t)test;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot test");
free (test);
@@ -2276,7 +2279,7 @@ static int do_test(int fd, struct ifreq *ifr)
strings->string_set = ETH_SS_TEST;
strings->len = drvinfo.testinfo_len;
ifr->ifr_data = (caddr_t)strings;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get strings");
free (test);
@@ -2298,7 +2301,7 @@ static int do_phys_id(int fd, struct ifreq *ifr)
edata.cmd = ETHTOOL_PHYS_ID;
edata.data = phys_id_time;
ifr->ifr_data = (caddr_t)&edata;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0)
perror("Cannot identify NIC");
@@ -2315,7 +2318,7 @@ static int do_gstats(int fd, struct ifreq *ifr)
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr->ifr_data = (caddr_t)&drvinfo;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get driver information");
return 71;
@@ -2341,7 +2344,7 @@ static int do_gstats(int fd, struct ifreq *ifr)
strings->string_set = ETH_SS_STATS;
strings->len = n_stats;
ifr->ifr_data = (caddr_t) strings;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get stats strings information");
free(strings);
@@ -2352,7 +2355,7 @@ static int do_gstats(int fd, struct ifreq *ifr)
stats->cmd = ETHTOOL_GSTATS;
stats->n_stats = n_stats;
ifr->ifr_data = (caddr_t) stats;
- err = ioctl(fd, SIOCETHTOOL, ifr);
+ err = send_ioctl(fd, ifr);
if (err < 0) {
perror("Cannot get stats information");
free(strings);
@@ -2416,6 +2419,11 @@ static int do_grxclass(int fd, struct ifreq *ifr)
return 0;
}
+static int send_ioctl(int fd, struct ifreq *ifr)
+{
+ return ioctl(fd, SIOCETHTOOL, ifr);
+}
+
int main(int argc, char **argp, char **envp)
{
parse_cmdline(argc, argp);