]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: Initialize linear mapping of symbols in _init() of extension
authorSerhey Popovych <serhe.popovych@gmail.com>
Thu, 1 Mar 2018 11:03:10 +0000 (13:03 +0200)
committerFlorian Westphal <fw@strlen.de>
Fri, 27 Apr 2018 16:56:14 +0000 (18:56 +0200)
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>
extensions/libipt_realm.c
extensions/libxt_devgroup.c

index 8eea7874f53ce47150e82cca337d535930e27dbd..750091053a03c8b9a6ab9491edd11e309b697025 100644 (file)
@@ -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);
 }
index 2ec3905c91b5840d96ef38bfee1c4063ebe09bb5..f1352c47ecc174ed44384c95b6973987dd5f5b57 100644 (file)
@@ -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);
 }