cal: make it NOEXEC
[oweals/busybox.git] / networking / nameif.c
index 9a16b0fbc58327397c91fbec986d97e81200dbfa..91d50536a72abb39dea4ce7c793755cbea4e819f 100644 (file)
@@ -9,36 +9,39 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
 //config:config NAMEIF
-//config:      bool "nameif"
+//config:      bool "nameif (6.6 kb)"
 //config:      default y
 //config:      select PLATFORM_LINUX
 //config:      select FEATURE_SYSLOG
 //config:      help
-//config:        nameif is used to rename network interface by its MAC address.
-//config:        Renamed interfaces MUST be in the down state.
-//config:        It is possible to use a file (default: /etc/mactab)
-//config:        with list of new interface names and MACs.
-//config:        Maximum interface name length: IFNAMSIZ = 16
-//config:        File fields are separated by space or tab.
-//config:        File format:
-//config:        # Comment
-//config:        new_interface_name    XX:XX:XX:XX:XX:XX
+//config:      nameif is used to rename network interface by its MAC address.
+//config:      Renamed interfaces MUST be in the down state.
+//config:      It is possible to use a file (default: /etc/mactab)
+//config:      with list of new interface names and MACs.
+//config:      Maximum interface name length: IFNAMSIZ = 16
+//config:      File fields are separated by space or tab.
+//config:      File format:
+//config:              # Comment
+//config:              new_interface_name  XX:XX:XX:XX:XX:XX
 //config:
 //config:config FEATURE_NAMEIF_EXTENDED
 //config:      bool "Extended nameif"
 //config:      default y
 //config:      depends on NAMEIF
 //config:      help
-//config:        This extends the nameif syntax to support the bus_info, driver,
-//config:        phyaddr selectors. The syntax is compatible to the normal nameif.
-//config:        File format:
-//config:          new_interface_name  driver=asix bus=usb-0000:00:08.2-3
-//config:          new_interface_name  bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
-//config:          new_interface_name  phy_address=2 00:80:C8:38:91:B5
-//config:          new_interface_name  mac=00:80:C8:38:91:B5
-//config:          new_interface_name  00:80:C8:38:91:B5
+//config:      This extends the nameif syntax to support the bus_info, driver,
+//config:      phyaddr selectors. The syntax is compatible to the normal nameif.
+//config:      File format:
+//config:              new_interface_name  driver=asix bus=usb-0000:00:08.2-3
+//config:              new_interface_name  bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
+//config:              new_interface_name  phy_address=2 00:80:C8:38:91:B5
+//config:              new_interface_name  mac=00:80:C8:38:91:B5
+//config:              new_interface_name  00:80:C8:38:91:B5
+
+//applet:IF_NAMEIF(APPLET_NOEXEC(nameif, nameif, BB_DIR_SBIN, BB_SUID_DROP, nameif))
+
+//kbuild:lib-$(CONFIG_NAMEIF) += nameif.o
 
 //usage:#define nameif_trivial_usage
 //usage:       IF_NOT_FEATURE_NAMEIF_EXTENDED(
@@ -121,20 +124,20 @@ struct ethtool_drvinfo {
 };
 
 struct ethtool_cmd {
-       __u32   cmd;
-       __u32   supported;      /* Features this interface supports */
-       __u32   advertising;    /* Features this interface advertises */
-       __u16   speed;          /* The forced speed, 10Mb, 100Mb, gigabit */
-       __u8    duplex;         /* Duplex, half or full */
-       __u8    port;           /* Which connector port */
-       __u8    phy_address;
-       __u8    transceiver;    /* Which transceiver to use */
-       __u8    autoneg;        /* Enable or disable autonegotiation */
-       __u32   maxtxpkt;       /* Tx pkts before generating tx int */
-       __u32   maxrxpkt;       /* Rx pkts before generating rx int */
-       __u16   speed_hi;
-       __u16   reserved2;
-       __u32   reserved[3];
+       uint32_t   cmd;
+       uint32_t   supported;      /* Features this interface supports */
+       uint32_t   advertising;    /* Features this interface advertises */
+       uint16_t   speed;          /* The forced speed, 10Mb, 100Mb, gigabit */
+       uint8_t    duplex;         /* Duplex, half or full */
+       uint8_t    port;           /* Which connector port */
+       uint8_t    phy_address;
+       uint8_t    transceiver;    /* Which transceiver to use */
+       uint8_t    autoneg;        /* Enable or disable autonegotiation */
+       uint32_t   maxtxpkt;       /* Tx pkts before generating tx int */
+       uint32_t   maxrxpkt;       /* Rx pkts before generating rx int */
+       uint16_t   speed_hi;
+       uint16_t   reserved2;
+       uint32_t   reserved[3];
 };
 
 #define ETHTOOL_GSET      0x00000001 /* Get settings. */
@@ -161,19 +164,19 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
                if (*next)
                        *next++ = '\0';
                /* Check for selectors, mac= is assumed */
-               if (strncmp(selector, "bus=", 4) == 0) {
+               if (is_prefixed_with(selector, "bus=")) {
                        ch->bus_info = xstrdup(selector + 4);
                        found_selector++;
-               } else if (strncmp(selector, "driver=", 7) == 0) {
+               } else if (is_prefixed_with(selector, "driver=")) {
                        ch->driver = xstrdup(selector + 7);
                        found_selector++;
-               } else if (strncmp(selector, "phyaddr=", 8) == 0) {
+               } else if (is_prefixed_with(selector, "phyaddr=")) {
                        ch->phy_address = xatoi_positive(selector + 8);
                        found_selector++;
                } else {
 #endif
                        lmac = xmalloc(ETH_ALEN);
-                       ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) != 0 ? 0 : 4), lmac);
+                       ch->mac = ether_aton_r(selector + (is_prefixed_with(selector, "mac=") ? 4 : 0), lmac);
                        if (ch->mac == NULL)
                                bb_error_msg_and_die("can't parse %s", selector);
 #if  ENABLE_FEATURE_NAMEIF_EXTENDED
@@ -292,12 +295,11 @@ int nameif_main(int argc UNUSED_PARAM, char **argv)
                        if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0)
                                continue;
                        /* if we came here, all selectors have matched */
-                       break;
+                       goto found;
                }
                /* Nothing found for current interface */
-               if (!ch)
-                       continue;
-
+               continue;
+ found:
                if (strcmp(ifr.ifr_name, ch->ifname) != 0) {
                        strcpy(ifr.ifr_newname, ch->ifname);
                        ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
@@ -313,10 +315,14 @@ int nameif_main(int argc UNUSED_PARAM, char **argv)
                        ch->next->prev = ch->prev;
                if (ENABLE_FEATURE_CLEAN_UP)
                        delete_eth_table(ch);
-       }
+       } /* while */
+
        if (ENABLE_FEATURE_CLEAN_UP) {
-               for (ch = clist; ch; ch = ch->next)
+               ethtable_t *next;
+               for (ch = clist; ch; ch = next) {
+                       next = ch->next;
                        delete_eth_table(ch);
+               }
                config_close(parser);
        };