From 766e4872e10bccc12fa37dcf5380d3c99fcf1d75 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 5 Nov 2021 18:02:13 +0100 Subject: xshared: Share print_iface() function Merge the three identical copies into one and name it 'save_iface' (as the printed syntax is for "save"-format). Leave arptables alone for now, its rather complicated whitespace printing doesn't allow for use of the shared function. Also keep ebtables' custom implementation, it is used for the --logical-in/--logical-out long-options, too. Apart from that, ebtables-nft does not use a mask, at all. Signed-off-by: Phil Sutter --- iptables/nft-shared.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'iptables/nft-shared.c') diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c index 082cc0e2..b86cc086 100644 --- a/iptables/nft-shared.c +++ b/iptables/nft-shared.c @@ -785,28 +785,6 @@ void print_rule_details(const struct iptables_command_state *cs, } } -static void -print_iface(char letter, const char *iface, const unsigned char *mask, int inv) -{ - unsigned int i; - - if (mask[0] == 0) - return; - - printf("%s -%c ", inv ? " !" : "", letter); - - for (i = 0; i < IFNAMSIZ; i++) { - if (mask[i] != 0) { - if (iface[i] != '\0') - printf("%c", iface[i]); - } else { - if (iface[i-1] != '\0') - printf("+"); - break; - } - } -} - void save_rule_details(const struct iptables_command_state *cs, uint8_t invflags, uint16_t proto, const char *iniface, @@ -815,11 +793,11 @@ void save_rule_details(const struct iptables_command_state *cs, unsigned const char *outiface_mask) { if (iniface != NULL) { - print_iface('i', iniface, iniface_mask, + save_iface('i', iniface, iniface_mask, invflags & IPT_INV_VIA_IN); } if (outiface != NULL) { - print_iface('o', outiface, outiface_mask, + save_iface('o', outiface, outiface_mask, invflags & IPT_INV_VIA_OUT); } -- cgit v1.2.3