RFC: introduce xtables global param struct

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

 



I would like to introduce this new struct so as to pass 
localize the globals used and help in symbol renames. 

xtables_set_params() is intended to free xtables from depending
(as it does right now) on existence of such externally definitions
(from iptables/iptables6 etc).
 
Ive included a sample user - xtables_free_opts() to show
how i plan to use it.

Let me know what you think before i proceed since i am going
to be using this approach as a basis for other changes.

cheers,
jamal
diff --git a/include/xtables.h.in b/include/xtables.h.in
index 9e45c8b..d91d902 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -27,6 +27,15 @@
 
 struct in_addr;
 
+struct xtables_globals
+{
+	unsigned int option_offset;
+	char *program_version;
+	char *program_name;
+	struct xtables_afinfo *afinfo;
+	struct option *opts;
+};
+
 /* Include file for additions: new matches and targets. */
 struct xtables_match
 {
@@ -165,6 +174,8 @@ extern void *xtables_malloc(size_t);
 extern int xtables_insmod(const char *, const char *, bool);
 extern int xtables_load_ko(const char *, bool);
 
+extern void xtables_free_opts(int reset_offset,  struct option *original_opts);
+
 extern struct xtables_match *xtables_find_match(const char *name,
 	enum xtables_tryload, struct xtables_rule_match **match);
 extern struct xtables_target *xtables_find_target(const char *name,
diff --git a/xtables.c b/xtables.c
index 849dc7d..b053a48 100644
--- a/xtables.c
+++ b/xtables.c
@@ -53,6 +53,29 @@ const char *xtables_modprobe_program;
 struct xtables_match *xtables_matches;
 struct xtables_target *xtables_targets;
 
+struct xtables_globals *xt_params;
+int xtables_set_params(struct xtables_globals *xtp)
+{
+	if (!xtp) {
+		fprintf(stderr, "%s: Illegal global params\n",__func__);
+		return -1;
+	}
+
+	xt_params = xtp;
+	return 0;
+}
+
+void xtables_free_opts(int reset_offset, struct option *original_opts)
+{
+	if (xt_params->opts != original_opts) {
+		if (original_opts) 
+			free(xt_params->opts);
+		xt_params->opts = original_opts;
+		if (reset_offset)
+			xt_params->option_offset = 0;
+	}
+}
+
 /**
  * xtables_*alloc - wrappers that exit on failure
  */

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

  Powered by Linux