netfilter 00/06: CT target
Subsystems (3)
This first part of my conntrack zones patchset contains the CT target, which is used for specifying initial conntrack parameters and will be used by the zones series for zone classification. I've seperated the two patchsets since they're mostly unrelated for easier review.
If there are no further comments or requests, I'll begin by merging this patchset into the nf-next-2.6.git tree and will post the zones patchset next.
include/linux/netfilter/Kbuild | 1 + include/linux/netfilter/nf_conntrack_common.h | 22 ++++ include/linux/netfilter/x_tables.h | 2 + include/linux/netfilter/xt_CT.h | 16 +++ include/net/netfilter/nf_conntrack_ecache.h | 58 +++++----- include/net/netfilter/nf_conntrack_helper.h | 8 +- net/bridge/netfilter/ebtables.c | 10 +- net/ipv4/netfilter/ip_tables.c | 8 +- net/ipv6/netfilter/ip6_tables.c | 8 +- net/netfilter/Kconfig | 12 ++ net/netfilter/Makefile | 1 + net/netfilter/nf_conntrack_core.c | 52 ++++++--- net/netfilter/nf_conntrack_helper.c | 44 ++++++- net/netfilter/nf_conntrack_netlink.c | 33 +++--- net/netfilter/nf_conntrack_proto_gre.c | 2 +- net/netfilter/nf_conntrack_proto_sctp.c | 2 +- net/netfilter/nf_conntrack_proto_tcp.c | 2 +- net/netfilter/nf_conntrack_proto_udp.c | 2 +- net/netfilter/nf_conntrack_proto_udplite.c | 2 +- net/netfilter/xt_CT.c | 151 +++++++++++++++++++++++++ 20 files changed, 349 insertions(+), 87 deletions(-) create mode 100644 include/linux/netfilter/xt_CT.h create mode 100644 net/netfilter/xt_CT.c
Patrick McHardy (6):
netfilter: add struct net * to target parameters
netfilter: nf_conntrack: split up IPCT_STATUS event
netfilter: ctnetlink: support selective event delivery
netfilter: ctnetlink: only assign helpers for matching protocols
netfilter: nf_conntrack: support conntrack templates
netfilter: xtables: add CT target
netfilter 01/06: add struct net * to target parameters
commit 3865f0e2d43d8a9ec3caf96f5b4435c56f61a612
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:17:15 2010 +0100
netfilter: add struct net * to target parameters
include/linux/netfilter/x_tables.h +2 -0
@@ -249,6 +249,7 @@ struct xt_target_param {* Other fields see above. */ struct xt_tgchk_param { +struct net *net;const char *table;const void *entryinfo;const struct xt_target *target;
@@ -259,6 +260,7 @@ struct xt_tgchk_param {/* Target destructor parameters */ struct xt_tgdtor_param { +struct net *net;const struct xt_target *target;void *targinfo;u_int8_t family;
net/bridge/netfilter/ebtables.c +6 -4
@@ -579,13 +579,14 @@ ebt_cleanup_match(struct ebt_entry_match *m, struct net *net, unsigned int *i) }static inline int -ebt_cleanup_watcher (struct ebt_entry_watcher *w,unsigned int *i) +ebt_cleanup_watcher (struct ebt_entry_watcher *w,struct net *net,unsigned int *i) {struct xt_tgdtor_param par;if (i && (*i)-- ==0 )return 1 ; + par.net = net; par.target = w->u.watcher; par.targinfo = w->data; par.family =NFPROTO_BRIDGE ;
@@ -606,10 +607,11 @@ ebt_cleanup_entry(struct ebt_entry *e, struct net *net, unsigned int *cnt)/* we're done */ if (cnt && (*cnt)-- ==0 )return 1 ; -EBT_WATCHER_ITERATE (e, ebt_cleanup_watcher,NULL ); +EBT_WATCHER_ITERATE (e, ebt_cleanup_watcher, net,NULL );EBT_MATCH_ITERATE (e, ebt_cleanup_match, net,NULL ); t = (struct ebt_entry_target *)(((char *)e) + e->target_offset); + par.net = net; par.target = t->u.target; par.targinfo = t->data; par.family =NFPROTO_BRIDGE ;
@@ -674,7 +676,7 @@ ebt_check_entry(struct ebt_entry *e, } i =0 ; - mtpar.net = net; + mtpar.net = tgpar.net = net; mtpar.table = tgpar.table = name; mtpar.entryinfo = tgpar.entryinfo = e; mtpar.hook_mask = tgpar.hook_mask = hookmask;
@@ -730,7 +732,7 @@ ebt_check_entry(struct ebt_entry *e, (*cnt)++;return 0 ; cleanup_watchers: -EBT_WATCHER_ITERATE (e, ebt_cleanup_watcher, &j); +EBT_WATCHER_ITERATE (e, ebt_cleanup_watcher, net, &j); cleanup_matches:EBT_MATCH_ITERATE (e, ebt_cleanup_match, net, &i);return ret;
net/ipv4/netfilter/ip_tables.c +5 -3
@@ -638,10 +638,11 @@ err:return ret; } -static int check_target (struct ipt_entry *e,const char *name) +static int check_target (struct ipt_entry *e,struct net *net,const char *name) {struct ipt_entry_target *t =ipt_get_target (e);struct xt_tgchk_param par = { + .net = net, .table = name, .entryinfo = e, .target = t->u.kernel.target,
@@ -697,7 +698,7 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name, } t->u.kernel.target = target; - ret =check_target (e, name); + ret =check_target (e, net, name);if (ret) goto err;
@@ -788,6 +789,7 @@ cleanup_entry(struct ipt_entry *e, struct net *net, unsigned int *i)IPT_MATCH_ITERATE (e, cleanup_match, net,NULL ); t =ipt_get_target (e); + par.net = net; par.target = t->u.kernel.target; par.targinfo = t->data; par.family =NFPROTO_IPV4 ;
@@ -1675,7 +1677,7 @@ compat_check_entry(struct ipt_entry *e, struct net *net, const char *name,if (ret) goto cleanup_matches; - ret =check_target (e, name); + ret =check_target (e, net, name);if (ret) goto cleanup_matches;
net/ipv6/netfilter/ip6_tables.c +5 -3
@@ -669,10 +669,11 @@ err:return ret; } -static int check_target (struct ip6t_entry *e,const char *name) +static int check_target (struct ip6t_entry *e,struct net *net,const char *name) {struct ip6t_entry_target *t =ip6t_get_target (e);struct xt_tgchk_param par = { + .net = net, .table = name, .entryinfo = e, .target = t->u.kernel.target,
@@ -729,7 +730,7 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name, } t->u.kernel.target = target; - ret =check_target (e, name); + ret =check_target (e, net, name);if (ret) goto err;
@@ -820,6 +821,7 @@ cleanup_entry(struct ip6t_entry *e, struct net *net, unsigned int *i)IP6T_MATCH_ITERATE (e, cleanup_match, net,NULL ); t =ip6t_get_target (e); + par.net = net; par.target = t->u.kernel.target; par.targinfo = t->data; par.family =NFPROTO_IPV6 ;
@@ -1710,7 +1712,7 @@ static int compat_check_entry(struct ip6t_entry *e, struct net *net,if (ret) goto cleanup_matches; - ret =check_target (e, name); + ret =check_target (e, net, name);if (ret) goto cleanup_matches;
netfilter 02/06: nf_conntrack: split up IPCT_STATUS event
In reply to Patrick McHardycommit 8d7aeb2c974994fe106c0c072063de6667ecbc34
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:17:16 2010 +0100
netfilter: nf_conntrack: split up IPCT_STATUS event
Split up the IPCT_STATUS event into an IPCT_REPLY event, which is generated when the IPS_SEEN_REPLY bit is set, and an IPCT_ASSURED event, which is generated when the IPS_ASSURED bit is set.
In combination with a following patch to support selective event delivery, this can be used for "sparse" conntrack replication: start replicating the conntrack entry after it reached the ASSURED state and that way it's SYN-flood resistant.
include/net/netfilter/nf_conntrack_ecache.h +11 -10
@@ -14,19 +14,20 @@/* Connection tracking event types */ enum ip_conntrack_events { -IPCT_NEW =0 ,/* new conntrack */ -IPCT_RELATED =1 ,/* related conntrack */ -IPCT_DESTROY =2 ,/* destroyed conntrack */ -IPCT_STATUS =3 ,/* status has changed */ -IPCT_PROTOINFO =4 ,/* protocol information has changed */ -IPCT_HELPER =5 ,/* new helper has been set */ -IPCT_MARK =6 ,/* new mark has been set */ -IPCT_NATSEQADJ =7 ,/* NAT is doing sequence adjustment */ -IPCT_SECMARK =8 ,/* new security mark has been set */ +IPCT_NEW ,/* new conntrack */ +IPCT_RELATED ,/* related conntrack */ +IPCT_DESTROY ,/* destroyed conntrack */ +IPCT_REPLY ,/* connection has seen two-way traffic */ +IPCT_ASSURED ,/* connection status has changed to assured */ +IPCT_PROTOINFO ,/* protocol information has changed */ +IPCT_HELPER ,/* new helper has been set */ +IPCT_MARK ,/* new mark has been set */ +IPCT_NATSEQADJ ,/* NAT is doing sequence adjustment */ +IPCT_SECMARK ,/* new security mark has been set */ };enum ip_conntrack_expect_events { -IPEXP_NEW =0 ,/* new expectation */ +IPEXP_NEW ,/* new expectation */ };struct nf_conntrack_ecache {
net/netfilter/nf_conntrack_core.c +1 -1
@@ -825,7 +825,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, }if (set_reply && !test_and_set_bit (IPS_SEEN_REPLY_BIT , &ct->status)) -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_REPLY , ct);return ret; }
net/netfilter/nf_conntrack_netlink.c +4 -2
@@ -1366,7 +1366,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,else events =IPCT_NEW ; - nf_conntrack_eventmask_report((1 << IPCT_STATUS) | + nf_conntrack_eventmask_report((1 << IPCT_REPLY) | + (1 << IPCT_ASSURED) | (1 << IPCT_HELPER) | (1 << IPCT_PROTOINFO) | (1 << IPCT_NATSEQADJ) |
@@ -1391,7 +1392,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,if (err ==0 ) {nf_conntrack_get (&ct->ct_general);spin_unlock_bh (&nf_conntrack_lock); - nf_conntrack_eventmask_report((1 << IPCT_STATUS) | + nf_conntrack_eventmask_report((1 << IPCT_REPLY) | + (1 << IPCT_ASSURED) | (1 << IPCT_HELPER) | (1 << IPCT_PROTOINFO) | (1 << IPCT_NATSEQADJ) |
net/netfilter/nf_conntrack_proto_gre.c +1 -1
@@ -241,7 +241,7 @@ static int gre_packet(struct nf_conn *ct, ct->proto.gre.stream_timeout);/* Also, more likely to be important, and not a probe. */ set_bit (IPS_ASSURED_BIT , &ct->status); -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_ASSURED , ct); }else nf_ct_refresh_acct (ct, ctinfo, skb, ct->proto.gre.timeout);
net/netfilter/nf_conntrack_proto_sctp.c +1 -1
@@ -377,7 +377,7 @@ static int sctp_packet(struct nf_conn *ct, new_state == SCTP_CONNTRACK_ESTABLISHED) {pr_debug ("Setting assured bit\n" );set_bit (IPS_ASSURED_BIT , &ct->status); -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_ASSURED , ct); }return NF_ACCEPT ;
net/netfilter/nf_conntrack_proto_tcp.c +1 -1
@@ -1045,7 +1045,7 @@ static int tcp_packet(struct nf_conn *ct,after SYN_RECV or a valid answer for a picked up connection. */ set_bit (IPS_ASSURED_BIT , &ct->status); -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_ASSURED , ct); }nf_ct_refresh_acct (ct, ctinfo, skb, timeout);
net/netfilter/nf_conntrack_proto_udp.c +1 -1
@@ -77,7 +77,7 @@ static int udp_packet(struct nf_conn *ct,nf_ct_refresh_acct (ct, ctinfo, skb, nf_ct_udp_timeout_stream);/* Also, more likely to be important, and not a probe */ if (!test_and_set_bit (IPS_ASSURED_BIT , &ct->status)) -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_ASSURED , ct); }else nf_ct_refresh_acct (ct, ctinfo, skb, nf_ct_udp_timeout);
net/netfilter/nf_conntrack_proto_udplite.c +1 -1
@@ -75,7 +75,7 @@ static int udplite_packet(struct nf_conn *ct, nf_ct_udplite_timeout_stream);/* Also, more likely to be important, and not a probe */ if (!test_and_set_bit (IPS_ASSURED_BIT , &ct->status)) -nf_conntrack_event_cache (IPCT_STATUS , ct); +nf_conntrack_event_cache (IPCT_ASSURED , ct); }else nf_ct_refresh_acct (ct, ctinfo, skb, nf_ct_udplite_timeout);
netfilter 03/06: ctnetlink: support selective event delivery
In reply to Patrick McHardycommit f08fc65133411a0e461f3235cd9d07f2ffb7a742
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:17:16 2010 +0100
netfilter: ctnetlink: support selective event delivery
Add two masks for conntrack end expectation events to struct nf_conntrack_ecache and use them to filter events. Their default value is "all events" when the event sysctl is on and "no events" when it is off. A following patch will add specific initializations. Expectation events depend on the ecache struct of their master conntrack.
include/linux/netfilter/nf_conntrack_common.h +18 -0
@@ -74,6 +74,24 @@ enum ip_conntrack_status { IPS_FIXED_TIMEOUT = (1 << IPS_FIXED_TIMEOUT_BIT), }; +/* Connection tracking event types */ +enum ip_conntrack_events { +IPCT_NEW ,/* new conntrack */ +IPCT_RELATED ,/* related conntrack */ +IPCT_DESTROY ,/* destroyed conntrack */ +IPCT_REPLY ,/* connection has seen two-way traffic */ +IPCT_ASSURED ,/* connection status has changed to assured */ +IPCT_PROTOINFO ,/* protocol information has changed */ +IPCT_HELPER ,/* new helper has been set */ +IPCT_MARK ,/* new mark has been set */ +IPCT_NATSEQADJ ,/* NAT is doing sequence adjustment */ +IPCT_SECMARK ,/* new security mark has been set */ +}; + +enum ip_conntrack_expect_events { +IPEXP_NEW ,/* new expectation */ +}; +#ifdef __KERNEL__ struct ip_conntrack_stat { unsigned int searched;
include/net/netfilter/nf_conntrack_ecache.h +28 -31
116 lines not on this page · raw message
net/netfilter/nf_conntrack_core.c +1 -1
@@ -648,7 +648,7 @@ init_conntrack(struct net *net, }nf_ct_acct_ext_add (ct,GFP_ATOMIC ); -nf_ct_ecache_ext_add (ct,GFP_ATOMIC ); +nf_ct_ecache_ext_add (ct,0 ,0 ,GFP_ATOMIC );spin_lock_bh (&nf_conntrack_lock); exp =nf_ct_find_expectation (net, tuple);
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -1276,7 +1276,7 @@ ctnetlink_create_conntrack(struct net *net, }nf_ct_acct_ext_add (ct,GFP_ATOMIC ); -nf_ct_ecache_ext_add (ct,GFP_ATOMIC ); +nf_ct_ecache_ext_add (ct,0 ,0 ,GFP_ATOMIC );#if defined(CONFIG_NF_CONNTRACK_MARK )if (cda[CTA_MARK ])
netfilter 04/06: ctnetlink: only assign helpers for matching protocols
In reply to Patrick McHardycommit 331b603738531949ab227d0671e204080231166c
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:17:17 2010 +0100
netfilter: ctnetlink: only assign helpers for matching protocols
Make sure not to assign a helper for a different network or transport layer protocol to a connection.
Additionally change expectation deletion by helper to compare the name directly - there might be multiple helper registrations using the same name, currently one of them is chosen in an unpredictable manner and only those expectations are removed.
include/net/netfilter/nf_conntrack_helper.h +1 -1
@@ -40,7 +40,7 @@ struct nf_conntrack_helper { };extern struct nf_conntrack_helper * -__nf_conntrack_helper_find_byname (const char *name); +__nf_conntrack_helper_find (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 *);
net/netfilter/nf_conntrack_helper.c +5 -3
@@ -65,7 +65,7 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple) }struct nf_conntrack_helper * -__nf_conntrack_helper_find_byname (const char *name) +__nf_conntrack_helper_find (const char *name,u16 l3num,u8 protonum) {struct nf_conntrack_helper *h;struct hlist_node *n;
@@ -73,13 +73,15 @@ __nf_conntrack_helper_find_byname(const char *name)for (i =0 ; i < nf_ct_helper_hsize; i++) {hlist_for_each_entry_rcu (h, n, &nf_ct_helper_hash[i], hnode) { -if (!strcmp (h->name, name)) +if (!strcmp (h->name, name) && + h->tuple.src.l3num == l3num && + h->tuple.dst.protonum == protonum)return h; } }return NULL ; } -EXPORT_SYMBOL_GPL (__nf_conntrack_helper_find_byname); +EXPORT_SYMBOL_GPL (__nf_conntrack_helper_find);struct nf_conn_help *nf_ct_helper_ext_add (struct nf_conn *ct,gfp_t gfp) {
net/netfilter/nf_conntrack_netlink.c +11 -12
@@ -1001,7 +1001,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])return 0 ; } - helper =__nf_conntrack_helper_find_byname (helpname); + helper =__nf_conntrack_helper_find (helpname,nf_ct_l3num (ct), +nf_ct_protonum (ct));if (helper ==NULL ) {#ifdef CONFIG_MODULES spin_unlock_bh (&nf_conntrack_lock);
@@ -1012,7 +1013,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[]) }spin_lock_bh (&nf_conntrack_lock); - helper =__nf_conntrack_helper_find_byname (helpname); + helper =__nf_conntrack_helper_find (helpname,nf_ct_l3num (ct), +nf_ct_protonum (ct));if (helper)return -EAGAIN ;#endif
@@ -1211,7 +1213,8 @@ ctnetlink_create_conntrack(struct net *net,if (err <0 ) goto err2; - helper =__nf_conntrack_helper_find_byname (helpname); + helper =__nf_conntrack_helper_find (helpname,nf_ct_l3num (ct), +nf_ct_protonum (ct));if (helper ==NULL ) {rcu_read_unlock ();#ifdef CONFIG_MODULES
@@ -1221,7 +1224,9 @@ ctnetlink_create_conntrack(struct net *net, }rcu_read_lock (); - helper =__nf_conntrack_helper_find_byname (helpname); + helper =__nf_conntrack_helper_find (helpname, +nf_ct_l3num (ct), +nf_ct_protonum (ct));if (helper) { err = -EAGAIN ; goto err2;
@@ -1716,7 +1721,6 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,struct net *net =sock_net (ctnl);struct nf_conntrack_expect *exp;struct nf_conntrack_tuple tuple; -struct nf_conntrack_helper *h;struct nfgenmsg *nfmsg =nlmsg_data (nlh);struct hlist_node *n, *next;u_int8_t u3 = nfmsg->nfgen_family;
@@ -1753,18 +1757,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,/* delete all expectations for this helper */ spin_lock_bh (&nf_conntrack_lock); - h =__nf_conntrack_helper_find_byname (name); -if (!h) { -spin_unlock_bh (&nf_conntrack_lock); -return -EOPNOTSUPP ; - }for (i =0 ; i < nf_ct_expect_hsize; i++) {hlist_for_each_entry_safe (exp, n, next, &net->ct.expect_hash[i], hnode) { m_help =nfct_help (exp->master); -if (m_help->helper == h - &&del_timer (&exp->timeout)) { +if (!strcmp (m_help->helper->name, name) && +del_timer (&exp->timeout)) {nf_ct_unlink_expect (exp);nf_ct_expect_put (exp); }
netfilter 05/06: nf_conntrack: support conntrack templates
In reply to Patrick McHardycommit 294e5293455427625020f101c366f0624322ccfa
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:17:18 2010 +0100
netfilter: nf_conntrack: support conntrack templates
Support initializing selected parameters of new conntrack entries from a "conntrack template", which is a specially marked conntrack entry attached to the skb.
Currently the helper and the event delivery masks can be initialized this way.
include/linux/netfilter/nf_conntrack_common.h +4 -0
@@ -72,6 +72,10 @@ enum ip_conntrack_status {/* Connection has fixed timeout. */ IPS_FIXED_TIMEOUT_BIT =10 ,IPS_FIXED_TIMEOUT = (1 <<IPS_FIXED_TIMEOUT_BIT ), + +/* Conntrack is a template */ +IPS_TEMPLATE_BIT =11 , + IPS_TEMPLATE = (1 << IPS_TEMPLATE_BIT), };/* Connection tracking event types */
include/net/netfilter/nf_conntrack_helper.h +2 -1
@@ -47,7 +47,8 @@ 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 int __nf_ct_try_assign_helper (struct nf_conn *ct,gfp_t flags); +extern int __nf_ct_try_assign_helper (struct nf_conn *ct,struct nf_conn *tmpl, +gfp_t flags);extern void nf_ct_helper_destroy (struct nf_conn *ct);
net/netfilter/nf_conntrack_core.c +34 -16
139 lines not on this page · raw message
net/netfilter/nf_conntrack_helper.c +13 -4
@@ -96,13 +96,22 @@ struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp) }EXPORT_SYMBOL_GPL (nf_ct_helper_ext_add); -int __nf_ct_try_assign_helper (struct nf_conn *ct,gfp_t flags) +int __nf_ct_try_assign_helper (struct nf_conn *ct,struct nf_conn *tmpl, +gfp_t flags) { +struct nf_conntrack_helper *helper =NULL ; +struct nf_conn_help *help;int ret =0 ; -struct nf_conntrack_helper *helper; -struct nf_conn_help *help =nfct_help (ct); - helper =__nf_ct_helper_find (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple); +if (tmpl !=NULL ) { + help =nfct_help (tmpl); +if (help !=NULL ) + helper = help->helper; + } + + help =nfct_help (ct); +if (helper ==NULL ) + helper =__nf_ct_helper_find (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple);if (helper ==NULL ) {if (help)rcu_assign_pointer (help->helper,NULL );
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -1249,7 +1249,7 @@ ctnetlink_create_conntrack(struct net *net, } }else {/* try an implicit helper assignation */ - err =__nf_ct_try_assign_helper (ct,GFP_ATOMIC ); + err =__nf_ct_try_assign_helper (ct,NULL ,GFP_ATOMIC );if (err <0 ) goto err2; }
netfilter 06/06: xtables: add CT target
In reply to Patrick McHardycommit ee07b4f51b64d68eb35725b3fc033175cbdfc14e
Author: Patrick McHardy <[email protected]> Date: Tue Feb 2 17:32:08 2010 +0100
netfilter: xtables: add CT target
Add a new target for the raw table, which can be used to specify conntrack parameters for specific connections, f.i. the conntrack helper.
The target attaches a "template" connection tracking entry to the skb, which is used by the conntrack core when initializing the new conntrack.
include/linux/netfilter/Kbuild +1 -0
@@ -6,6 +6,7 @@ header-y += nfnetlink_queue.h header-y += xt_CLASSIFY.h header-y += xt_CONNMARK.h header-y += xt_CONNSECMARK.h +header-y += xt_CT.h header-y += xt_DSCP.h header-y += xt_LED.h header-y += xt_MARK.h
include/linux/netfilter/xt_CT.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _XT_CT_H +#define _XT_CT_H + +#define XT_CT_NOTRACK 0x1 + +struct xt_ct_target_info { +u_int16_t flags; +u_int32_t ct_events; +u_int32_t exp_events; +char helper[16 ]; + +/* Used internally by the kernel */ +struct nf_conn *ct __attribute__((aligned (8 ))); +}; + +#endif /* _XT_CT_H */
include/net/netfilter/nf_conntrack_helper.h +3 -0
@@ -42,6 +42,9 @@ struct nf_conntrack_helper {extern struct nf_conntrack_helper *__nf_conntrack_helper_find (const char *name,u16 l3num,u8 protonum); +extern struct nf_conntrack_helper * +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 *);
net/netfilter/Kconfig +12 -0
@@ -341,6 +341,18 @@ config NETFILTER_XT_TARGET_CONNSECMARK To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_CT + tristate '"CT" target support' + depends on NF_CONNTRACK + depends on IP_NF_RAW || IP6_NF_RAW + depends on NETFILTER_ADVANCED + help + This options adds a `CT' target, which allows to specify initial + connection tracking parameters like events to be delivered and + the helper to be used. + + To compile it as a module, choose M here. If unsure, say N. + config NETFILTER_XT_TARGET_DSCP tristate '"DSCP" and "TOS" target support' depends on IP_NF_MANGLE || IP6_NF_MANGLE
net/netfilter/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o +obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
net/netfilter/nf_conntrack_helper.c +19 -0
@@ -83,6 +83,25 @@ __nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum) }EXPORT_SYMBOL_GPL (__nf_conntrack_helper_find); +struct nf_conntrack_helper * +nf_conntrack_helper_try_module_get (const char *name,u16 l3num,u8 protonum) +{ +struct nf_conntrack_helper *h; + + h =__nf_conntrack_helper_find (name, l3num, protonum); +#ifdef CONFIG_MODULES +if (h ==NULL ) { +if (request_module ("nfct-helper-%s" , name) ==0 ) + h =__nf_conntrack_helper_find (name, l3num, protonum); + } +#endif +if (h !=NULL && !try_module_get (h->me)) + h =NULL ; + +return h; +} +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 *help;
net/netfilter/xt_CT.c new file +151 -0
151 lines not on this page · raw message