[iptables] libxtables: simple aliasing macro for exit_error

Patrick McHardy netfilter-cvslog-bounces at lists.netfilter.org
Wed Feb 11 13:07:25 CET 2009


Gitweb:		http://git.netfilter.org/cgi-bin/gitweb.cgi?p=iptables.git;a=commit;h=8b7baebc93989106fd5d26b262d0ce191f8ef7c0
commit 8b7baebc93989106fd5d26b262d0ce191f8ef7c0
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 13:05:43 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 13:05:43 2009 +0100

    libxtables: simple aliasing macro for exit_error
    
    Rename xtables_globals exit_error cb to exit_err and introduce
    a very simple aliasing macro to point to it.
    convert iptables, ip6tables and iptables_xml to use it.
    Note iptables_xml does not have to define its own exit_error()
    since it can use the basic one provided.
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 7878483dfaf91adcdb7e8e88c93ded82312af39a
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 13:04:26 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 13:04:26 2009 +0100

    libxtables: Replace direct exit_error() calls inside libxtables
    
    Replace direct exit_error() calls inside libxtables with
    xt_params->exit_error().
    
    With this change; i can now compile the useless app:
    -----
     #include <xtables.h>
     int main(int argc, char **argv) {
    
            return 0;
     }
    ----
    
    with "gcc useless.c -lxtables -ldl"
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 4dcdc9b3f8f42eb3b5a1d12e1b3d2fc1e2675725
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 13:03:34 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 13:03:34 2009 +0100

    libxtables: Make ip6tables, iptables and iptables-xml use xtables_globals
    
    convert ip6tables, iptables and iptables-xml to use
    xtables_globals/xtables_set_params()
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 40a8343d3ad0cdbc3a7e69c8d970ad75807c29ed
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 13:02:21 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 13:02:21 2009 +0100

    libxtables: Add exit_error cb to xtables_globals
    
    Introduce exit_error() as part of xtables_globals structure.
    When an application registers its xtables_globals definition
    and does not specify its exit_error() it gets assigned a
    basic version
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 84c3055bf08d0a8fe5db6e5f3f96dd826a290147
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 13:00:02 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 13:00:02 2009 +0100

    libxtables: define xtables_free_opts()
    
    Introduce xtables_free_opts() an xtables variant of
    free_opts() which uses xtables_globals already set
    by xtables_set_params(). The end goal is to have all internal
    references in xtables.c use xtables_free_opts() instead of
    depending on external defined free_opts()
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 8e90ce66a99e5dc9b055a9fd14e8e9216f90233c
Author:     Jamal Hadi Salim <hadi at cyberus.ca>
AuthorDate: Wed Feb 11 12:58:54 2009 +0100
Commit:     Patrick McHardy <kaber at trash.net>
CommitDate: Wed Feb 11 12:58:54 2009 +0100

    libxtables: Introduce global params structuring
    
    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 at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>
       via  8b7baebc93989106fd5d26b262d0ce191f8ef7c0 (commit)
       via  7878483dfaf91adcdb7e8e88c93ded82312af39a (commit)
       via  4dcdc9b3f8f42eb3b5a1d12e1b3d2fc1e2675725 (commit)
       via  40a8343d3ad0cdbc3a7e69c8d970ad75807c29ed (commit)
       via  84c3055bf08d0a8fe5db6e5f3f96dd826a290147 (commit)
       via  8e90ce66a99e5dc9b055a9fd14e8e9216f90233c (commit)
      from  300e2909ba4714abc6093cba0ed860708282bd3e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8b7baebc93989106fd5d26b262d0ce191f8ef7c0
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 13:05:43 2009 +0100

    libxtables: simple aliasing macro for exit_error
    
    Rename xtables_globals exit_error cb to exit_err and introduce
    a very simple aliasing macro to point to it.
    convert iptables, ip6tables and iptables_xml to use it.
    Note iptables_xml does not have to define its own exit_error()
    since it can use the basic one provided.
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 7878483dfaf91adcdb7e8e88c93ded82312af39a
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 13:04:26 2009 +0100

    libxtables: Replace direct exit_error() calls inside libxtables
    
    Replace direct exit_error() calls inside libxtables with
    xt_params->exit_error().
    
    With this change; i can now compile the useless app:
    -----
     #include <xtables.h>
     int main(int argc, char **argv) {
    
            return 0;
     }
    ----
    
    with "gcc useless.c -lxtables -ldl"
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 4dcdc9b3f8f42eb3b5a1d12e1b3d2fc1e2675725
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 13:03:34 2009 +0100

    libxtables: Make ip6tables, iptables and iptables-xml use xtables_globals
    
    convert ip6tables, iptables and iptables-xml to use
    xtables_globals/xtables_set_params()
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 40a8343d3ad0cdbc3a7e69c8d970ad75807c29ed
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 13:02:21 2009 +0100

    libxtables: Add exit_error cb to xtables_globals
    
    Introduce exit_error() as part of xtables_globals structure.
    When an application registers its xtables_globals definition
    and does not specify its exit_error() it gets assigned a
    basic version
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 84c3055bf08d0a8fe5db6e5f3f96dd826a290147
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 13:00:02 2009 +0100

    libxtables: define xtables_free_opts()
    
    Introduce xtables_free_opts() an xtables variant of
    free_opts() which uses xtables_globals already set
    by xtables_set_params(). The end goal is to have all internal
    references in xtables.c use xtables_free_opts() instead of
    depending on external defined free_opts()
    
    Signed-off-by: Jamal Hadi Salim <hadi at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

commit 8e90ce66a99e5dc9b055a9fd14e8e9216f90233c
Author: Jamal Hadi Salim <hadi at cyberus.ca>
Date:   Wed Feb 11 12:58:54 2009 +0100

    libxtables: Introduce global params structuring
    
    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 at cyberus.ca>
    Signed-off-by: Patrick McHardy <kaber at trash.net>

-----------------------------------------------------------------------

 Makefile.am          |    1 +
 include/xtables.h.in |   15 +++++++-
 ip6tables.c          |   11 ++++++-
 iptables-xml.c       |   19 ++++-------
 iptables.c           |   13 +++++++-
 xtables.c            |   89 +++++++++++++++++++++++++++++++++++++++----------
 6 files changed, 114 insertions(+), 34 deletions(-)
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 at cyberus.ca>
Signed-off-by: Patrick McHardy <kaber at trash.net>

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")



More information about the netfilter-cvslog mailing list