From: Phil Sutter Date: Sat, 27 Jul 2024 11:40:55 +0000 (+0200) Subject: arptables: Introduce print_iface() X-Git-Tag: v1.8.11~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=baccf16efb0472dac65c0e4245ff43a49dc92431;p=thirdparty%2Fiptables.git arptables: Introduce print_iface() Merge conditional interface printing code for input and output interface into a function. Signed-off-by: Phil Sutter --- diff --git a/iptables/nft-arp.c b/iptables/nft-arp.c index c7383327..264864c3 100644 --- a/iptables/nft-arp.c +++ b/iptables/nft-arp.c @@ -197,13 +197,23 @@ static void nft_arp_print_header(unsigned int format, const char *chain, } } +static void print_iface(char letter, const char *iface, + unsigned int format, bool invert, const char **sep) +{ + if (iface[0] == '\0' || (!strcmp(iface, "+") && !invert)) { + if (!(format & FMT_VIA)) + return; + iface = (format & FMT_NUMERIC) ? "*" : "any"; + } + printf("%s%s-%c %s", *sep, invert ? "! " : "", letter, iface); + *sep = " "; +} + static void nft_arp_print_rule_details(const struct iptables_command_state *cs, unsigned int format) { const struct arpt_entry *fw = &cs->arp; - char iface[IFNAMSIZ+2]; const char *sep = ""; - int print_iface = 0; int i; if (strlen(cs->jumpto)) { @@ -211,40 +221,10 @@ static void nft_arp_print_rule_details(const struct iptables_command_state *cs, sep = " "; } - iface[0] = '\0'; - - if (fw->arp.iniface[0] != '\0') { - strcat(iface, fw->arp.iniface); - print_iface = 1; - } - else if (format & FMT_VIA) { - print_iface = 1; - if (format & FMT_NUMERIC) strcat(iface, "*"); - else strcat(iface, "any"); - } - if (print_iface) { - printf("%s%s-i %s", sep, fw->arp.invflags & IPT_INV_VIA_IN ? - "! " : "", iface); - sep = " "; - } - - print_iface = 0; - iface[0] = '\0'; - - if (fw->arp.outiface[0] != '\0') { - strcat(iface, fw->arp.outiface); - print_iface = 1; - } - else if (format & FMT_VIA) { - print_iface = 1; - if (format & FMT_NUMERIC) strcat(iface, "*"); - else strcat(iface, "any"); - } - if (print_iface) { - printf("%s%s-o %s", sep, fw->arp.invflags & IPT_INV_VIA_OUT ? - "! " : "", iface); - sep = " "; - } + print_iface('i', fw->arp.iniface, format, + fw->arp.invflags & IPT_INV_VIA_IN, &sep); + print_iface('o', fw->arp.outiface, format, + fw->arp.invflags & IPT_INV_VIA_OUT, &sep); if (fw->arp.smsk.s_addr != 0L) { printf("%s%s-s %s", sep,