]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-compat: ebtables: add and use helper to parse all interface names
authorFlorian Westphal <fw@strlen.de>
Tue, 8 May 2018 09:33:02 +0000 (11:33 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 10 May 2018 00:31:05 +0000 (02:31 +0200)
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/xtables-eb-translate.c
iptables/xtables-eb.c

index 5b0bbb41f54385772a209c59718b01a33b3a3a63..23d261e0a8adfb653af9a1114da75131fc67429d 100644 (file)
@@ -294,19 +294,19 @@ invalid:
        xtables_error(PARAMETER_PROBLEM,"Packet counter '%s' invalid", argv[optind]);
 }
 
-static int parse_iface(char *iface, char *option)
+static void ebtables_parse_interface(const char *arg, char *vianame)
 {
+       unsigned char mask[IFNAMSIZ];
        char *c;
 
-       if ((c = strchr(iface, '+'))) {
-               if (*(c + 1) != '\0') {
+       xtables_parse_interface(arg, vianame, mask);
+
+       if ((c = strchr(vianame, '+'))) {
+               if (*(c + 1) != '\0')
                        xtables_error(PARAMETER_PROBLEM,
-                                     "Spurious characters after '+' wildcard for '%s'", option);
-                       return -1;
-               } else
-                       *c = IF_WILDCARD;
+                                     "Spurious characters after '+' wildcard");
+               *c = IF_WILDCARD;
        }
-       return 0;
 }
 
 static void print_ebt_cmd(int argc, char *argv[])
@@ -539,12 +539,7 @@ print_zero:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_IIN;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-big_iface_length:
-                                       xtables_error(PARAMETER_PROBLEM,
-                                                     "Interface name length cannot exceed %d characters",
-                                                     IFNAMSIZ - 1);
-                               xtables_parse_interface(optarg, cs.eb.in, cs.eb.in_mask);
+                               ebtables_parse_interface(optarg, cs.eb.in);
                                break;
                        } else if (c == 2) {
                                ebt_check_option2(&flags, OPT_LOGICALIN);
@@ -554,11 +549,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_ILOGICALIN;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-                               strcpy(cs.eb.logical_in, optarg);
-                               if (parse_iface(cs.eb.logical_in, "--logical-in"))
-                                       return -1;
+                               ebtables_parse_interface(optarg, cs.eb.logical_in);
                                break;
                        } else if (c == 'o') {
                                ebt_check_option2(&flags, OPT_OUT);
@@ -568,10 +559,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_IOUT;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-
-                               xtables_parse_interface(optarg, cs.eb.out, cs.eb.out_mask);
+                               ebtables_parse_interface(optarg, cs.eb.out);
                                break;
                        } else if (c == 3) {
                                ebt_check_option2(&flags, OPT_LOGICALOUT);
@@ -581,11 +569,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_ILOGICALOUT;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-                               strcpy(cs.eb.logical_out, optarg);
-                               if (parse_iface(cs.eb.logical_out, "--logical-out"))
-                                       return -1;
+                               ebtables_parse_interface(optarg, cs.eb.logical_out);
                                break;
                        } else if (c == 'j') {
                                ebt_check_option2(&flags, OPT_JUMP);
index a6cb3f1fdb56551f41770ae94861822508b6df1a..5f8f0fb5856914e127c45f040ab2d50f62c429ca 100644 (file)
@@ -584,19 +584,18 @@ invalid:
        xtables_error(PARAMETER_PROBLEM,"Packet counter '%s' invalid", argv[optind]);
 }
 
-static int parse_iface(char *iface, char *option)
+static void ebtables_parse_interface(const char *arg, char *vianame)
 {
+       unsigned char mask[IFNAMSIZ];
        char *c;
 
-       if ((c = strchr(iface, '+'))) {
-               if (*(c + 1) != '\0') {
+       xtables_parse_interface(arg, vianame, mask);
+
+       if ((c = strchr(vianame, '+'))) {
+               if (*(c + 1) != '\0')
                        xtables_error(PARAMETER_PROBLEM,
-                                     "Spurious characters after '+' wildcard for '%s'", option);
-                       return -1;
-               } else
-                       *c = IF_WILDCARD;
+                                     "Spurious characters after '+' wildcard");
        }
-       return 0;
 }
 
 /* This code is very similar to iptables/xtables.c:command_match() */
@@ -1008,12 +1007,7 @@ print_zero:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_IIN;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-big_iface_length:
-                                       xtables_error(PARAMETER_PROBLEM,
-                                                     "Interface name length cannot exceed %d characters",
-                                                     IFNAMSIZ - 1);
-                               xtables_parse_interface(optarg, cs.eb.in, cs.eb.in_mask);
+                               ebtables_parse_interface(optarg, cs.eb.in);
                                break;
                        } else if (c == 2) {
                                ebt_check_option2(&flags, OPT_LOGICALIN);
@@ -1023,11 +1017,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_ILOGICALIN;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-                               strcpy(cs.eb.logical_in, optarg);
-                               if (parse_iface(cs.eb.logical_in, "--logical-in"))
-                                       return -1;
+                               ebtables_parse_interface(optarg, cs.eb.logical_in);
                                break;
                        } else if (c == 'o') {
                                ebt_check_option2(&flags, OPT_OUT);
@@ -1037,10 +1027,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_IOUT;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-
-                               xtables_parse_interface(optarg, cs.eb.out, cs.eb.out_mask);
+                               ebtables_parse_interface(optarg, cs.eb.out);
                                break;
                        } else if (c == 3) {
                                ebt_check_option2(&flags, OPT_LOGICALOUT);
@@ -1050,11 +1037,7 @@ big_iface_length:
                                if (ebt_check_inverse2(optarg, argc, argv))
                                        cs.eb.invflags |= EBT_ILOGICALOUT;
 
-                               if (strlen(optarg) >= IFNAMSIZ)
-                                       goto big_iface_length;
-                               strcpy(cs.eb.logical_out, optarg);
-                               if (parse_iface(cs.eb.logical_out, "--logical-out"))
-                                       return -1;
+                               ebtables_parse_interface(optarg, cs.eb.logical_out);
                                break;
                        } else if (c == 'j') {
                                ebt_check_option2(&flags, OPT_JUMP);