Merge conditional interface printing code for input and output interface into a function. Signed-off-by: Phil Sutter <phil@xxxxxx> --- iptables/nft-arp.c | 52 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/iptables/nft-arp.c b/iptables/nft-arp.c index c73833270f0e8..264864c3fb2b2 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, -- 2.43.0