summaryrefslogtreecommitdiffstats
path: root/libxtables
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-11-03 23:43:49 +0100
committerFlorian Westphal <fw@strlen.de>2018-11-07 20:08:15 +0100
commit7bd9febf65e98eb1f4b4d51afa2479c442066235 (patch)
tree016e65d6e7fc85cda5baa28837e8e0f2c2c93240 /libxtables
parenta10eb8861c8fdc8894a8c2f6baf4dd791d5ab4f0 (diff)
libxtables: add and use mac print helpers
This changes ebtables-nft to consistently print mac address with two characters, i.e. 00:01:02:03:04:0a, not 0:1:2:3:4:a. Will require another bump of vcurrent/vage. Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'libxtables')
-rw-r--r--libxtables/xtables.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 34a084f4..11231fc4 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -2077,6 +2077,28 @@ void xtables_print_num(uint64_t number, unsigned int format)
printf(FMT("%4lluT ","%lluT "), (unsigned long long)number);
}
+void xtables_print_mac(const unsigned char *macaddress)
+{
+ unsigned int i;
+
+ printf("%02x", macaddress[0]);
+ for (i = 1; i < 6; ++i)
+ printf(":%02x", macaddress[i]);
+}
+
+void xtables_print_mac_and_mask(const unsigned char *mac, const unsigned char *mask)
+{
+ static const char hlpmsk[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+ xtables_print_mac(mac);
+
+ if (memcmp(mask, hlpmsk, 6) == 0)
+ return;
+
+ printf("/");
+ xtables_print_mac(mask);
+}
+
void xtables_parse_val_mask(struct xt_option_call *cb,
unsigned int *val, unsigned int *mask,
const struct xtables_lmap *lmap)