From d3f143727c308ff303ea9404945e71138a7792a1 Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Thu, 1 Mar 2018 13:03:12 +0200 Subject: xtables: Introduce and use common function to print val[/mask] arguments There are number of places where argument is in val[/mask] format printed in extensions and some of them may print corresponding symbolic name. By introducing common function for this task we eliminate custom code parts in extensions to perform printing of arguments in required formats. Use xtables_print_mark_mask() helper for extensions without symbolic name for val[/mask]. Signed-off-by: Serhey Popovych Signed-off-by: Florian Westphal --- libxtables/xtables.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libxtables/xtables.c') diff --git a/libxtables/xtables.c b/libxtables/xtables.c index f93e88dd..60a0231c 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -2012,6 +2012,26 @@ name2val: cb->ext_name, cb->arg, cb->entry->name); } +void xtables_print_val_mask(unsigned int val, unsigned int mask, + const struct xtables_lmap *lmap) +{ + if (mask != ~0U) { + printf(" 0x%x/0x%x", val, mask); + return; + } + + if (lmap) { + const char *name = xtables_lmap_id2name(lmap, val); + + if (name) { + printf(" %s", name); + return; + } + } + + printf(" 0x%x", val); +} + int kernel_version; void get_kernel_version(void) -- cgit v1.2.3