]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
ebtables{,-translate}: Convert if-clause to switch()
authorPhil Sutter <phil@nwl.cc>
Tue, 21 Nov 2023 23:58:02 +0000 (00:58 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 5 Dec 2023 15:35:37 +0000 (16:35 +0100)
Parser merge prep work, align final do_commandeb*() parts with
do_commandx().

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/xtables-eb-translate.c
iptables/xtables-eb.c

index da7e5e3dda1f3554e971a7ee2f75331af110e697..d0fec9c6d5ae39b71c68636957f683075b08211b 100644 (file)
@@ -497,23 +497,25 @@ print_zero:
 
        cs.eb.ethproto = htons(cs.eb.ethproto);
 
-       if (command == 'P') {
-               return 0;
-       } else if (command == 'F') {
-                       if (p.chain) {
-                               printf("flush chain bridge %s %s\n", p.table, p.chain);
-                       } else {
-                               printf("flush table bridge %s\n", p.table);
-                       }
-                       ret = 1;
-       } else if (command == 'A') {
+       switch (command) {
+       case 'F':
+               if (p.chain) {
+                       printf("flush chain bridge %s %s\n", p.table, p.chain);
+               } else {
+                       printf("flush table bridge %s\n", p.table);
+               }
+               ret = 1;
+               break;
+       case 'A':
                ret = nft_rule_eb_xlate_add(h, &p, &cs, true);
                if (!ret)
                        print_ebt_cmd(argc, argv);
-       } else if (command == 'I') {
+               break;
+       case 'I':
                ret = nft_rule_eb_xlate_add(h, &p, &cs, false);
                if (!ret)
                        print_ebt_cmd(argc, argv);
+               break;
        }
 
        ebt_cs_clean(&cs);
index ddbe1b5a3adc04f8df550146a4d5d8ac306a7f3c..db75e65caa02a62069065d25e033f6a2caf0885c 100644 (file)
@@ -1168,47 +1168,57 @@ print_zero:
         * The kernel does not have to do this of course */
        cs.eb.ethproto = htons(cs.eb.ethproto);
 
-       if (command == 'P') {
+       switch (command) {
+       case 'P':
                if (selected_chain >= NF_BR_NUMHOOKS) {
                        ret = ebt_cmd_user_chain_policy(h, *table, chain, policy);
-               } else {
-                       if (strcmp(policy, "RETURN") == 0) {
-                               xtables_error(PARAMETER_PROBLEM,
-                                             "Policy RETURN only allowed for user defined chains");
-                       }
-                       ret = nft_cmd_chain_set(h, *table, chain, policy, NULL);
-                       if (ret < 0)
-                               xtables_error(PARAMETER_PROBLEM, "Wrong policy");
+                       break;
                }
-       } else if (command == 'L') {
+               if (strcmp(policy, "RETURN") == 0) {
+                       xtables_error(PARAMETER_PROBLEM,
+                                     "Policy RETURN only allowed for user defined chains");
+               }
+               ret = nft_cmd_chain_set(h, *table, chain, policy, NULL);
+               if (ret < 0)
+                       xtables_error(PARAMETER_PROBLEM, "Wrong policy");
+               break;
+       case 'L':
                ret = list_rules(h, chain, *table, rule_nr,
                                 flags & OPT_VERBOSE,
                                 0,
                                 /*flags&OPT_EXPANDED*/0,
                                 flags&LIST_N,
                                 flags&LIST_C);
-       }
-       if (flags & OPT_ZERO) {
+               if (!(flags & OPT_ZERO))
+                       break;
+       case 'Z':
                ret = nft_cmd_chain_zero_counters(h, chain, *table,
                                                  flags & OPT_VERBOSE);
-       } else if (command == 'F') {
+               break;
+       case 'F':
                ret = nft_cmd_rule_flush(h, chain, *table, flags & OPT_VERBOSE);
-       } else if (command == 'A') {
+               break;
+       case 'A':
                ret = nft_cmd_rule_append(h, chain, *table, &cs,
                                          flags & OPT_VERBOSE);
-       } else if (command == 'I') {
+               break;
+       case 'I':
                ret = nft_cmd_rule_insert(h, chain, *table, &cs,
                                          rule_nr - 1, flags & OPT_VERBOSE);
-       } else if (command == 'D') {
+               break;
+       case 'D':
                ret = delete_entry(h, chain, *table, &cs, rule_nr - 1,
                                   rule_nr_end, flags & OPT_VERBOSE);
-       } else if (command == 14) {
+               break;
+       case 14:
                ret = nft_cmd_rule_check(h, chain, *table,
                                         &cs, flags & OPT_VERBOSE);
-       } else if (command == 'C') {
+               break;
+       case 'C':
                ret = change_entry_counters(h, chain, *table, &cs,
                                            rule_nr - 1, rule_nr_end, chcounter,
                                            flags & OPT_VERBOSE);
+               break;
        }
 
        ebt_cs_clean(&cs);