[PATCH iptables 1/3] extensions: Initialize linear mapping of symbols in _init() of extension

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 extensions/libipt_realm.c   |   18 +++++++-----------
 extensions/libxt_devgroup.c |   17 +++++++----------
 2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c
index 8eea787..7500910 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 2ec3905..f1352c4 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);
 }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux