netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxtables: Introduce global params structuring
@ 2009-02-09 20:57 jamal
  2009-02-09 21:04 ` several messages Jan Engelhardt
  2009-02-11 11:59 ` [PATCH] libxtables: Introduce global params structuring Patrick McHardy
  0 siblings, 2 replies; 5+ messages in thread
From: jamal @ 2009-02-09 20:57 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Jan Engelhardt, Pablo Neira Ayuso, netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 41 bytes --]


Here's the basic change.

cheers,
jamal

[-- Attachment #2: iptv2-0 --]
[-- Type: text/plain, Size: 2246 bytes --]

commit bc259a1516e63a38496d568dff2d6135b925d968
Author: Jamal Hadi Salim <hadi@cyberus.ca>
Date:   Mon Feb 9 15:20:18 2009 -0500

    introduce a new struct,xtables_globals, so as to
    localize the globals used and help in symbol renames.
    The applications must invoke xtables_set_params() before starting
    to use any iptables APIs.
    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). At the moment, xtables wont even
    compile without presence of at least one of {iptables/iptables6 etc}
    
    Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>

diff --git a/include/xtables.h.in b/include/xtables.h.in
index 02750fb..61dbc76 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -33,6 +33,14 @@
 
 struct in_addr;
 
+struct xtables_globals
+{
+	unsigned int option_offset;
+	char *program_version;
+	char *program_name;
+	struct option *opts;
+};
+
 /* Include file for additions: new matches and targets. */
 struct xtables_match
 {
@@ -195,6 +203,7 @@ extern void *xtables_malloc(size_t);
 
 extern int xtables_insmod(const char *, const char *, bool);
 extern int xtables_load_ko(const char *, bool);
+int xtables_set_params(struct xtables_globals *xtp);
 
 extern struct xtables_match *xtables_find_match(const char *name,
 	enum xtables_tryload, struct xtables_rule_match **match);
diff --git a/xtables.c b/xtables.c
index 6c95475..aad5e53 100644
--- a/xtables.c
+++ b/xtables.c
@@ -46,6 +46,28 @@
 #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
 #endif
 
+struct xtables_globals *xt_params;
+/**
+ * xtables_set_params - set the global parameters used by xtables
+ * @xtp:	input xtables_globals structure
+ *
+ * The app is expected to pass a valid xtables_globals data-filled
+ * with proper values
+ * @xtp cannot be NULL
+ *
+ * Returns -1 on failure to set and 0 on success
+ */
+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;
+}
+
 /**
  * xtables_afinfo - protocol family dependent information
  * @kmod:		kernel module basename (e.g. "ip_tables")

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: several messages
  2009-02-09 20:57 [PATCH] libxtables: Introduce global params structuring jamal
@ 2009-02-09 21:04 ` Jan Engelhardt
  2009-02-09 21:27   ` jamal
  2009-02-11 11:59 ` [PATCH] libxtables: Introduce global params structuring Patrick McHardy
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2009-02-09 21:04 UTC (permalink / raw)
  To: jamal; +Cc: Patrick McHardy, Pablo Neira Ayuso, netfilter-devel


On Monday 2009-02-09 21:45, jamal wrote:
>
>Ok, I just synced with latest git. I will send you a few patches first.
>My path to resolving tc/ipt is to start with being able to take a basic
>useless program like:
>
>----------
>#include <xtables.h>
>int main(int argc, char **argv) {
>
>        return 0;
>}
>--------
>
>then compile and link with "gcc useless.c -lxtables -ldl"
>
>As it is right now i have to define in the minimal exit_error()

I do not think a library should call exit() and cause the main program 
to terminate; to this end it might be best to add a

	void (*exit_error)(..

function pointer to the xtables_global struct you are proposing.


>
>Here's the basic change.

If you could convert iptables.c and friends to also make use of this, 
that'd be great.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: several messages
  2009-02-09 21:04 ` several messages Jan Engelhardt
@ 2009-02-09 21:27   ` jamal
  2009-02-09 21:44     ` Jan Engelhardt
  0 siblings, 1 reply; 5+ messages in thread
From: jamal @ 2009-02-09 21:27 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Patrick McHardy, Pablo Neira Ayuso, netfilter-devel

On Mon, 2009-02-09 at 22:04 +0100, Jan Engelhardt wrote:

> 
> I do not think a library should call exit() and cause the main program 
> to terminate; 
> to this end it might be best to add a
> 
> 	void (*exit_error)(..
> 
> function pointer to the xtables_global struct you are proposing.
> 
> 

Thanks for the suggestion - it sounds reasonable. 
Note, however, grep says there are about 700 references  to exit_error()
- so my intent of moving it into xtables.c is for usability more than
anything.

> If you could convert iptables.c and friends to also make use of this, 
> that'd be great.

There are only 3 definitions as far as i can see. If i can convert those
to use that global struct then I should be able to compile that basic
program.

cheers,
jamal


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: several messages
  2009-02-09 21:27   ` jamal
@ 2009-02-09 21:44     ` Jan Engelhardt
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Engelhardt @ 2009-02-09 21:44 UTC (permalink / raw)
  To: jamal; +Cc: Patrick McHardy, Pablo Neira Ayuso, netfilter-devel







On Monday 2009-02-09 22:27, jamal wrote:
>On Mon, 2009-02-09 at 22:04 +0100, Jan Engelhardt wrote:
>> 
>> I do not think a library should call exit() and cause the main program 
>> to terminate; 
>> to this end it might be best to add a
>> 
>> 	void (*exit_error)(..
>> 
>> function pointer to the xtables_global struct you are proposing.
>
>Thanks for the suggestion - it sounds reasonable. 
>Note, however, grep says there are about 700 references  to exit_error()
>- so my intent of moving it into xtables.c is for usability more than
>anything.

Hm you are right; much of the code assumes that exit_error()
never returns. We need to stick to that for the time being.

>> If you could convert iptables.c and friends to also make use of this, 
>> that'd be great.
>
>There are only 3 definitions as far as i can see. If i can convert those
>to use that global struct then I should be able to compile that basic
>program.

Yep.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxtables: Introduce global params structuring
  2009-02-09 20:57 [PATCH] libxtables: Introduce global params structuring jamal
  2009-02-09 21:04 ` several messages Jan Engelhardt
@ 2009-02-11 11:59 ` Patrick McHardy
  1 sibling, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2009-02-11 11:59 UTC (permalink / raw)
  To: hadi; +Cc: Jan Engelhardt, Pablo Neira Ayuso, netfilter-devel

jamal wrote:
> Here's the basic change.

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-02-11 11:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-09 20:57 [PATCH] libxtables: Introduce global params structuring jamal
2009-02-09 21:04 ` several messages Jan Engelhardt
2009-02-09 21:27   ` jamal
2009-02-09 21:44     ` Jan Engelhardt
2009-02-11 11:59 ` [PATCH] libxtables: Introduce global params structuring Patrick McHardy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).