summaryrefslogtreecommitdiffstats
path: root/iptables
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-11-22 00:58:02 +0100
committerPhil Sutter <phil@nwl.cc>2023-12-05 16:35:37 +0100
commit17a5f3ae86897f6c55bc90d3757f522daa734fc8 (patch)
treeb669260e1c9aa2007278dd9fad450476fb0cf204 /iptables
parent9c777205d6464b8af64d7ab2cdfbf2c85e22b3ed (diff)
ebtables{,-translate}: Convert if-clause to switch()
Parser merge prep work, align final do_commandeb*() parts with do_commandx(). Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables')
-rw-r--r--iptables/xtables-eb-translate.c24
-rw-r--r--iptables/xtables-eb.c46
2 files changed, 41 insertions, 29 deletions
diff --git a/iptables/xtables-eb-translate.c b/iptables/xtables-eb-translate.c
index da7e5e3d..d0fec9c6 100644
--- a/iptables/xtables-eb-translate.c
+++ b/iptables/xtables-eb-translate.c
@@ -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);
diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c
index ddbe1b5a..db75e65c 100644
--- a/iptables/xtables-eb.c
+++ b/iptables/xtables-eb.c
@@ -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);