summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorSerhey Popovych <serhe.popovych@gmail.com>2018-03-01 13:03:10 +0200
committerFlorian Westphal <fw@strlen.de>2018-04-27 18:56:14 +0200
commit56aadc01b258ef7849463723ab5ddc4885db22f6 (patch)
treeb8fb3f0c3c95231a0843ee5eb4386096b811f96e /extensions
parent79c2da9860d704e7e709a0612da1fdc5cde8b5fa (diff)
extensions: Initialize linear mapping of symbols in _init() of extension
libxt_devgroup and libipt_realm currently unable to display symbolic names in save/print commands because linear mapping is not initialized. It looks bit confusing as linear mapping initialization is done in init() of extension, which is expected to be called before any other function of extension. However init is called only when '-m' option specified on command line, that is true only for insert, append, replace and destroy iptables commands. Move initialization to extension _init() function before calling any function in extension. Before: ------- ... src-group 0x1 dst-group 0x2 ... src-group 0x2 dst-group 0x1 After: ------ ... src-group grp1 dst-group grp2 ... src-group grp2 dst-group grp1 Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'extensions')
-rw-r--r--extensions/libipt_realm.c18
-rw-r--r--extensions/libxt_devgroup.c17
2 files changed, 14 insertions, 21 deletions
diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c
index 8eea7874..75009105 100644
--- a/extensions/libipt_realm.c
+++ b/extensions/libipt_realm.c
@@ -28,18 +28,10 @@ static const struct xt_option_entry realm_opts[] = {
XTOPT_TABLEEND,
};
-/* array of realms from /etc/iproute2/rt_realms */
+static const char f_realms[] = "/etc/iproute2/rt_realms";
+/* array of realms from f_realms[] */
static struct xtables_lmap *realms;
-static void realm_init(struct xt_entry_match *m)
-{
- const char file[] = "/etc/iproute2/rt_realms";
-
- realms = xtables_lmap_init(file);
- if (realms == NULL && errno != ENOENT)
- fprintf(stderr, "Warning: %s: %s\n", file, strerror(errno));
-}
-
static void realm_parse(struct xt_option_call *cb)
{
struct xt_realm_info *realminfo = cb->data;
@@ -151,7 +143,6 @@ static struct xtables_match realm_mt_reg = {
.size = XT_ALIGN(sizeof(struct xt_realm_info)),
.userspacesize = XT_ALIGN(sizeof(struct xt_realm_info)),
.help = realm_help,
- .init = realm_init,
.print = realm_print,
.save = realm_save,
.x6_parse = realm_parse,
@@ -161,5 +152,10 @@ static struct xtables_match realm_mt_reg = {
void _init(void)
{
+ realms = xtables_lmap_init(f_realms);
+ if (realms == NULL && errno != ENOENT)
+ fprintf(stderr, "Warning: %s: %s\n", f_realms,
+ strerror(errno));
+
xtables_register_match(&realm_mt_reg);
}
diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c
index 2ec3905c..f1352c47 100644
--- a/extensions/libxt_devgroup.c
+++ b/extensions/libxt_devgroup.c
@@ -31,17 +31,10 @@ static const struct xt_option_entry devgroup_opts[] = {
XTOPT_TABLEEND,
};
-/* array of devgroups from /etc/iproute2/group */
+static const char f_devgroups[] = "/etc/iproute2/group";
+/* array of devgroups from f_devgroups[] */
static struct xtables_lmap *devgroups;
-static void devgroup_init(struct xt_entry_match *match)
-{
- const char file[] = "/etc/iproute2/group";
- devgroups = xtables_lmap_init(file);
- if (devgroups == NULL && errno != ENOENT)
- fprintf(stderr, "Warning: %s: %s\n", file, strerror(errno));
-}
-
static void devgroup_parse_groupspec(const char *arg, unsigned int *group,
unsigned int *mask)
{
@@ -212,7 +205,6 @@ static struct xtables_match devgroup_mt_reg = {
.family = NFPROTO_UNSPEC,
.size = XT_ALIGN(sizeof(struct xt_devgroup_info)),
.userspacesize = XT_ALIGN(sizeof(struct xt_devgroup_info)),
- .init = devgroup_init,
.help = devgroup_help,
.print = devgroup_print,
.save = devgroup_save,
@@ -224,5 +216,10 @@ static struct xtables_match devgroup_mt_reg = {
void _init(void)
{
+ devgroups = xtables_lmap_init(f_devgroups);
+ if (devgroups == NULL && errno != ENOENT)
+ fprintf(stderr, "Warning: %s: %s\n", f_devgroups,
+ strerror(errno));
+
xtables_register_match(&devgroup_mt_reg);
}