From 1ce8986798f2003a9b2084a987971deedf52228e Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 23 May 2013 13:32:42 +0200 Subject: [PATCH] Use weak function pointers to call extension init functions, this makes firewall3 independant from the features compiled into iptables --- iptables.c | 33 +++++++++----------------------- iptables.h | 56 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/iptables.c b/iptables.c index 56f68c3..f39ed1e 100644 --- a/iptables.c +++ b/iptables.c @@ -54,32 +54,17 @@ get_kernel_version(void) kernel_version = LINUX_VERSION(x, y, z); } +#undef __ipt_module +#define __ipt_module(x) libxt_##x##_init, libipt_##x##_init, libip6t_##x##_init, + static void fw3_init_extensions(void) { - libip6t_icmp6_init(); - libip6t_LOG_init(); - libip6t_REJECT_init(); - libipt_DNAT_init(); - libipt_icmp_init(); - libipt_LOG_init(); - libipt_MASQUERADE_init(); - libipt_REDIRECT_init(); - libipt_REJECT_init(); - libipt_SNAT_init(); - libxt_comment_init(); - libxt_conntrack_init(); - libxt_CT_init(); - libxt_limit_init(); - libxt_mac_init(); - libxt_mark_init(); - libxt_MARK_init(); - libxt_set_init(); - libxt_SET_init(); - libxt_standard_init(); - libxt_TCPMSS_init(); - libxt_tcp_init(); - libxt_time_init(); - libxt_udp_init(); + int i; + void (*initfuncs[])(void) = { FW3_IPT_MODULES }; + + for (i = 0; i < sizeof(initfuncs)/sizeof(initfuncs[0]); i++) + if (initfuncs[i]) + initfuncs[i](); } struct fw3_ipt_handle * diff --git a/iptables.h b/iptables.h index cee9cc4..c8c86ec 100644 --- a/iptables.h +++ b/iptables.h @@ -34,30 +34,38 @@ extern struct xtables_match *xtables_pending_matches; extern struct xtables_target *xtables_pending_targets; /* libext.a interface */ -void libip6t_icmp6_init(void); -void libip6t_LOG_init(void); -void libip6t_REJECT_init(void); -void libipt_DNAT_init(void); -void libipt_icmp_init(void); -void libipt_LOG_init(void); -void libipt_MASQUERADE_init(void); -void libipt_REDIRECT_init(void); -void libipt_REJECT_init(void); -void libipt_SNAT_init(void); -void libxt_comment_init(void); -void libxt_conntrack_init(void); -void libxt_CT_init(void); -void libxt_limit_init(void); -void libxt_mac_init(void); -void libxt_mark_init(void); -void libxt_MARK_init(void); -void libxt_set_init(void); -void libxt_SET_init(void); -void libxt_standard_init(void); -void libxt_TCPMSS_init(void); -void libxt_tcp_init(void); -void libxt_time_init(void); -void libxt_udp_init(void); +#define FW3_IPT_MODULES \ + __ipt_module(comment) \ + __ipt_module(conntrack) \ + __ipt_module(icmp) \ + __ipt_module(icmp6) \ + __ipt_module(limit) \ + __ipt_module(mac) \ + __ipt_module(mark) \ + __ipt_module(set) \ + __ipt_module(standard) \ + __ipt_module(tcp) \ + __ipt_module(time) \ + __ipt_module(udp) \ + __ipt_module(CT) \ + __ipt_module(DNAT) \ + __ipt_module(LOG) \ + __ipt_module(MARK) \ + __ipt_module(MASQUERADE) \ + __ipt_module(REDIRECT) \ + __ipt_module(REJECT) \ + __ipt_module(SET) \ + __ipt_module(SNAT) \ + __ipt_module(TCPMSS) + +#undef __ipt_module +#define __ipt_module(x) \ + extern void libxt_##x##_init(void) __attribute__((weak)); \ + extern void libipt_##x##_init(void) __attribute__((weak)); \ + extern void libip6t_##x##_init(void) __attribute__((weak)); + +FW3_IPT_MODULES + /* Required by certain extensions like SNAT and DNAT */ extern int kernel_version; -- 2.25.1