chiark / gitweb /
Make tables for DEFINE_STRING_TABLE_LOOKUP consistent
[elogind.git] / src / udev / net / ethtool-util.c
index 4fad52b469f28c6ef3216ad726bec04dc6e9d586..3ec245ecabc96b14b3e9582de3d61998653f109d 100644 (file)
@@ -31,7 +31,7 @@
 #include "log.h"
 #include "conf-parser.h"
 
-static const char* const duplex_table[] = {
+static const char* const duplex_table[_DUP_MAX] = {
         [DUP_FULL] = "full",
         [DUP_HALF] = "half"
 };
@@ -39,7 +39,7 @@ static const char* const duplex_table[] = {
 DEFINE_STRING_TABLE_LOOKUP(duplex, Duplex);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_duplex, duplex, Duplex, "Failed to parse duplex setting");
 
-static const char* const wol_table[] = {
+static const char* const wol_table[_WOL_MAX] = {
         [WOL_PHY] = "phy",
         [WOL_MAGIC] = "magic",
         [WOL_OFF] = "off"
@@ -63,21 +63,45 @@ int ethtool_connect(int *ret) {
         return 0;
 }
 
+int ethtool_get_driver(int fd, const char *ifname, char **ret) {
+        struct ethtool_drvinfo ecmd = {
+                .cmd = ETHTOOL_GDRVINFO
+        };
+        struct ifreq ifr = {
+                .ifr_data = (void*) &ecmd
+        };
+        char *d;
+        int r;
+
+        strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
+
+        r = ioctl(fd, SIOCETHTOOL, &ifr);
+        if (r < 0)
+                return -errno;
+
+        d = strdup(ecmd.driver);
+        if (!d)
+                return -ENOMEM;
+
+        *ret = d;
+        return 0;
+}
+
 int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex duplex)
 {
-        struct ifreq ifr;
-        struct ethtool_cmd ecmd;
-        bool need_update;
+        struct ethtool_cmd ecmd = {
+                .cmd = ETHTOOL_GSET
+        };
+        struct ifreq ifr = {
+                .ifr_data = (void*) &ecmd
+        };
+        bool need_update = false;
         int r;
 
         if (speed == 0 && duplex == _DUP_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_cmd));
-        ecmd.cmd = ETHTOOL_GSET;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
-        ifr.ifr_data = (void *)&ecmd;
 
         r = ioctl(fd, SIOCETHTOOL, &ifr);
         if (r < 0)
@@ -117,19 +141,19 @@ int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex dup
 }
 
 int ethtool_set_wol(int fd, const char *ifname, WakeOnLan wol) {
-        struct ifreq ifr;
-        struct ethtool_wolinfo ecmd;
-        bool need_update;
+        struct ethtool_wolinfo ecmd = {
+                .cmd = ETHTOOL_GWOL
+        };
+        struct ifreq ifr = {
+                .ifr_data = (void*) &ecmd
+        };
+        bool need_update = false;
         int r;
 
         if (wol == _WOL_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_wolinfo));
-        ecmd.cmd = ETHTOOL_GWOL;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
-        ifr.ifr_data = (void *)&ecmd;
 
         r = ioctl(fd, SIOCETHTOOL, &ifr);
         if (r < 0)