From 1bdb5535f561a4e065d766f0f4f41067e31c7281 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 3 Nov 2020 12:08:39 +0100 Subject: libxtables: Extend MAC address printing/parsing support Adding a parser which supports common names for special MAC/mask combinations and a print routine detecting those special addresses and printing the respective name allows to consolidate all the various duplicated implementations. The side-effects of this change are manageable: * arptables now accepts "BGA" as alias for the bridge group address * "mac" match now prints MAC addresses in lower-case which is consistent with the remaining code at least Signed-off-by: Phil Sutter --- extensions/libxt_mac.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'extensions/libxt_mac.c') diff --git a/extensions/libxt_mac.c b/extensions/libxt_mac.c index b6d717bc..b90eef20 100644 --- a/extensions/libxt_mac.c +++ b/extensions/libxt_mac.c @@ -37,15 +37,6 @@ static void mac_parse(struct xt_option_call *cb) macinfo->invert = 1; } -static void print_mac(const unsigned char *macaddress) -{ - unsigned int i; - - printf(" %02X", macaddress[0]); - for (i = 1; i < ETH_ALEN; ++i) - printf(":%02X", macaddress[i]); -} - static void mac_print(const void *ip, const struct xt_entry_match *match, int numeric) { @@ -56,7 +47,7 @@ mac_print(const void *ip, const struct xt_entry_match *match, int numeric) if (info->invert) printf(" !"); - print_mac(info->srcaddr); + xtables_print_mac(info->srcaddr); } static void mac_save(const void *ip, const struct xt_entry_match *match) @@ -66,8 +57,8 @@ static void mac_save(const void *ip, const struct xt_entry_match *match) if (info->invert) printf(" !"); - printf(" --mac-source"); - print_mac(info->srcaddr); + printf(" --mac-source "); + xtables_print_mac(info->srcaddr); } static void print_mac_xlate(const unsigned char *macaddress, -- cgit v1.2.3