]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-arp: Use xtables_parse_interface()
authorPhil Sutter <phil@nwl.cc>
Sat, 26 Oct 2019 19:37:48 +0000 (21:37 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 30 Oct 2019 09:01:17 +0000 (10:01 +0100)
The local implementation differs just slightly but libxtables version
seems more correct (no needless memsetting of mask, more relevant
illegal character checking) so use that one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/xtables-arp.c

index bbc1ceb6e8e38e8fd94b3a6627062240b358840a..9cfad76263d32eda56a1a87ca8aa3d05e06092ef 100644 (file)
@@ -357,44 +357,6 @@ check_inverse(const char option[], int *invert, int *optidx, int argc)
        return false;
 }
 
-static void
-parse_interface(const char *arg, char *vianame, unsigned char *mask)
-{
-       int vialen = strlen(arg);
-       unsigned int i;
-
-       memset(mask, 0, IFNAMSIZ);
-       memset(vianame, 0, IFNAMSIZ);
-
-       if (vialen + 1 > IFNAMSIZ)
-               xtables_error(PARAMETER_PROBLEM,
-                             "interface name `%s' must be shorter than IFNAMSIZ"
-                             " (%i)", arg, IFNAMSIZ-1);
-
-       strcpy(vianame, arg);
-       if (vialen == 0)
-               memset(mask, 0, IFNAMSIZ);
-       else if (vianame[vialen - 1] == '+') {
-               memset(mask, 0xFF, vialen - 1);
-               memset(mask + vialen - 1, 0, IFNAMSIZ - vialen + 1);
-               /* Don't remove `+' here! -HW */
-       } else {
-               /* Include nul-terminator in match */
-               memset(mask, 0xFF, vialen + 1);
-               memset(mask + vialen + 1, 0, IFNAMSIZ - vialen - 1);
-               for (i = 0; vianame[i]; i++) {
-                       if (!isalnum(vianame[i])
-                           && vianame[i] != '_'
-                           && vianame[i] != '.') {
-                               printf("Warning: weird character in interface"
-                                      " `%s' (No aliases, :, ! or *).\n",
-                                      vianame);
-                               break;
-                       }
-               }
-       }
-}
-
 static void
 set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
           int invert)
@@ -816,18 +778,18 @@ int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table,
                        check_inverse(optarg, &invert, &optind, argc);
                        set_option(&options, OPT_VIANAMEIN, &cs.arp.arp.invflags,
                                   invert);
-                       parse_interface(argv[optind-1],
-                                       cs.arp.arp.iniface,
-                                       cs.arp.arp.iniface_mask);
+                       xtables_parse_interface(argv[optind-1],
+                                               cs.arp.arp.iniface,
+                                               cs.arp.arp.iniface_mask);
                        break;
 
                case 'o':
                        check_inverse(optarg, &invert, &optind, argc);
                        set_option(&options, OPT_VIANAMEOUT, &cs.arp.arp.invflags,
                                   invert);
-                       parse_interface(argv[optind-1],
-                                       cs.arp.arp.outiface,
-                                       cs.arp.arp.outiface_mask);
+                       xtables_parse_interface(argv[optind-1],
+                                               cs.arp.arp.outiface,
+                                               cs.arp.arp.outiface_mask);
                        break;
 
                case 'v':