Skip to contentSkip to conversation

RFC: introduce xtables global param struct

PATCH jamal 2 participants 6 messages Feb 7, 2009 – Feb 12, 2009 netfilter

lore
Share & tools
lore

jamal

author
#0 lore raw

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

include/xtables.h.in +11 -0
index 9e45c8b..d91d902 100644
@@ -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,
xtables.c +23 -0
index 849dc7d..b053a48 100644
@@ -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
  */
#1 lore raw
Quoted 3 lines · jamal

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

Please post patch inline. I otherwise need to save them and reinsert them into alpine..

Quoted 14 lines

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

include/xtables.h.in line 37

Quoted 8 lines
include/xtables.h.in +8 -0
+struct xtables_globals
+{
+	unsigned int option_offset;
+	char *program_version;
+	char *program_name;
+	struct xtables_afinfo *afinfo;
+	struct option *opts;
+};

These should be const, esp. program_version and program_name. I added myself a patch now.

author
#2 lore raw
Quoted 4 lines · Jan Engelhardt

On Saturday 2009-02-07 20:28, jamal wrote:

Please post patch inline. I otherwise need to save them and reinsert them into alpine..

I have problems with my client with insertion of whitespaces if i do that. I will send the next one inlined and see if Patrick complains when applying.

Quoted 11 lines

include/xtables.h.in line 37

Quoted 8 lines
include/xtables.h.in +8 -0
+struct xtables_globals
+{
+	unsigned int option_offset;
+	char *program_version;
+	char *program_name;
+	struct xtables_afinfo *afinfo;
+	struct option *opts;
+};

These should be const, esp. program_version and program_name. I added myself a patch now.

Ok, so you took care of this?

cheers,
jamal

#3 lore raw
Quoted 13 lines · jamal
Quoted 12 lines

include/xtables.h.in line 37

Quoted 9 lines
include/xtables.h.in +8 -0
+struct xtables_globals
+{
+	unsigned int option_offset;
+	char *program_version;
+	char *program_name;
+	struct xtables_afinfo *afinfo;
+	struct option *opts;
+};

These should be const, esp. program_version and program_name. I added myself a patch now.

Quoted 2 lines

Ok, so you took care of this?

About the const - yes. (Since the patch itself was already applied.)

author
#4 lore raw
Quoted 1 line · Jan Engelhardt

About the const - yes. (Since the patch itself was already applied.)

Ok, This hasnt propagated yet. My two other patches depend on this. So once Patrick syncs with you, I will submit on top later today.

cheers,
jamal

#5 lore raw
Quoted 6 lines · jamal
Quoted 1 line · Jan Engelhardt

About the const - yes. (Since the patch itself was already applied.)

Ok, This hasnt propagated yet. My two other patches depend on this. So once Patrick syncs with you, I will submit on top later today.

This has already - 41f03ba382dfd26e7db939fd02447058b1c56f7b.