summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhey Popovych <serhe.popovych@gmail.com>2018-03-01 13:03:12 +0200
committerFlorian Westphal <fw@strlen.de>2018-04-27 18:56:22 +0200
commitd3f143727c308ff303ea9404945e71138a7792a1 (patch)
treed454846d68234640b3fdec17414ad6a69bd943cf
parent29b1d97764d1849651388d870565b3fa815a0bd8 (diff)
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 <serhe.popovych@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--extensions/libipt_realm.c21
-rw-r--r--extensions/libxt_connmark.c18
-rw-r--r--extensions/libxt_devgroup.c27
-rw-r--r--extensions/libxt_mark.c17
-rw-r--r--include/xtables.h9
-rw-r--r--libxtables/xtables.c20
6 files changed, 48 insertions, 64 deletions
diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c
index 545b2580..e01d048e 100644
--- a/extensions/libipt_realm.c
+++ b/extensions/libipt_realm.c
@@ -47,23 +47,6 @@ static void realm_parse(struct xt_option_call *cb)
ri->invert = 1;
}
-static void
-print_realm(unsigned long id, unsigned long mask, int numeric)
-{
- const char *name = NULL;
-
- if (mask != 0xffffffff)
- printf(" 0x%lx/0x%lx", id, mask);
- else {
- if (numeric == 0)
- name = xtables_lmap_id2name(realms, id);
- if (name)
- printf(" %s", name);
- else
- printf(" 0x%lx", id);
- }
-}
-
static void realm_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
@@ -73,7 +56,7 @@ static void realm_print(const void *ip, const struct xt_entry_match *match,
printf(" !");
printf(" realm");
- print_realm(ri->id, ri->mask, numeric);
+ xtables_print_val_mask(ri->id, ri->mask, numeric ? NULL : realms);
}
static void realm_save(const void *ip, const struct xt_entry_match *match)
@@ -84,7 +67,7 @@ static void realm_save(const void *ip, const struct xt_entry_match *match)
printf(" !");
printf(" --realm");
- print_realm(ri->id, ri->mask, 0);
+ xtables_print_val_mask(ri->id, ri->mask, realms);
}
static void
diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
index be3499b6..cb4264e5 100644
--- a/extensions/libxt_connmark.c
+++ b/extensions/libxt_connmark.c
@@ -69,14 +69,6 @@ static void connmark_parse(struct xt_option_call *cb)
markinfo->invert = 1;
}
-static void print_mark(unsigned int mark, unsigned int mask)
-{
- if (mask != 0xffffffffU)
- printf(" 0x%x/0x%x", mark, mask);
- else
- printf(" 0x%x", mark);
-}
-
static void
connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
@@ -85,7 +77,8 @@ connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
printf(" CONNMARK match ");
if (info->invert)
printf("!");
- print_mark(info->mark, info->mask);
+
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void
@@ -97,7 +90,8 @@ connmark_mt_print(const void *ip, const struct xt_entry_match *match,
printf(" connmark match ");
if (info->invert)
printf("!");
- print_mark(info->mark, info->mask);
+
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void connmark_save(const void *ip, const struct xt_entry_match *match)
@@ -108,7 +102,7 @@ static void connmark_save(const void *ip, const struct xt_entry_match *match)
printf(" !");
printf(" --mark");
- print_mark(info->mark, info->mask);
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void
@@ -120,7 +114,7 @@ connmark_mt_save(const void *ip, const struct xt_entry_match *match)
printf(" !");
printf(" --mark");
- print_mark(info->mark, info->mask);
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void print_mark_xlate(unsigned int mark, unsigned int mask,
diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c
index 99a4d502..a88211c5 100644
--- a/extensions/libxt_devgroup.c
+++ b/extensions/libxt_devgroup.c
@@ -61,38 +61,23 @@ static void devgroup_parse(struct xt_option_call *cb)
}
}
-static void
-print_devgroup(unsigned int id, unsigned int mask, int numeric)
-{
- const char *name = NULL;
-
- if (mask != 0xffffffff)
- printf("0x%x/0x%x", id, mask);
- else {
- if (numeric == 0)
- name = xtables_lmap_id2name(devgroups, id);
- if (name)
- printf("%s", name);
- else
- printf("0x%x", id);
- }
-}
-
static void devgroup_show(const char *pfx, const struct xt_devgroup_info *info,
int numeric)
{
if (info->flags & XT_DEVGROUP_MATCH_SRC) {
if (info->flags & XT_DEVGROUP_INVERT_SRC)
printf(" !");
- printf(" %ssrc-group ", pfx);
- print_devgroup(info->src_group, info->src_mask, numeric);
+ printf(" %ssrc-group", pfx);
+ xtables_print_val_mask(info->src_group, info->src_mask,
+ numeric ? NULL : devgroups);
}
if (info->flags & XT_DEVGROUP_MATCH_DST) {
if (info->flags & XT_DEVGROUP_INVERT_DST)
printf(" !");
- printf(" %sdst-group ", pfx);
- print_devgroup(info->dst_group, info->dst_mask, numeric);
+ printf(" %sdst-group", pfx);
+ xtables_print_val_mask(info->dst_group, info->dst_mask,
+ numeric ? NULL : devgroups);
}
}
diff --git a/extensions/libxt_mark.c b/extensions/libxt_mark.c
index e1d00de9..134ad438 100644
--- a/extensions/libxt_mark.c
+++ b/extensions/libxt_mark.c
@@ -47,14 +47,6 @@ static void mark_parse(struct xt_option_call *cb)
markinfo->mask = cb->val.mask;
}
-static void print_mark(unsigned int mark, unsigned int mask)
-{
- if (mask != 0xffffffffU)
- printf(" 0x%x/0x%x", mark, mask);
- else
- printf(" 0x%x", mark);
-}
-
static void
mark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
@@ -63,7 +55,8 @@ mark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
printf(" mark match");
if (info->invert)
printf(" !");
- print_mark(info->mark, info->mask);
+
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void
@@ -76,7 +69,7 @@ mark_print(const void *ip, const struct xt_entry_match *match, int numeric)
if (info->invert)
printf(" !");
- print_mark(info->mark, info->mask);
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void mark_mt_save(const void *ip, const struct xt_entry_match *match)
@@ -87,7 +80,7 @@ static void mark_mt_save(const void *ip, const struct xt_entry_match *match)
printf(" !");
printf(" --mark");
- print_mark(info->mark, info->mask);
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void
@@ -99,7 +92,7 @@ mark_save(const void *ip, const struct xt_entry_match *match)
printf(" !");
printf(" --mark");
- print_mark(info->mark, info->mask);
+ xtables_print_mark_mask(info->mark, info->mask);
}
static void
diff --git a/include/xtables.h b/include/xtables.h
index 47129483..304828a6 100644
--- a/include/xtables.h
+++ b/include/xtables.h
@@ -548,6 +548,15 @@ static inline void xtables_parse_mark_mask(struct xt_option_call *cb,
xtables_parse_val_mask(cb, mark, mask, NULL);
}
+extern void xtables_print_val_mask(unsigned int val, unsigned int mask,
+ const struct xtables_lmap *lmap);
+
+static inline void xtables_print_mark_mask(unsigned int mark,
+ unsigned int mask)
+{
+ xtables_print_val_mask(mark, mask, NULL);
+}
+
#if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
# ifdef _INIT
# undef _init
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)