new user-space connection tracking helper infrastructure
Subsystems (3)
[email protected]
maintainercover new user-space connection tracking helper infrastructure
From: Pablo Neira Ayuso <[email protected]>
Hi!
This is a new try to provide a full user-space connection tracking helper infrastructure. Some of you, that check my tree, already know that I've been working on this since time ago.
Previous approaches had important limitations and the integration with iptables was not precisely nice.
The initial patches prepare the field for the introduction of the cthelper infrastructure:
1) allocate fixed area for helper name, as a side effect, the initialization code of the kernel-space helpers looks better IMO.
2) allow variable length conntrack extensions.
3) add support for variable length helper extensions.
4) improve integration between nfnetlink_queue and ctnetlink. Now, you don't have to open two handlers listen to packets via nfqueue and receive events via ctnetlink. Instead, you can enable one flag to get the conntrack data together with the packet via nfqueue.
5) improve integration of packet mangling and nf_conntrack. This has been a long standing issue. If you mangle one TCP packet in user-space and connection tracking is enabled, nf_ct_tcp reports sequence tracking errors. This patch aims to resolve this issue.
6) Add CTA_HELP_INFO attribute. This is used to store the private helper data. Thus, we don't need to keep a redundant cache of conntrack entries in user-space. The private helper information is stored.
7) finally, the netlink cthelper infrastructure.
Of course, this patch makes no sense without the user-space changes, they are:
* updates in the conntrack-tools (see cthelper11 branch):
http://git.netfilter.org/cgi-bin/gitweb.cgi?p=conntrack-tools.git;a=shortlog;h=refs/heads/cthelper11
It includes the FTP user-space helper, one RPC helper (for NFSv3) and one TNS helper (for Oracle).
* libnetfilter_cthelper
http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libnetfilter_cthelper.git;a=summary
* libnetfilter_conntrack (new libmnl API)
http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libnetfilter_conntrack.git;a=summary
* libnetfilter_queue
http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libnetfilter_queue.git;a=shortlog;h=refs/heads/cthelper2
WARNING: Changes may occur in the user-space side until all those cthelper branches are merged into master. Mind that this is work-in-progress.
Pablo Neira Ayuso (7):
netfilter: nf_ct_helper: allocate 16 bytes for the helper and policy names
netfilter: nf_ct_ext: support variable length extensions
netfilter: nf_ct_helper: implement variable length helper private data
netfilter: add glue code to integrate nfnetlink_queue and ctnetlink
netfilter: nfnl_queue: support NAT TCP sequence adjustment if packet mangled
netfilter: ctnetlink: add CTA_HELP_INFO attribute
netfilter: add user-space connection tracking helper infrastructure
include/linux/netfilter.h | 10 + include/linux/netfilter/Kbuild | 1 + include/linux/netfilter/nf_conntrack_sip.h | 1 + include/linux/netfilter/nfnetlink.h | 3 +- include/linux/netfilter/nfnetlink_conntrack.h | 1 + include/linux/netfilter/nfnetlink_cthelper.h | 55 ++ include/linux/netfilter/nfnetlink_queue.h | 7 + include/linux/netfilter_ipv4.h | 1 + include/linux/netfilter_ipv6.h | 1 + include/net/netfilter/nf_conntrack.h | 35 +- include/net/netfilter/nf_conntrack_expect.h | 4 +- include/net/netfilter/nf_conntrack_extend.h | 7 +- include/net/netfilter/nf_conntrack_helper.h | 29 +- include/net/netfilter/nf_nat_helper.h | 7 + net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 56 +- net/ipv4/netfilter/nf_nat_amanda.c | 4 +- net/ipv4/netfilter/nf_nat_h323.c | 8 +- net/ipv4/netfilter/nf_nat_helper.c | 13 + net/ipv4/netfilter/nf_nat_pptp.c | 6 +- net/ipv4/netfilter/nf_nat_sip.c | 14 +- net/ipv4/netfilter/nf_nat_tftp.c | 4 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 56 +- net/netfilter/Kconfig | 8 + net/netfilter/Makefile | 1 + net/netfilter/core.c | 4 + net/netfilter/nf_conntrack_core.c | 3 +- net/netfilter/nf_conntrack_extend.c | 16 +- net/netfilter/nf_conntrack_ftp.c | 11 +- net/netfilter/nf_conntrack_h323_main.c | 16 +- net/netfilter/nf_conntrack_helper.c | 35 +- net/netfilter/nf_conntrack_irc.c | 8 +- net/netfilter/nf_conntrack_netlink.c | 190 ++++++- net/netfilter/nf_conntrack_pptp.c | 17 +- net/netfilter/nf_conntrack_proto_gre.c | 16 +- net/netfilter/nf_conntrack_sane.c | 12 +- net/netfilter/nf_conntrack_sip.c | 36 +- net/netfilter/nf_conntrack_tftp.c | 8 +- net/netfilter/nfnetlink_cthelper.c | 668 ++++++++++++++++++++++++ net/netfilter/nfnetlink_queue.c | 84 ++- net/netfilter/xt_CT.c | 44 +- 40 files changed, 1309 insertions(+), 191 deletions(-) create mode 100644 include/linux/netfilter/nfnetlink_cthelper.h create mode 100644 net/netfilter/nfnetlink_cthelper.c
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 1/7 netfilter: nf_ct_helper: allocate 16 bytes for the helper and policy names
From: Pablo Neira Ayuso <[email protected]>
This patch modifies the struct nf_conntrack_helper to allocate the room for the helper name. The maximum length is 16 bytes (this was already introduced in 2.6.24).
For the maximum length for expectation policy names, I have also selected 16 bytes.
This patch is required by the follow-up patch to support user-space connection tracking helpers.
--- include/net/netfilter/nf_conntrack_expect.h | 4 +++- include/net/netfilter/nf_conntrack_helper.h | 2 +- net/netfilter/nf_conntrack_ftp.c | 8 ++------ net/netfilter/nf_conntrack_irc.c | 8 ++------ net/netfilter/nf_conntrack_sane.c | 8 ++------ net/netfilter/nf_conntrack_sip.c | 7 ++----- net/netfilter/nf_conntrack_tftp.c | 8 ++------ 7 files changed, 14 insertions(+), 31 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +3 -1
@@ -59,10 +59,12 @@ static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)return nf_ct_net (exp->master); } +#define NF_CT_EXP_POLICY_NAME_LEN 16 +struct nf_conntrack_expect_policy {unsigned int max_expected;unsigned int timeout; -const char *name; +char name[NF_CT_EXP_POLICY_NAME_LEN ]; };#define NF_CT_EXPECT_CLASS_DEFAULT 0
include/net/netfilter/nf_conntrack_helper.h +1 -1
@@ -19,7 +19,7 @@ struct module;struct nf_conntrack_helper {struct hlist_node hnode;/* Internal use. */ -const char *name;/* name of the module */ +char name[NF_CT_HELPER_NAME_LEN ];/* name of the module */ struct module *me;/* pointer to self */ const struct nf_conntrack_expect_policy *expect_policy;
net/netfilter/nf_conntrack_ftp.c +2 -6
@@ -512,7 +512,6 @@ out_update_nl: }static struct nf_conntrack_helper ftp[MAX_PORTS ][2 ]__read_mostly ; -static char ftp_names[MAX_PORTS ][2 ][sizeof ("ftp-65535" )]__read_mostly ;static const struct nf_conntrack_expect_policy ftp_exp_policy = { .max_expected =1 ,
@@ -541,7 +540,6 @@ static void nf_conntrack_ftp_fini(void)static int __init nf_conntrack_ftp_init (void ) {int i, j =-1 , ret =0 ; -char *tmpname; ftp_buffer =kmalloc (65536 ,GFP_KERNEL );if (!ftp_buffer)
@@ -561,12 +559,10 @@ static int __init nf_conntrack_ftp_init(void) ftp[i][j].expect_policy = &ftp_exp_policy; ftp[i][j].me =THIS_MODULE ; ftp[i][j].help = help; - tmpname = &ftp_names[i][j][0 ];if (ports[i] ==FTP_PORT ) -sprintf (tmpname,"ftp" ); +sprintf (ftp[i][j].name,"ftp" );else -sprintf (tmpname,"ftp-%d" , ports[i]); - ftp[i][j].name = tmpname; +sprintf (ftp[i][j].name,"ftp-%d" , ports[i]); pr_debug("nf_ct_ftp: registering helper for pf: %d " "port: %d\n",
net/netfilter/nf_conntrack_irc.c +2 -6
@@ -223,7 +223,6 @@ static int help(struct sk_buff *skb, unsigned int protoff, }static struct nf_conntrack_helper irc[MAX_PORTS ]__read_mostly ; -static char irc_names[MAX_PORTS ][sizeof ("irc-65535" )]__read_mostly ;static struct nf_conntrack_expect_policy irc_exp_policy;static void nf_conntrack_irc_fini (void );
@@ -231,7 +230,6 @@ static void nf_conntrack_irc_fini(void);static int __init nf_conntrack_irc_init (void ) {int i, ret; -char *tmpname;if (max_dcc_channels <1 ) {printk (KERN_ERR "nf_ct_irc: max_dcc_channels must not be zero\n" );
@@ -257,12 +255,10 @@ static int __init nf_conntrack_irc_init(void) irc[i].me =THIS_MODULE ; irc[i].help = help; - tmpname = &irc_names[i][0 ];if (ports[i] ==IRC_PORT ) -sprintf (tmpname,"irc" ); +sprintf (irc[i].name,"irc" );else -sprintf (tmpname,"irc-%u" , i); - irc[i].name = tmpname; +sprintf (irc[i].name,"irc-%u" , i); ret =nf_conntrack_helper_register (&irc[i]);if (ret) {
net/netfilter/nf_conntrack_sane.c +2 -6
@@ -163,7 +163,6 @@ out: }static struct nf_conntrack_helper sane[MAX_PORTS ][2 ]__read_mostly ; -static char sane_names[MAX_PORTS ][2 ][sizeof ("sane-65535" )]__read_mostly ;static const struct nf_conntrack_expect_policy sane_exp_policy = { .max_expected =1 ,
@@ -190,7 +189,6 @@ static void nf_conntrack_sane_fini(void)static int __init nf_conntrack_sane_init (void ) {int i, j =-1 , ret =0 ; -char *tmpname; sane_buffer =kmalloc (65536 ,GFP_KERNEL );if (!sane_buffer)
@@ -210,12 +208,10 @@ static int __init nf_conntrack_sane_init(void) sane[i][j].expect_policy = &sane_exp_policy; sane[i][j].me =THIS_MODULE ; sane[i][j].help = help; - tmpname = &sane_names[i][j][0 ];if (ports[i] ==SANE_PORT ) -sprintf (tmpname,"sane" ); +sprintf (sane[i][j].name,"sane" );else -sprintf (tmpname,"sane-%d" , ports[i]); - sane[i][j].name = tmpname; +sprintf (sane[i][j].name,"sane-%d" , ports[i]); pr_debug("nf_ct_sane: registering helper for pf: %d " "port: %d\n",
net/netfilter/nf_conntrack_sip.c +2 -5
@@ -1573,7 +1573,6 @@ static void nf_conntrack_sip_fini(void)static int __init nf_conntrack_sip_init (void ) {int i, j, ret; -char *tmpname;if (ports_c ==0 ) ports[ports_c++] =SIP_PORT ;
@@ -1601,12 +1600,10 @@ static int __init nf_conntrack_sip_init(void) sip[i][j].expect_class_max =SIP_EXPECT_MAX ; sip[i][j].me =THIS_MODULE ; - tmpname = &sip_names[i][j][0 ];if (ports[i] ==SIP_PORT ) -sprintf (tmpname,"sip" ); +sprintf (sip_names[i][j],"sip" );else -sprintf (tmpname,"sip-%u" , i); - sip[i][j].name = tmpname; +sprintf (sip_names[i][j],"sip-%u" , i);pr_debug ("port #%u: %u\n" , i, ports[i]);
net/netfilter/nf_conntrack_tftp.c +2 -6
@@ -92,7 +92,6 @@ static int tftp_help(struct sk_buff *skb, }static struct nf_conntrack_helper tftp[MAX_PORTS ][2 ]__read_mostly ; -static char tftp_names[MAX_PORTS ][2 ][sizeof ("tftp-65535" )]__read_mostly ;static const struct nf_conntrack_expect_policy tftp_exp_policy = { .max_expected =1 ,
@@ -112,7 +111,6 @@ static void nf_conntrack_tftp_fini(void)static int __init nf_conntrack_tftp_init (void ) {int i, j, ret; -char *tmpname;if (ports_c ==0 ) ports[ports_c++] =TFTP_PORT ;
@@ -129,12 +127,10 @@ static int __init nf_conntrack_tftp_init(void) tftp[i][j].me =THIS_MODULE ; tftp[i][j].help = tftp_help; - tmpname = &tftp_names[i][j][0 ];if (ports[i] ==TFTP_PORT ) -sprintf (tmpname,"tftp" ); +sprintf (tftp[i][j].name,"tftp" );else -sprintf (tmpname,"tftp-%u" , i); - tftp[i][j].name = tmpname; +sprintf (tftp[i][j].name,"tftp-%u" , i); ret =nf_conntrack_helper_register (&tftp[i][j]);if (ret) {
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 2/7 netfilter: nf_ct_ext: support variable length extensions
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
We can now define conntrack extensions of variable size. This patch is useful to get rid of these unions:
union nf_conntrack_help
union nf_conntrack_proto
union nf_conntrack_nat_help
--- include/net/netfilter/nf_conntrack_extend.h | 7 ++++++- net/netfilter/nf_conntrack_extend.c | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-)
include/net/netfilter/nf_conntrack_extend.h +6 -1
@@ -79,11 +79,16 @@ static inline void nf_ct_ext_free(struct nf_conn *ct)kfree (ct->ext); } +void *__nf_ct_ext_add_length (struct nf_conn *ct,enum nf_ct_ext_id id, +size_t var_alloc_len,gfp_t gfp); +/* Add this type, returns pointer to data or NULL. */ void *__nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp);#define nf_ct_ext_add (ct, id, gfp) \ - ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp))) + ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), 0, (gfp))) +#define nf_ct_ext_add_length (ct, id, len, gfp) \ + ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), (len), (gfp)))#define NF_CT_EXT_F_PREALLOC 0x0001
net/netfilter/nf_conntrack_extend.c +9 -7
@@ -44,7 +44,8 @@ void __nf_ct_ext_destroy(struct nf_conn *ct)EXPORT_SYMBOL (__nf_ct_ext_destroy);static void * -nf_ct_ext_create (struct nf_ct_ext **ext,enum nf_ct_ext_id id,gfp_t gfp) +nf_ct_ext_create (struct nf_ct_ext **ext,enum nf_ct_ext_id id, +size_t var_alloc_len,gfp_t gfp) {unsigned int off, len;struct nf_ct_ext_type *t;
@@ -54,8 +55,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) t =rcu_dereference (nf_ct_ext_types[id]);BUG_ON (t ==NULL ); off =ALIGN (sizeof (struct nf_ct_ext ), t->align); - len = off + t->len; - alloc_size = t->alloc_size; + len = off + t->len + var_alloc_len; + alloc_size = t->alloc_size + var_alloc_len;rcu_read_unlock (); *ext =kzalloc (alloc_size, gfp);
@@ -68,7 +69,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp)return (void *)(*ext) + off; } -void *__nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp) +void *__nf_ct_ext_add_length (struct nf_conn *ct,enum nf_ct_ext_id id, +size_t var_alloc_len,gfp_t gfp) {struct nf_ct_ext *old, *new;int i, newlen, newoff;
@@ -79,7 +81,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) old = ct->ext;if (!old) -return nf_ct_ext_create (&ct->ext, id, gfp); +return nf_ct_ext_create (&ct->ext, id, var_alloc_len, gfp);if (__nf_ct_ext_exist (old, id))return NULL ;
@@ -89,7 +91,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)BUG_ON (t ==NULL ); newoff =ALIGN (old->len, t->align); - newlen = newoff + t->len; + newlen = newoff + t->len + var_alloc_len;rcu_read_unlock (); new =__krealloc (old, newlen, gfp);
@@ -117,7 +119,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)memset ((void *)new + newoff,0 , newlen - newoff);return (void *)new + newoff; } -EXPORT_SYMBOL (__nf_ct_ext_add); +EXPORT_SYMBOL (__nf_ct_ext_add_length);static void update_alloc_size (struct nf_ct_ext_type *type) {
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 3/7 netfilter: nf_ct_helper: implement variable length helper private data
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch uses the new variable length conntrack extensions.
Instead of using union nf_conntrack_help that contain all the helper private data information, we allocate variable length area to store the private helper data.
This patch includes the modification of all existing helpers. It also includes a couple of include header to avoid compilation warnings.
--- include/linux/netfilter/nf_conntrack_sip.h | 1 + include/net/netfilter/nf_conntrack.h | 35 ++------------------- include/net/netfilter/nf_conntrack_helper.h | 15 ++++++++- net/ipv4/netfilter/nf_nat_amanda.c | 4 +-- net/ipv4/netfilter/nf_nat_h323.c | 8 ++--- net/ipv4/netfilter/nf_nat_pptp.c | 6 ++-- net/ipv4/netfilter/nf_nat_sip.c | 14 ++++----- net/ipv4/netfilter/nf_nat_tftp.c | 4 +-- net/netfilter/nf_conntrack_core.c | 3 +- net/netfilter/nf_conntrack_ftp.c | 3 +- net/netfilter/nf_conntrack_h323_main.c | 16 ++++++---- net/netfilter/nf_conntrack_helper.c | 11 ++++--- net/netfilter/nf_conntrack_netlink.c | 4 +-- net/netfilter/nf_conntrack_pptp.c | 17 ++++++----- net/netfilter/nf_conntrack_proto_gre.c | 16 +++++----- net/netfilter/nf_conntrack_sane.c | 4 +-- net/netfilter/nf_conntrack_sip.c | 29 +++++++++--------- net/netfilter/xt_CT.c | 44 ++++++++++++++++----------- 18 files changed, 119 insertions(+), 115 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +1 -0
@@ -3,6 +3,7 @@#ifdef __KERNEL__#include <linux/types.h> +#include <net/netfilter/nf_conntrack_expect.h> #define SIP_PORT 5060#define SIP_TIMEOUT 3600
include/net/netfilter/nf_conntrack.h +3 -32
@@ -39,36 +39,6 @@ union nf_conntrack_expect_proto {/* insert expect proto private data here */ }; -/* Add protocol helper include file here */ -#include <linux/netfilter/nf_conntrack_ftp.h> -#include <linux/netfilter/nf_conntrack_pptp.h> -#include <linux/netfilter/nf_conntrack_h323.h> -#include <linux/netfilter/nf_conntrack_sane.h> -#include <linux/netfilter/nf_conntrack_sip.h> - -/* per conntrack: application helper private data */ -union nf_conntrack_help { -/* insert conntrack helper private data (master) here */ -#if defined(CONFIG_NF_CONNTRACK_FTP ) || defined(CONFIG_NF_CONNTRACK_FTP_MODULE ) -struct nf_ct_ftp_master ct_ftp_info; -#endif -#if defined(CONFIG_NF_CONNTRACK_PPTP ) || \ - defined(CONFIG_NF_CONNTRACK_PPTP_MODULE ) -struct nf_ct_pptp_master ct_pptp_info; -#endif -#if defined(CONFIG_NF_CONNTRACK_H323 ) || \ - defined(CONFIG_NF_CONNTRACK_H323_MODULE ) -struct nf_ct_h323_master ct_h323_info; -#endif -#if defined(CONFIG_NF_CONNTRACK_SANE ) || \ - defined(CONFIG_NF_CONNTRACK_SANE_MODULE ) -struct nf_ct_sane_master ct_sane_info; -#endif -#if defined(CONFIG_NF_CONNTRACK_SIP ) || defined(CONFIG_NF_CONNTRACK_SIP_MODULE ) -struct nf_ct_sip_master ct_sip_info; -#endif -}; -#include <linux/types.h> #include <linux/skbuff.h> #include <linux/timer.h>
@@ -89,12 +59,13 @@ struct nf_conn_help {/* Helper. if any */ struct nf_conntrack_helper __rcu *helper; -union nf_conntrack_help help; -struct hlist_head expectations;/* Current number of expected connections */ u8 expecting[NF_CT_MAX_EXPECT_CLASSES ]; + +/* private helper information. */ +char data[0 ]; };#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
include/net/netfilter/nf_conntrack_helper.h +14 -1
@@ -11,6 +11,7 @@#define _NF_CONNTRACK_HELPER_H#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_extend.h> +#include <net/netfilter/nf_conntrack_expect.h> struct module ;
@@ -23,6 +24,9 @@ struct nf_conntrack_helper {struct module *me;/* pointer to self */ const struct nf_conntrack_expect_policy *expect_policy; +/* length of internal data, ie. sizeof(struct nf_ct_*_master) */ +size_t data_len; +/* Tuple of things we will help (compared against server response) */ struct nf_conntrack_tuple tuple;
@@ -48,7 +52,7 @@ nf_conntrack_helper_try_module_get(const char *name, u16 l3num, u8 protonum);extern int nf_conntrack_helper_register (struct nf_conntrack_helper *);extern void nf_conntrack_helper_unregister (struct nf_conntrack_helper *); -extern struct nf_conn_help *nf_ct_helper_ext_add (struct nf_conn *ct,gfp_t gfp); +extern struct nf_conn_help *nf_ct_helper_ext_add (struct nf_conn *ct,struct nf_conntrack_helper *helper,gfp_t gfp);extern int __nf_ct_try_assign_helper (struct nf_conn *ct,struct nf_conn *tmpl,gfp_t flags);
@@ -60,6 +64,15 @@ static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)return nf_ct_ext_find (ct,NF_CT_EXT_HELPER ); } +static inline void *nfct_help_data (const struct nf_conn *ct) +{ +struct nf_conn_help *help; + + help =nf_ct_ext_find (ct,NF_CT_EXT_HELPER ); + +return (void *)&help->data; +} +extern int nf_conntrack_helper_init (struct net *net);extern void nf_conntrack_helper_fini (struct net *net);
net/ipv4/netfilter/nf_nat_amanda.c +2 -2
@@ -13,11 +13,11 @@#include <linux/skbuff.h> #include <linux/udp.h> -#include <net/netfilter/nf_nat_helper.h> -#include <net/netfilter/nf_nat_rule.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_expect.h> #include <linux/netfilter/nf_conntrack_amanda.h> +#include <net/netfilter/nf_nat_helper.h> +#include <net/netfilter/nf_nat_rule.h> MODULE_AUTHOR ("Brian J. Murrell <[email protected]>" );MODULE_DESCRIPTION ("Amanda NAT helper" );
net/ipv4/netfilter/nf_nat_h323.c +4 -4
@@ -99,7 +99,7 @@ static int set_sig_addr(struct sk_buff *skb, struct nf_conn *ct,unsigned char **data, TransportAddress *taddr, int count) { - const struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + const struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);int i;__be16 port;
@@ -182,7 +182,7 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,struct nf_conntrack_expect *rtp_exp, struct nf_conntrack_expect *rtcp_exp) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);int i;u_int16_t nated_port;
@@ -337,7 +337,7 @@ static int nat_h245(struct sk_buff *skb, struct nf_conn *ct, TransportAddress *taddr, __be16 port, struct nf_conntrack_expect *exp) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);u_int16_t nated_port =ntohs (port);
@@ -427,7 +427,7 @@ static int nat_q931(struct sk_buff *skb, struct nf_conn *ct, unsigned char **data, TransportAddress *taddr, int idx, __be16 port, struct nf_conntrack_expect *exp) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);u_int16_t nated_port =ntohs (port);union nf_inet_addr addr;
net/ipv4/netfilter/nf_nat_pptp.c +3 -3
@@ -49,7 +49,7 @@ static void pptp_nat_expected(struct nf_conn *ct,const struct nf_nat_pptp *nat_pptp_info;struct nf_nat_ipv4_range range; - ct_pptp_info = &nfct_help (master)->help.ct_pptp_info; + ct_pptp_info =nfct_help_data (master); nat_pptp_info = &nfct_nat (master)->help.nat_pptp_info;/* And here goes the grand finale of corrosion... */
@@ -123,7 +123,7 @@ pptp_outbound_pkt(struct sk_buff *skb,__be16 new_callid;unsigned int cid_off; - ct_pptp_info = &nfct_help (ct)->help.ct_pptp_info; + ct_pptp_info =nfct_help_data (ct); nat_pptp_info = &nfct_nat (ct)->help.nat_pptp_info; new_callid = ct_pptp_info->pns_call_id;
@@ -192,7 +192,7 @@ pptp_exp_gre(struct nf_conntrack_expect *expect_orig,struct nf_ct_pptp_master *ct_pptp_info;struct nf_nat_pptp *nat_pptp_info; - ct_pptp_info = &nfct_help (ct)->help.ct_pptp_info; + ct_pptp_info =nfct_help_data (ct); nat_pptp_info = &nfct_nat (ct)->help.nat_pptp_info;/* save original PAC call ID in nat_info */
net/ipv4/netfilter/nf_nat_sip.c +7 -7
@@ -73,7 +73,7 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];unsigned int buflen;__be32 newaddr;
@@ -86,7 +86,7 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff, }else if (ct->tuplehash[dir].tuple.dst.u3.ip == addr->ip && ct->tuplehash[dir].tuple.dst.u.udp.port == port) { newaddr = ct->tuplehash[!dir].tuple.src.u3.ip; - newport = help->help.ct_sip_info.forced_dport ? : + newport = ct_sip_info->forced_dport ? : ct->tuplehash[!dir].tuple.src.u.udp.port; }else return 1 ;
@@ -123,7 +123,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);unsigned int coff, matchoff, matchlen;enum sip_header_types hdr;union nf_inet_addr addr;
@@ -233,14 +233,14 @@ next:return NF_DROP ;/* Mangle destination port for Cisco phones, then fix up checksums */ -if (dir ==IP_CT_DIR_REPLY && help->help.ct_sip_info.forced_dport) { +if (dir ==IP_CT_DIR_REPLY && ct_sip_info->forced_dport) {struct udphdr *uh;if (!skb_make_writable (skb, skb->len))return NF_DROP ; uh = (struct udphdr *)(skb->data +ip_hdrlen (skb)); - uh->dest = help->help.ct_sip_info.forced_dport; + uh->dest = ct_sip_info->forced_dport;if (!nf_nat_mangle_udp_packet (skb, ct, ctinfo,0 ,0 ,NULL ,0 ))return NF_DROP ;
@@ -297,7 +297,7 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);__be32 newip;u_int16_t port;__be16 srcport;
@@ -313,7 +313,7 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,/* If the signalling port matches the connection's source port in the * original direction, try to use the destination port in the opposite * direction. */ - srcport = help->help.ct_sip_info.forced_dport ? : + srcport = ct_sip_info->forced_dport ? : ct->tuplehash[dir].tuple.src.u.udp.port;if (exp->tuple.dst.u.udp.port == srcport) port =ntohs (ct->tuplehash[!dir].tuple.dst.u.udp.port);
net/ipv4/netfilter/nf_nat_tftp.c +2 -2
@@ -8,11 +8,11 @@#include <linux/module.h> #include <linux/udp.h> -#include <net/netfilter/nf_nat_helper.h> -#include <net/netfilter/nf_nat_rule.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_expect.h> #include <linux/netfilter/nf_conntrack_tftp.h> +#include <net/netfilter/nf_nat_helper.h> +#include <net/netfilter/nf_nat_rule.h> MODULE_AUTHOR ("Magnus Boden <[email protected]>" );MODULE_DESCRIPTION ("TFTP NAT helper" );
net/netfilter/nf_conntrack_core.c +2 -1
@@ -822,7 +822,8 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,__set_bit (IPS_EXPECTED_BIT , &ct->status); ct->master = exp->master;if (exp->helper) { - help =nf_ct_helper_ext_add (ct,GFP_ATOMIC ); + help =nf_ct_helper_ext_add (ct, exp->helper, +GFP_ATOMIC );if (help)rcu_assign_pointer (help->helper, exp->helper); }
net/netfilter/nf_conntrack_ftp.c +2 -1
@@ -358,7 +358,7 @@ static int help(struct sk_buff *skb,u32 seq;int dir =CTINFO2DIR (ctinfo);unsigned int uninitialized_var (matchlen ),uninitialized_var (matchoff ); -struct nf_ct_ftp_master *ct_ftp_info = &nfct_help (ct)->help.ct_ftp_info; +struct nf_ct_ftp_master *ct_ftp_info =nfct_help_data (ct);struct nf_conntrack_expect *exp;union nf_inet_addr *daddr;struct nf_conntrack_man cmd = {};
@@ -554,6 +554,7 @@ static int __init nf_conntrack_ftp_init(void) ftp[i][0 ].tuple.src.l3num =PF_INET ; ftp[i][1 ].tuple.src.l3num =PF_INET6 ;for (j =0 ; j <2 ; j++) { + ftp[i][j].data_len =sizeof (struct nf_ct_ftp_master ); ftp[i][j].tuple.src.u.tcp.port =htons (ports[i]); ftp[i][j].tuple.dst.protonum =IPPROTO_TCP ; ftp[i][j].expect_policy = &ftp_exp_policy;
net/netfilter/nf_conntrack_h323_main.c +10 -6
@@ -114,7 +114,7 @@ static int get_tpkt_data(struct sk_buff *skb, unsigned int protoff, struct nf_conn *ct, enum ip_conntrack_info ctinfo, unsigned char **data, int *datalen, int *dataoff) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);const struct tcphdr *th;struct tcphdr _tcph;
@@ -619,6 +619,7 @@ static const struct nf_conntrack_expect_policy h245_exp_policy = {static struct nf_conntrack_helper nf_conntrack_helper_h245__read_mostly = { .name ="H.245" , .me =THIS_MODULE , + .data_len =sizeof (struct nf_ct_h323_master ), .tuple.src.l3num =AF_UNSPEC , .tuple.dst.protonum =IPPROTO_UDP , .help = h245_help,
@@ -1172,6 +1173,7 @@ static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = { { .name = "Q.931", .me = THIS_MODULE, + .data_len = sizeof(struct nf_ct_h323_master), .tuple.src.l3num = AF_INET, .tuple.src.u.tcp.port = cpu_to_be16(Q931_PORT), .tuple.dst.protonum = IPPROTO_TCP,
@@ -1247,7 +1249,7 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,unsigned char **data, TransportAddress *taddr, int count) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);int ret =0 ;int i;
@@ -1362,7 +1364,7 @@ static int process_rrq(struct sk_buff *skb, struct nf_conn *ct,enum ip_conntrack_info ctinfo, unsigned char **data, RegistrationRequest *rrq) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int ret;typeof (set_ras_addr_hook) set_ras_addr;
@@ -1397,7 +1399,7 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,enum ip_conntrack_info ctinfo, unsigned char **data, RegistrationConfirm *rcf) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);int ret;struct nf_conntrack_expect *exp;
@@ -1446,7 +1448,7 @@ static int process_urq(struct sk_buff *skb, struct nf_conn *ct,enum ip_conntrack_info ctinfo, unsigned char **data, UnregistrationRequest *urq) { - struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);int ret;typeof (set_sig_addr_hook) set_sig_addr;
@@ -1478,7 +1480,7 @@ static int process_arq(struct sk_buff *skb, struct nf_conn *ct,enum ip_conntrack_info ctinfo, unsigned char **data, AdmissionRequest *arq) { - const struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; + const struct nf_ct_h323_master *info = nfct_help_data(ct);int dir =CTINFO2DIR (ctinfo);__be16 port;union nf_inet_addr addr;
@@ -1746,6 +1748,7 @@ static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = { { .name = "RAS", .me = THIS_MODULE, + .data_len = sizeof(struct nf_ct_h323_master), .tuple.src.l3num = AF_INET, .tuple.src.u.udp.port = cpu_to_be16(RAS_PORT), .tuple.dst.protonum = IPPROTO_UDP,
@@ -1755,6 +1758,7 @@ static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = { { .name = "RAS", .me = THIS_MODULE, + .data_len = sizeof(struct nf_ct_h323_master), .tuple.src.l3num = AF_INET6, .tuple.src.u.udp.port = cpu_to_be16(RAS_PORT), .tuple.dst.protonum = IPPROTO_UDP,
net/netfilter/nf_conntrack_helper.c +7 -4
@@ -161,11 +161,14 @@ nf_conntrack_helper_try_module_get(const char *name, u16 l3num, u8 protonum) }EXPORT_SYMBOL_GPL (nf_conntrack_helper_try_module_get); -struct nf_conn_help *nf_ct_helper_ext_add (struct nf_conn *ct,gfp_t gfp) +struct nf_conn_help * +nf_ct_helper_ext_add (struct nf_conn *ct, +struct nf_conntrack_helper *helper,gfp_t gfp) {struct nf_conn_help *help; - help =nf_ct_ext_add (ct,NF_CT_EXT_HELPER , gfp); + help =nf_ct_ext_add_length (ct,NF_CT_EXT_HELPER , + helper->data_len, gfp);if (help)INIT_HLIST_HEAD (&help->expectations);else
@@ -218,13 +221,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, }if (help ==NULL ) { - help =nf_ct_helper_ext_add (ct, flags); + help =nf_ct_helper_ext_add (ct, helper, flags);if (help ==NULL ) { ret = -ENOMEM ; goto out; } }else { -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 ,sizeof (helper->data_len)); }rcu_assign_pointer (help->helper, helper);
net/netfilter/nf_conntrack_netlink.c +2 -2
@@ -1218,7 +1218,7 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])if (help->helper)return -EBUSY ;/* need to zero data of old helper */ -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 , help->helper->data_len); }else {/* we cannot set a helper for an existing conntrack */ return -EOPNOTSUPP ;
@@ -1440,7 +1440,7 @@ ctnetlink_create_conntrack(struct net *net, u16 zone, }else {struct nf_conn_help *help; - help =nf_ct_helper_ext_add (ct,GFP_ATOMIC ); + help =nf_ct_helper_ext_add (ct, helper,GFP_ATOMIC );if (help ==NULL ) { err = -ENOMEM ; goto err2;
net/netfilter/nf_conntrack_pptp.c +9 -8
@@ -174,7 +174,7 @@ static int destroy_sibling_or_exp(struct net *net, struct nf_conn *ct,static void pptp_destroy_siblings (struct nf_conn *ct) {struct net *net =nf_ct_net (ct); -const struct nf_conn_help *help =nfct_help (ct); +const struct nf_ct_pptp_master *ct_pptp_info =nfct_help_data (ct);struct nf_conntrack_tuple t;nf_ct_gre_keymap_destroy (ct);
@@ -182,16 +182,16 @@ static void pptp_destroy_siblings(struct nf_conn *ct)/* try original (pns->pac) tuple */ memcpy (&t, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple,sizeof (t)); t.dst.protonum =IPPROTO_GRE ; - t.src.u.gre.key = help->help.ct_pptp_info.pns_call_id; - t.dst.u.gre.key = help->help.ct_pptp_info.pac_call_id; + t.src.u.gre.key = ct_pptp_info->pns_call_id; + t.dst.u.gre.key = ct_pptp_info->pac_call_id;if (!destroy_sibling_or_exp (net, ct, &t))pr_debug ("failed to timeout original pns->pac ct/exp\n" );/* try reply (pac->pns) tuple */ memcpy (&t, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple,sizeof (t)); t.dst.protonum =IPPROTO_GRE ; - t.src.u.gre.key = help->help.ct_pptp_info.pac_call_id; - t.dst.u.gre.key = help->help.ct_pptp_info.pns_call_id; + t.src.u.gre.key = ct_pptp_info->pac_call_id; + t.dst.u.gre.key = ct_pptp_info->pns_call_id;if (!destroy_sibling_or_exp (net, ct, &t))pr_debug ("failed to timeout reply pac->pns ct/exp\n" ); }
@@ -269,7 +269,7 @@ pptp_inbound_pkt(struct sk_buff *skb,struct nf_conn *ct, enum ip_conntrack_info ctinfo) { - struct nf_ct_pptp_master *info = &nfct_help(ct)->help.ct_pptp_info; + struct nf_ct_pptp_master *info = nfct_help_data(ct);u_int16_t msg;__be16 cid =0 , pcid =0 ;typeof (nf_nat_pptp_hook_inbound) nf_nat_pptp_inbound;
@@ -396,7 +396,7 @@ pptp_outbound_pkt(struct sk_buff *skb,struct nf_conn *ct, enum ip_conntrack_info ctinfo) { - struct nf_ct_pptp_master *info = &nfct_help(ct)->help.ct_pptp_info; + struct nf_ct_pptp_master *info = nfct_help_data(ct);u_int16_t msg;__be16 cid =0 , pcid =0 ;typeof (nf_nat_pptp_hook_outbound) nf_nat_pptp_outbound;
@@ -506,7 +506,7 @@ conntrack_pptp_help(struct sk_buff *skb, unsigned int protoff, {int dir =CTINFO2DIR (ctinfo); -const struct nf_ct_pptp_master *info = &nfct_help (ct)->help.ct_pptp_info; +const struct nf_ct_pptp_master *info =nfct_help_data (ct);const struct tcphdr *tcph;struct tcphdr _tcph;const struct pptp_pkt_hdr *pptph;
@@ -592,6 +592,7 @@ static const struct nf_conntrack_expect_policy pptp_exp_policy = {static struct nf_conntrack_helper pptp__read_mostly = { .name ="pptp" , .me =THIS_MODULE , + .data_len =sizeof (struct nf_ct_pptp_master ), .tuple.src.l3num =AF_INET , .tuple.src.u.tcp.port =cpu_to_be16 (PPTP_CONTROL_PORT ), .tuple.dst.protonum =IPPROTO_TCP ,
net/netfilter/nf_conntrack_proto_gre.c +8 -8
@@ -110,10 +110,10 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir, {struct net *net =nf_ct_net (ct);struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_pptp_master *ct_pptp_info =nfct_help_data (ct);struct nf_ct_gre_keymap **kmp, *km; - kmp = &help->help.ct_pptp_info.keymap[dir]; + kmp = &ct_pptp_info->keymap[dir];if (*kmp) {/* check whether it's a retransmission */ read_lock_bh (&net_gre->keymap_lock);
@@ -151,19 +151,19 @@ void nf_ct_gre_keymap_destroy(struct nf_conn *ct) {struct net *net =nf_ct_net (ct);struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_pptp_master *ct_pptp_info =nfct_help_data (ct);enum ip_conntrack_dir dir;pr_debug ("entering for ct %p\n" , ct);write_lock_bh (&net_gre->keymap_lock);for (dir =IP_CT_DIR_ORIGINAL ; dir <IP_CT_DIR_MAX ; dir++) { -if (help->help.ct_pptp_info.keymap[dir]) { +if (ct_pptp_info->keymap[dir]) {pr_debug ("removing %p from list\n" , - help->help.ct_pptp_info.keymap[dir]); -list_del (&help->help.ct_pptp_info.keymap[dir]->list); -kfree (help->help.ct_pptp_info.keymap[dir]); - help->help.ct_pptp_info.keymap[dir] =NULL ; + ct_pptp_info->keymap[dir]); +list_del (&ct_pptp_info->keymap[dir]->list); +kfree (ct_pptp_info->keymap[dir]); + ct_pptp_info->keymap[dir] =NULL ; } }write_unlock_bh (&net_gre->keymap_lock);
net/netfilter/nf_conntrack_sane.c +2 -2
@@ -69,13 +69,12 @@ static int help(struct sk_buff *skb,void *sb_ptr;int ret =NF_ACCEPT ;int dir =CTINFO2DIR (ctinfo); -struct nf_ct_sane_master *ct_sane_info; +struct nf_ct_sane_master *ct_sane_info =nfct_help_data (ct);struct nf_conntrack_expect *exp;struct nf_conntrack_tuple *tuple;struct sane_request *req;struct sane_reply_net_start *reply; - ct_sane_info = &nfct_help (ct)->help.ct_sane_info;/* Until there's been traffic both ways, don't look in packets. */ if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )
@@ -203,6 +202,7 @@ static int __init nf_conntrack_sane_init(void) sane[i][0 ].tuple.src.l3num =PF_INET ; sane[i][1 ].tuple.src.l3num =PF_INET6 ;for (j =0 ; j <2 ; j++) { + sane[i][j].data_len =sizeof (struct nf_ct_sane_master ); sane[i][j].tuple.src.u.tcp.port =htons (ports[i]); sane[i][j].tuple.dst.protonum =IPPROTO_TCP ; sane[i][j].expect_policy = &sane_exp_policy;
net/netfilter/nf_conntrack_sip.c +15 -14
@@ -1075,12 +1075,12 @@ static int process_invite_response(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);if ((code >=100 && code <=199 ) || (code >=200 && code <=299 ))return process_sdp (skb, dataoff, dptr, datalen, cseq); -else if (help->help.ct_sip_info.invite_cseq == cseq) +else if (ct_sip_info->invite_cseq == cseq)flush_expectations (ct, true);return NF_ACCEPT ; }
@@ -1091,12 +1091,12 @@ static int process_update_response(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);if ((code >=100 && code <=199 ) || (code >=200 && code <=299 ))return process_sdp (skb, dataoff, dptr, datalen, cseq); -else if (help->help.ct_sip_info.invite_cseq == cseq) +else if (ct_sip_info->invite_cseq == cseq)flush_expectations (ct, true);return NF_ACCEPT ; }
@@ -1107,12 +1107,12 @@ static int process_prack_response(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);if ((code >=100 && code <=199 ) || (code >=200 && code <=299 ))return process_sdp (skb, dataoff, dptr, datalen, cseq); -else if (help->help.ct_sip_info.invite_cseq == cseq) +else if (ct_sip_info->invite_cseq == cseq)flush_expectations (ct, true);return NF_ACCEPT ; }
@@ -1123,13 +1123,13 @@ static int process_invite_request(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);unsigned int ret;flush_expectations (ct, true); ret =process_sdp (skb, dataoff, dptr, datalen, cseq);if (ret ==NF_ACCEPT ) - help->help.ct_sip_info.invite_cseq = cseq; + ct_sip_info->invite_cseq = cseq;return ret; }
@@ -1154,7 +1154,7 @@ static int process_register_request(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);unsigned int matchoff, matchlen;struct nf_conntrack_expect *exp;
@@ -1235,7 +1235,7 @@ static int process_register_request(struct sk_buff *skb, unsigned int dataoff, store_cseq:if (ret ==NF_ACCEPT ) - help->help.ct_sip_info.register_cseq = cseq; + ct_sip_info->register_cseq = cseq;return ret; }
@@ -1245,7 +1245,7 @@ static int process_register_response(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);union nf_inet_addr addr;__be16 port;
@@ -1262,7 +1262,7 @@ static int process_register_response(struct sk_buff *skb, unsigned int dataoff,* responses, so we store the sequence number of the last valid * request and compare it here. */ -if (help->help.ct_sip_info.register_cseq != cseq) +if (ct_sip_info->register_cseq != cseq)return NF_ACCEPT ;if (code >=100 && code <=199 )
@@ -1363,7 +1363,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct); +struct nf_ct_sip_master *ct_sip_info =nfct_help_data (ct);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);unsigned int matchoff, matchlen;unsigned int cseq, i;
@@ -1381,7 +1381,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int dataoff, &matchlen, &addr, &port) > 0 && port != ct->tuplehash[dir].tuple.src.u.udp.port && nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3)) - help->help.ct_sip_info.forced_dport = port; + ct_sip_info->forced_dport = port;for (i =0 ; i <ARRAY_SIZE (sip_handlers); i++) {const struct sip_handler *handler;
@@ -1595,6 +1595,7 @@ static int __init nf_conntrack_sip_init(void) sip[i][3 ].help = sip_help_tcp;for (j =0 ; j <ARRAY_SIZE (sip[i]); j++) { + sip[i][j].data_len =sizeof (struct nf_ct_sip_master ); sip[i][j].tuple.src.u.udp.port =htons (ports[i]); sip[i][j].expect_policy = sip_exp_policy; sip[i][j].expect_class_max =SIP_EXPECT_MAX ;
net/netfilter/xt_CT.c +26 -18
76 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 4/7 netfilter: add glue code to integrate nfnetlink_queue and ctnetlink
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch allows you to include the conntrack information together with the packet that is sent to user-space via NFQUEUE.
Previously, there was no integration between ctnetlink and nfnetlink_queue. If you wanted to access conntrack information from your libnetfilter_queue program, you required to query ctnetlink from user-space to obtain it. Thus, delaying the packet processing even more.
Including the conntrack information is optional, you can set it via NFQNL_F_CONNTRACK flag with the new NFQ_CFG_FLAGS attribute.
This change provides the required features to use nfnetlink_queue as the user-space queueing infrastructure for the follow-up patch that introduces user-space conntrack helpers.
--- include/linux/netfilter.h | 10 ++ include/linux/netfilter/nfnetlink_queue.h | 7 ++ net/netfilter/core.c | 4 + net/netfilter/nf_conntrack_netlink.c | 158 ++++++++++++++++++++++++++++- net/netfilter/nfnetlink_queue.c | 62 +++++++++++ 5 files changed, 240 insertions(+), 1 deletion(-)
include/linux/netfilter.h +10 -0
@@ -383,6 +383,16 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)extern void (*ip_ct_attach)(struct sk_buff *,struct sk_buff *)__rcu ;extern void nf_ct_attach (struct sk_buff *,struct sk_buff *);extern void (*nf_ct_destroy)(struct nf_conntrack *)__rcu ; + +struct nf_conn ; +struct nlattr ; + +struct nfq_ct_hook { +size_t (*build_size)(const struct nf_conn *ct); +int (*build)(struct sk_buff *skb,struct nf_conn *ct); +int (*parse)(const struct nlattr *attr,struct nf_conn *ct); +}; +extern struct nfq_ct_hook *nfq_ct_hook;#else static inline void nf_ct_attach (struct sk_buff *new,struct sk_buff *skb) {}#endif
include/linux/netfilter/nfnetlink_queue.h +7 -0
@@ -42,6 +42,8 @@ enum nfqnl_attr_type {NFQA_IFINDEX_PHYSOUTDEV ,/* __u32 ifindex */ NFQA_HWADDR ,/* nfqnl_msg_packet_hw */ NFQA_PAYLOAD ,/* opaque data payload */ +NFQA_CT ,/* nf_conntrack_netlink.h */ +NFQA_CT_INFO ,/* enum ip_conntrack_info */ __NFQA_MAX };
@@ -78,12 +80,17 @@ struct nfqnl_msg_config_params {__u8 copy_mode;/* enum nfqnl_config_mode */ } __attribute__ ((packed)); +enum nfqnl_flags { +NFQNL_F_NONE =0 , +NFQNL_F_CONNTRACK = (1 <<0 ), +};enum nfqnl_attr_config {NFQA_CFG_UNSPEC ,NFQA_CFG_CMD ,/* nfqnl_msg_config_cmd */ NFQA_CFG_PARAMS ,/* nfqnl_msg_config_params */ NFQA_CFG_QUEUE_MAXLEN ,/* __u32 */ +NFQA_CFG_FLAGS ,/* __u32 */ __NFQA_CFG_MAX };#define NFQA_CFG_MAX (__NFQA_CFG_MAX-1)
net/netfilter/core.c +4 -0
@@ -264,6 +264,10 @@ void nf_conntrack_destroy(struct nf_conntrack *nfct) rcu_read_unlock(); }EXPORT_SYMBOL (nf_conntrack_destroy); + +struct nfq_ct_hook *nfq_ct_hook; +EXPORT_SYMBOL_GPL (nfq_ct_hook); +#endif /* CONFIG_NF_CONNTRACK */ #ifdef CONFIG_PROC_FS
net/netfilter/nf_conntrack_netlink.c +157 -1
176 lines not on this page · raw message
net/netfilter/nfnetlink_queue.c +62 -0
116 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 5/7 netfilter: nfnl_queue: support NAT TCP sequence adjustment if packet mangled
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
User-space programs that receive traffic via NFQUEUE may mangle packets. If NAT is enabled, this usually puzzles sequence tracking, leading to traffic disruptions.
With this patch, nfnl_queue will make the corresponding NAT TCP sequence adjustment if:
1) The packet has been mangled,
2) the NFQNL_F_CONNTRACK flag has been set, and
3) NAT is detected.
This is required by the new user-space cthelper infrastructure. By now, we only support TCP since we have no helpers for DCCP or SCTP. Better to add this if we do ever need it.
You can still use this without the cthelper infrastructure. There are several post on the Internet complaning about this (mostly people using NFQUEUE for IDS).
--- include/net/netfilter/nf_nat_helper.h | 7 ++++++ net/ipv4/netfilter/nf_nat_helper.c | 13 ++++++++++ net/netfilter/nfnetlink_queue.c | 42 ++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 14 deletions(-)
include/net/netfilter/nf_nat_helper.h +7 -0
@@ -46,6 +46,13 @@ extern int (*nf_nat_seq_adjust_hook)(struct sk_buff *skb,struct nf_conn *ct, enum ip_conntrack_info ctinfo); +extern void nf_nat_tcp_seq_adjust (struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +int off); + +struct nf_conntrack_expect ; +/* Setup NAT on this expected conntrack so it follows master, but goes * to port ct->master->saved_proto. */ extern void nf_nat_follow_master(struct nf_conn *ct,
net/ipv4/netfilter/nf_nat_helper.c +13 -0
@@ -153,6 +153,19 @@ void nf_nat_set_seq_adjust(struct nf_conn *ct, enum ip_conntrack_info ctinfo, }EXPORT_SYMBOL_GPL (nf_nat_set_seq_adjust); +void nf_nat_tcp_seq_adjust (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo,int off) +{ +const struct tcphdr *th; + +if (nf_ct_protonum (ct) !=IPPROTO_TCP ) +return ; + + th = (struct tcphdr *)(skb_network_header (skb)+ip_hdrlen (skb)); +nf_nat_set_seq_adjust (ct, ctinfo, th->seq, off); +} +EXPORT_SYMBOL_GPL (nf_nat_tcp_seq_adjust); +static void nf_nat_csum (struct sk_buff *skb,const struct iphdr *iph,void *data,int datalen,__sum16 *check,int oldlen) {
net/netfilter/nfnetlink_queue.c +28 -14
78 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 6/7 netfilter: ctnetlink: add CTA_HELP_INFO attribute
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This attribute can be used to modify and to dump the internal protocol information. This is required by the follow-up patch that adds the user-space cthelper infrastructure.
--- include/linux/netfilter/nfnetlink_conntrack.h | 1 + include/net/netfilter/nf_conntrack_helper.h | 1 + net/netfilter/nf_conntrack_netlink.c | 28 ++++++++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-)
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -191,6 +191,7 @@ enum ctattr_expect_nat {enum ctattr_help {CTA_HELP_UNSPEC ,CTA_HELP_NAME , +CTA_HELP_INFO , __CTA_HELP_MAX };#define CTA_HELP_MAX (__CTA_HELP_MAX - 1)
include/net/netfilter/nf_conntrack_helper.h +1 -0
@@ -39,6 +39,7 @@ struct nf_conntrack_helper {void (*destroy)(struct nf_conn *ct); +int (*from_nlattr)(struct nlattr *attr,struct nf_conn *ct);int (*to_nlattr)(struct sk_buff *skb,const struct nf_conn *ct);unsigned int expect_class_max; };
net/netfilter/nf_conntrack_netlink.c +23 -5
@@ -901,7 +901,8 @@ static const struct nla_policy help_nla_policy[CTA_HELP_MAX+1] = { };static inline int -ctnetlink_parse_help (const struct nlattr *attr,char **helper_name) +ctnetlink_parse_help (const struct nlattr *attr,char **helper_name, +struct nlattr **helpinfo) {struct nlattr *tb[CTA_HELP_MAX +1 ];
@@ -912,6 +913,9 @@ ctnetlink_parse_help(const struct nlattr *attr, char **helper_name) *helper_name =nla_data (tb[CTA_HELP_NAME ]); +if (tb[CTA_HELP_INFO ]) + *helpinfo = tb[CTA_HELP_INFO ]; +return 0 ; }
@@ -1172,13 +1176,14 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])struct nf_conntrack_helper *helper;struct nf_conn_help *help =nfct_help (ct);char *helpname =NULL ; +struct nlattr *helpinfo =NULL ;int err;/* don't change helper of sibling connections */ if (ct->master)return -EBUSY ; - err =ctnetlink_parse_help (cda[CTA_HELP ], &helpname); + err =ctnetlink_parse_help (cda[CTA_HELP ], &helpname, &helpinfo);if (err <0 )return err;
@@ -1213,8 +1218,12 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[]) }if (help) { -if (help->helper == helper) +if (help->helper == helper) { +/* update private helper data if allowed. */ +if (helper->from_nlattr && helpinfo) + helper->from_nlattr (helpinfo, ct);return 0 ; + }if (help->helper)return -EBUSY ;/* need to zero data of old helper */
@@ -1410,8 +1419,9 @@ ctnetlink_create_conntrack(struct net *net, u16 zone,rcu_read_lock ();if (cda[CTA_HELP ]) {char *helpname =NULL ; - - err =ctnetlink_parse_help (cda[CTA_HELP ], &helpname); +struct nlattr *helpinfo =NULL ; + + err =ctnetlink_parse_help (cda[CTA_HELP ], &helpname, &helpinfo);if (err <0 ) goto err2;
@@ -1445,6 +1455,9 @@ ctnetlink_create_conntrack(struct net *net, u16 zone, err = -ENOMEM ; goto err2; } +/* set private helper data if allowed. */ +if (helper->from_nlattr && helpinfo) + helper->from_nlattr (helpinfo, ct);/* not in hash table yet so not strictly necessary */ RCU_INIT_POINTER (help->helper, helper);
@@ -1745,6 +1758,11 @@ ctnetlink_nfqueue_parse(const struct nlattr *attr, struct nf_conn *ct)if (err <0 )return err; } +if (cda[CTA_HELP ]) { + err =ctnetlink_change_helper (ct, cda); +if (err <0 ) +return err; + }#if defined(CONFIG_NF_CONNTRACK_MARK )if (cda[CTA_MARK ]) ct->mark =ntohl (nla_get_be32 (cda[CTA_MARK ]));
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 7/7 netfilter: add user-space connection tracking helper infrastructure
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
There are good reasons to supports helpers in user-space instead:
* Rapid connection tracking helper development, as developing code in user-space is usually faster.
* Reliability: A buggy helper does not crash the kernel. Moreover, we can monitor the helper process and restart it in case of problems.
* Security: Avoid complex string matching and mangling in kernel-space running in unprivileged mode. Going further, we can even think about running user-space helpers as a non-root process.
* It allows the development of very specific helpers (most likely non-standard proprietary protocols) that are very likely to be rejected for mainline inclusion in the form of kernel-space connection tracking helpers.
This patch adds the infrastructure to allow the implementation of user-space conntrack helpers by means of the new nfnetlink subsystem `nfnetlink_cthelper' and the existing queueing infrastructure (nfnetlink_queue).
I had to add the new hook NF_IP6_PRI_CONNTRACK_HELPER to register ipv[4|6]_helper which results from splitting ipv[4|6]_confirm into two pieces. This change is required not to break NAT sequence adjustment and conntrack confirmation for traffic that is enqueued to our user-space conntrack helpers.
Basic operation, in a few steps:
1) Register user-space helper by means of `nfct':
nfct helper add ftp inet
[ It must be a valid existing helper supported by conntrack-tools.
2) Add rules to enable the FTP user-space helper which is used to track traffic going to TCP port 10000.
For locally generated packets:
iptables -I OUTPUT -t raw -p tcp --dport 21 -j CT --helper ftp
For non-locally generated packets:
iptables -I PREROUTING -t raw -p tcp --dport 21 -j CT --helper ftp
3) Run the test conntrackd in helper mode (see example files under doc/helper/conntrackd.conf
conntrackd
4) Generate FTP traffic going, if everything is OK, then conntrackd should create expectations (you can check that with `conntrack':
conntrack -E expect
[NEW] 301 proto=6 src=192.168.1.136 dst=130.89.148.12 sport=0 dport=54037 mask-src=255.255.255.255 mask-dst=255.255.255.255 sport=0 dport=65535 master-src=192.168.1.136 master-dst=130.89.148.12 sport=57127 dport=21 class=0 helper=ftp
[DESTROY] 301 proto=6 src=192.168.1.136 dst=130.89.148.12 sport=0 dport=54037 mask-src=255.255.255.255 mask-dst=255.255.255.255 sport=0 dport=65535 master-src=192.168.1.136 master-dst=130.89.148.12 sport=57127 dport=21 class=0 helper=ftp
This confirms that our test helper is receiving packets including the conntrack information, and adding expectations in kernel-space.
The user-space helper can also store its private tracking information in the conntrack structure in the kernel via the CTA_HELP_INFO. The kernel will consider this a binary blob whose layout is unknown. This information will be included in the information that is transfered to user-space via glue code that integrates nfnetlink_queue and ctnetlink.
--- include/linux/netfilter/Kbuild | 1 + include/linux/netfilter/nfnetlink.h | 3 +- include/linux/netfilter/nfnetlink_cthelper.h | 55 ++ include/linux/netfilter_ipv4.h | 1 + include/linux/netfilter_ipv6.h | 1 + include/net/netfilter/nf_conntrack_helper.h | 11 + net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 56 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 56 +- net/netfilter/Kconfig | 8 + net/netfilter/Makefile | 1 + net/netfilter/nf_conntrack_helper.c | 24 +- net/netfilter/nfnetlink_cthelper.c | 668 ++++++++++++++++++++++++ 12 files changed, 858 insertions(+), 27 deletions(-) create mode 100644 include/linux/netfilter/nfnetlink_cthelper.h create mode 100644 net/netfilter/nfnetlink_cthelper.c
include/linux/netfilter/Kbuild +1 -0
@@ -10,6 +10,7 @@ header-y += nfnetlink.h header-y += nfnetlink_acct.h header-y += nfnetlink_compat.h header-y += nfnetlink_conntrack.h +header-y += nfnetlink_cthelper.h header-y += nfnetlink_cttimeout.h header-y += nfnetlink_log.h header-y += nfnetlink_queue.h
include/linux/netfilter/nfnetlink.h +2 -1
@@ -50,7 +50,8 @@ struct nfgenmsg {#define NFNL_SUBSYS_IPSET 6#define NFNL_SUBSYS_ACCT 7#define NFNL_SUBSYS_CTNETLINK_TIMEOUT 8 -#define NFNL_SUBSYS_COUNT 9 +#define NFNL_SUBSYS_CTHELPER 9 +#define NFNL_SUBSYS_COUNT 10#ifdef __KERNEL__
include/linux/netfilter/nfnetlink_cthelper.h new file +55 -0
55 lines not on this page · raw message
include/linux/netfilter_ipv4.h +1 -0
@@ -66,6 +66,7 @@ enum nf_ip_hook_priorities {NF_IP_PRI_SECURITY =50 ,NF_IP_PRI_NAT_SRC =100 ,NF_IP_PRI_SELINUX_LAST =225 , +NF_IP_PRI_CONNTRACK_HELPER =300 ,NF_IP_PRI_CONNTRACK_CONFIRM =INT_MAX , NF_IP_PRI_LAST = INT_MAX, };
include/linux/netfilter_ipv6.h +1 -0
@@ -71,6 +71,7 @@ enum nf_ip6_hook_priorities {NF_IP6_PRI_SECURITY =50 ,NF_IP6_PRI_NAT_SRC =100 ,NF_IP6_PRI_SELINUX_LAST =225 , +NF_IP6_PRI_CONNTRACK_HELPER =300 , NF_IP6_PRI_LAST = INT_MAX, };
include/net/netfilter/nf_conntrack_helper.h +11 -0
@@ -15,6 +15,11 @@struct module ; +enum nf_ct_helper_flags { +NF_CT_HELPER_F_USERSPACE = (1 <<0 ), +NF_CT_HELPER_F_CONFIGURED = (1 <<1 ), +}; +#define NF_CT_HELPER_NAME_LEN 16struct nf_conntrack_helper {
@@ -42,6 +47,9 @@ struct nf_conntrack_helper {int (*from_nlattr)(struct nlattr *attr,struct nf_conn *ct);int (*to_nlattr)(struct sk_buff *skb,const struct nf_conn *ct);unsigned int expect_class_max; + +unsigned int flags; +unsigned int queue_num;/* For user-space helpers. */ }; extern struct nf_conntrack_helper *
@@ -96,4 +104,7 @@ nf_ct_helper_expectfn_find_by_name(const char *name);struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_symbol (const void *symbol); +extern struct hlist_head *nf_ct_helper_hash; +extern unsigned int nf_ct_helper_hsize; +#endif /*_NF_CONNTRACK_HELPER_H*/
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +45 -11
99 lines not on this page · raw message
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +46 -10
97 lines not on this page · raw message
net/netfilter/Kconfig +8 -0
@@ -12,6 +12,14 @@ tristate "Netfilter NFACCT over NFNETLINK interface" If this option is enabled, the kernel will include support for extended accounting via NFNETLINK. +config NETFILTER_NETLINK_CTHELPER +tristate "Netfilter NFCT_HELPER over NFNETLINK interface" + depends on NETFILTER_ADVANCED + select NETFILTER_NETLINK + help + If this option is enabled, the kernel will include support + for user-space connection tracking helpers via NFNETLINK. + config NETFILTER_NETLINK_QUEUE tristate "Netfilter NFQUEUE over NFNETLINK interface" depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_NETFILTER) = netfilter.o obj-$(CONFIG_NETFILTER_NETLINK) += nfnetlink.o obj-$(CONFIG_NETFILTER_NETLINK_ACCT) += nfnetlink_acct.o +obj-$(CONFIG_NETFILTER_NETLINK_CTHELPER) += nfnetlink_cthelper.o obj-$(CONFIG_NETFILTER_NETLINK_QUEUE) += nfnetlink_queue.o obj-$(CONFIG_NETFILTER_NETLINK_LOG) += nfnetlink_log.o
net/netfilter/nf_conntrack_helper.c +19 -5
@@ -30,8 +30,10 @@#include <net/netfilter/nf_conntrack_extend.h> static DEFINE_MUTEX (nf_ct_helper_mutex); -static struct hlist_head *nf_ct_helper_hash__read_mostly ; -static unsigned int nf_ct_helper_hsize__read_mostly ; +struct hlist_head *nf_ct_helper_hash__read_mostly ; +EXPORT_SYMBOL_GPL (nf_ct_helper_hash); +unsigned int nf_ct_helper_hsize__read_mostly ; +EXPORT_SYMBOL_GPL (nf_ct_helper_hsize);static unsigned int nf_ct_helper_count__read_mostly ;static bool nf_ct_auto_assign_helper__read_mostly = true;
@@ -322,18 +324,30 @@ EXPORT_SYMBOL_GPL(nf_ct_helper_expectfn_find_by_symbol);int nf_conntrack_helper_register (struct nf_conntrack_helper *me) { +int ret =0 ; +struct nf_conntrack_helper *cur; +struct hlist_node *n;unsigned int h =helper_hash (&me->tuple); -BUG_ON (me->expect_policy ==NULL ); +BUG_ON (me->expect_policy ==NULL && + !(me->flags &NF_CT_HELPER_F_USERSPACE ));BUG_ON (me->expect_class_max >=NF_CT_MAX_EXPECT_CLASSES );BUG_ON (strlen (me->name) >NF_CT_HELPER_NAME_LEN -1 );mutex_lock (&nf_ct_helper_mutex); +hlist_for_each_entry (cur, n, &nf_ct_helper_hash[h], hnode) { +if (strncmp (cur->name, me->name,NF_CT_HELPER_NAME_LEN ) ==0 && + cur->tuple.src.l3num == me->tuple.src.l3num && + cur->tuple.dst.protonum == me->tuple.dst.protonum) { + ret = -EEXIST ; + goto out; + } + }hlist_add_head_rcu (&me->hnode, &nf_ct_helper_hash[h]); nf_ct_helper_count++; +out:mutex_unlock (&nf_ct_helper_mutex); - -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (nf_conntrack_helper_register);
net/netfilter/nfnetlink_cthelper.c new file +668 -0
668 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH 3/7] netfilter: nf_ct_helper: implement variable length helper private data
In reply to [email protected]include/net/netfilter/nf_conntrack_helper.h static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct) · line 74
Quoted 8 lines · On Monday 2012-06-04 14:21, [email protected] wrote:
include/net/netfilter/nf_conntrack_helper.h +8
-0+static inline void *nfct_help_data (const struct nf_conn *ct) +{ +struct nf_conn_help *help; + + help =nf_ct_ext_find (ct,NF_CT_EXT_HELPER ); + +return (void *)&help->data; +}
I think you wanted
return help->data;
here. Remember that help->data is of type char[0] which is convertible to char* - which is what you want,
while adding an extra & would turn that into the undesired (char[0])*.
include/net/netfilter/nf_conntrack.h struct nf_conn_help { · line 68
Quoted 13 lines
include/net/netfilter/nf_conntrack.h +3
-2@@ -89,12 +59,13 @@ struct nf_conn_help {/* Helper. if any */ struct nf_conntrack_helper __rcu *helper; -union nf_conntrack_help help; -struct hlist_head expectations;/* Current number of expected connections */ u8 expecting[NF_CT_MAX_EXPECT_CLASSES ]; + +/* private helper information. */ +char data[0 ];
There is a now-standardized notation:
char data[];
Quoted 4 lines
net/netfilter/nf_conntrack_helper.c +0
-0@@ -218,13 +221,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, }if (help ==NULL ) {
net/netfilter/nf_conntrack_helper.c int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, · line 231
Quoted 10 lines
net/netfilter/nf_conntrack_helper.c +2
-2- help =nf_ct_helper_ext_add (ct, flags); + help =nf_ct_helper_ext_add (ct, helper, flags);if (help ==NULL ) { ret = -ENOMEM ; goto out; } }else { -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 ,sizeof (helper->data_len)); }
memset(help->data, 0, sizeof(helper->data_len));
net/netfilter/nf_conntrack_netlink.c ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[]) · line 1221
Quoted 9 lines
index 6f4b00a..30f5e12 100644
net/netfilter/nf_conntrack_netlink.c +1
-1@@ -1218,7 +1218,7 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])if (help->helper)return -EBUSY ;/* need to zero data of old helper */ -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 , help->helper->data_len);
Here too.. memset(help->data,...
Re: [PATCH 3/7] netfilter: nf_ct_helper: implement variable length helper private data
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines · On Monday 2012-06-04 14:21, [email protected] wrote:
(quoted diff) +0
-0@@ -218,13 +221,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, }
Quoted 13 lines
net/netfilter/nf_conntrack_helper.c int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, · line 231
Quoted 11 lines
net/netfilter/nf_conntrack_helper.c +2
-2if (help ==NULL ) { - help =nf_ct_helper_ext_add (ct, flags); + help =nf_ct_helper_ext_add (ct, helper, flags);if (help ==NULL ) { ret = -ENOMEM ; goto out; } }else { -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 ,sizeof (helper->data_len)); }
memset(help->data, 0, sizeof(helper->data_len));
memset(help->data, 0, helper->data_len);
Re: [PATCH 3/7] netfilter: nf_ct_helper: implement variable length helper private data
Quoted 20 lines · Joe Perches
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines · On Monday 2012-06-04 14:21, [email protected] wrote:
(quoted diff) +0
-0@@ -218,13 +221,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, }Quoted 13 lines
net/netfilter/nf_conntrack_helper.c int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, · line 231
Quoted 11 lines
net/netfilter/nf_conntrack_helper.c +2
-2if (help ==NULL ) { - help =nf_ct_helper_ext_add (ct, flags); + help =nf_ct_helper_ext_add (ct, helper, flags);if (help ==NULL ) { ret = -ENOMEM ; goto out; } }else { -memset (&help->help,0 ,sizeof (help->help)); +memset (&help->data,0 ,sizeof (helper->data_len)); }
memset(help->data, 0, sizeof(helper->data_len));
Quoted 1 line
memset(help->data, 0, helper->data_len);
I knew this looked suspect. With so many "sizeof"s, this spot was starting to look like a "mine is bigger" competition.
Re: [PATCH 4/7] netfilter: add glue code to integrate nfnetlink_queue and ctnetlink
In reply to [email protected]net/netfilter/nf_conntrack_netlink.c ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, · line 1716
Quoted 4 lines · On Monday 2012-06-04 14:21, [email protected] wrote:
net/netfilter/nf_conntrack_netlink.c +4
-0+static int +ctnetlink_nfqueue_parse (const struct nlattr *attr,struct nf_conn *ct) +{ +const struct nlattr *const cda[CTA_MAX +1 ];
I suppose you wrote that because the same appears in function headers/signatures
void foo(const struct nlattr *const tb[]) { ... }But there, it is actually equal to
void foo(const struct nlattr *const *tb) { ... }In either case, tb is writable. IMHO, [] should be avoided in signatures to avoid self-confusion, as it seemed to occur in your case, where cda is - unlike tb - really marked const. You likely wanted
const struct nlattr *cda[CTA_MAX+1];
Quoted 1 line
+
nla_parse_nested((struct nlattr **)cda, CTA_MAX, attr, ct_nla_policy);
Re: [PATCH 7/7] netfilter: add user-space connection tracking helper infrastructure
In reply to [email protected]net/netfilter/nfnetlink_cthelper.c line 85
Quoted 9 lines · On Monday 2012-06-04 14:21, [email protected] wrote:
net/netfilter/nfnetlink_cthelper.c new file +9
-0+static int +nfnl_cthelper_from_nlattr (struct nlattr *attr,struct nf_conn *ct) +{ +const struct nf_conn_help *help =nfct_help (ct); + +if (help->helper->data_len ==0 ) +return -EINVAL ; + +memcpy (&help->data,nla_data (attr), help->helper->data_len);
memcpy(help->data, ...)
net/netfilter/nfnetlink_cthelper.c line 96
Quoted 8 lines
net/netfilter/nfnetlink_cthelper.c new file +8
-0+static int +nfnl_cthelper_to_nlattr (struct sk_buff *skb,const struct nf_conn *ct) +{ +const struct nf_conn_help *help =nfct_help (ct); + +if (help->helper->data_len && +nla_put (skb,CTA_HELP_INFO , help->helper->data_len, &help->data)) + goto nla_put_failure;
help->data
Re: [PATCH 7/7] netfilter: add user-space connection tracking helper infrastructure
In reply to [email protected]Quoted 2 lines · [email protected] writes:
* Security: Avoid complex string matching and mangling in kernel-space running in unprivileged mode.
Or rather in privileged mode?
Quoted 2 lines
2) Add rules to enable the FTP user-space helper which is used to track traffic going to TCP port 10000.
The examples use port 21 in the iptables commands and the expectations:
Quoted 5 lines
iptables -I OUTPUT -t raw -p tcp --dport 21 -j CT --helper ftp iptables -I PREROUTING -t raw -p tcp --dport 21 -j CT --helper ftp
[NEW] 301 proto=6 src=192.168.1.136 dst=130.89.148.12 sport=0 dport=54037 mask-src=255.255.255.255 mask-dst=255.255.255.255 sport=0 dport=65535 master-src=192.168.1.136 master-dst=130.89.148.12 sport=57127 dport=21 class=0 helper=ftp[DESTROY] 301 proto=6 src=192.168.1.136 dst=130.89.148.12 sport=0 dport=54037 mask-src=255.255.255.255 mask-dst=255.255.255.255 sport=0 dport=65535 master-src=192.168.1.136 master-dst=130.89.148.12 sport=57127 dport=21 class=0 helper=ftp
Signature · 2 lines
Regards, Feri.