Netfilter updates for nf-next tree (2.6.31) (2nd try)
Subsystems (2)
Pablo Neira Ayuso
maintainercover Netfilter updates for nf-next tree (2.6.31) (2nd try)
Here it follows the first bunch of updates for your nf-next tree (2nd try). This patchset is mostly oriented to cleanups and the conntrack event subsystem.
You can pull this changes from:
git://1984.lsi.us.es/nf-next-2.6 master
This is the first time that I prepare a git tree to be pulled, so let me know if I'm missing anything!
---
Pablo Neira Ayuso (9):
netfilter: conntrack: replace notify chain by function pointer
netfilter: conntrack: simplify event caching system
netfilter: conntrack: remove events flags from userspace exposed file
netfilter: conntrack: don't report events on module removal
netfilter: ctnetlink: cleanup message-size calculation
netfilter: ctnetlink: use nlmsg_* helper function to build messages
netfilter: ctnetlink: rename tuple() by nf_ct_tuple() macro definition
netfilter: ctnetlink: remove nowait parameter from *fill_info()
netfilter: nfnetlink: cleanup for nfnetlink_rcv_msg() function
include/linux/netfilter/nf_conntrack_common.h | 69 ------ include/linux/netfilter/nfnetlink.h | 2 include/net/netfilter/nf_conntrack.h | 4 include/net/netfilter/nf_conntrack_ecache.h | 113 +++++++++- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 1 net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 1 net/netfilter/nf_conntrack_core.c | 29 +-- net/netfilter/nf_conntrack_ecache.c | 101 ++++++++- net/netfilter/nf_conntrack_ftp.c | 2 net/netfilter/nf_conntrack_netlink.c | 261 +++++++++++------------- net/netfilter/nf_conntrack_proto_tcp.c | 1 net/netfilter/nfnetlink.c | 28 +-- 12 files changed, 321 insertions(+), 291 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/9 netfilter: nfnetlink: cleanup for nfnetlink_rcv_msg() function
This patch cleans up the message handling path in two aspects:
* it uses NLMSG_LENGTH() instead of NLMSG_SPACE() like rtnetlink
does in this case to check if there is enough room for the Netlink/nfnetlink headers. No need to check for the padding room.
* it removes a redundant header size checking that has been already do at the beginning of the function.
---
net/netfilter/nfnetlink.c | 23 +++++++++-------------- 1 files changed, 9 insertions(+), 14 deletions(-)
net/netfilter/nfnetlink.c +9 -14
@@ -136,7 +136,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)return -EPERM ;/* All the messages must at least contain nfgenmsg */ -if (nlh->nlmsg_len <NLMSG_SPACE (sizeof (struct nfgenmsg ))) +if (nlh->nlmsg_len <NLMSG_LENGTH (sizeof (struct nfgenmsg )))return 0 ; type = nlh->nlmsg_type;
@@ -160,19 +160,14 @@ replay: {int min_len =NLMSG_SPACE (sizeof (struct nfgenmsg ));u_int8_t cb_id =NFNL_MSG_TYPE (nlh->nlmsg_type); -u_int16_t attr_count = ss->cb[cb_id].attr_count; -struct nlattr *cda[attr_count+1 ]; - -if (likely (nlh->nlmsg_len >= min_len)) { -struct nlattr *attr = (void *)nlh +NLMSG_ALIGN (min_len); -int attrlen = nlh->nlmsg_len -NLMSG_ALIGN (min_len); - - err =nla_parse (cda, attr_count, attr, attrlen, - ss->cb[cb_id].policy); -if (err <0 ) -return err; - }else -return -EINVAL ; +struct nlattr *cda[ss->cb[cb_id].attr_count +1 ]; +struct nlattr *attr = (void *)nlh + min_len; +int attrlen = nlh->nlmsg_len - min_len; + + err =nla_parse (cda, ss->cb[cb_id].attr_count, + attr, attrlen, ss->cb[cb_id].policy); +if (err <0 ) +return err; err = nc->call (nfnl, skb, nlh, cda);if (err == -EAGAIN )
Pablo Neira Ayuso
maintainerPATCH 2/9 netfilter: ctnetlink: remove nowait parameter from *fill_info()
In reply to Pablo Neira AyusoThis patch is a cleanup, it removes the `nowait' parameter from all *fill_info() function since it is always set to one.
---
net/netfilter/nf_conntrack_netlink.c | 24 ++++++++++-------------- 1 files changed, 10 insertions(+), 14 deletions(-)
net/netfilter/nf_conntrack_netlink.c +10 -14
@@ -350,8 +350,7 @@ nla_put_failure:static int ctnetlink_fill_info (struct sk_buff *skb,u32 pid,u32 seq, -int event,int nowait, -const struct nf_conn *ct) +int event,const struct nf_conn *ct) {struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;
@@ -362,7 +361,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, nlh =NLMSG_PUT (skb, pid, seq, event,sizeof (struct nfgenmsg )); nfmsg =NLMSG_DATA (nlh); - nlh->nlmsg_flags = (nowait && pid) ?NLM_F_MULTI :0 ; + nlh->nlmsg_flags = pid ?NLM_F_MULTI :0 ; nfmsg->nfgen_family =nf_ct_l3num (ct); nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -637,8 +636,7 @@ restart: }if (ctnetlink_fill_info (skb,NETLINK_CB (cb->skb).pid, cb->nlh->nlmsg_seq, -IPCTNL_MSG_CT_NEW , -1 , ct) <0 ) { +IPCTNL_MSG_CT_NEW , ct) <0 ) { cb->args[1 ] = (unsigned long )ct; goto out; }
@@ -880,7 +878,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,rcu_read_lock (); err =ctnetlink_fill_info (skb2,NETLINK_CB (skb).pid, nlh->nlmsg_seq, -IPCTNL_MSG_CT_NEW ,1 , ct); +IPCTNL_MSG_CT_NEW , ct);rcu_read_unlock ();nf_ct_put (ct);if (err <=0 )
@@ -1503,9 +1501,7 @@ nla_put_failure:static int ctnetlink_exp_fill_info (struct sk_buff *skb,u32 pid,u32 seq, -int event, -int nowait, -const struct nf_conntrack_expect *exp) +int event,const struct nf_conntrack_expect *exp) {struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;
@@ -1515,7 +1511,7 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, nlh =NLMSG_PUT (skb, pid, seq, event,sizeof (struct nfgenmsg )); nfmsg =NLMSG_DATA (nlh); - nlh->nlmsg_flags = (nowait && pid) ?NLM_F_MULTI :0 ; + nlh->nlmsg_flags = pid ?NLM_F_MULTI :0 ; nfmsg->nfgen_family = exp->tuple.src.l3num; nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -1617,10 +1613,11 @@ restart:continue ; cb->args[1 ] =0 ; } -if (ctnetlink_exp_fill_info (skb,NETLINK_CB (cb->skb).pid, +if (ctnetlink_exp_fill_info (skb, +NETLINK_CB (cb->skb).pid, cb->nlh->nlmsg_seq,IPCTNL_MSG_EXP_NEW , -1 , exp) <0 ) { + exp) <0 ) {if (!atomic_inc_not_zero (&exp->use))continue ; cb->args[1 ] = (unsigned long )exp;
@@ -1689,8 +1686,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,rcu_read_lock (); err =ctnetlink_exp_fill_info (skb2,NETLINK_CB (skb).pid, - nlh->nlmsg_seq,IPCTNL_MSG_EXP_NEW , -1 , exp); + nlh->nlmsg_seq,IPCTNL_MSG_EXP_NEW , exp);rcu_read_unlock ();if (err <=0 ) goto free;
Pablo Neira Ayuso
maintainerPATCH 3/9 netfilter: ctnetlink: rename tuple() by nf_ct_tuple() macro definition
In reply to Pablo Neira AyusoThis patch move the internal tuple() macro definition to the header file as nf_ct_tuple().
---
include/net/netfilter/nf_conntrack.h | 2 ++ net/netfilter/nf_conntrack_netlink.c | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack.h +2 -0
@@ -144,6 +144,8 @@ static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)return ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum; } +#define nf_ct_tuple (ct, dir) (&(ct)->tuplehash[dir].tuple) +/* get master conntrack via master expectation */ #define master_ct (conntr) (conntr->master)
net/netfilter/nf_conntrack_netlink.c +6 -7
@@ -346,8 +346,6 @@ nla_put_failure:return -1 ; } -#define tuple (ct, dir) (&(ct)->tuplehash[dir].tuple) -static int ctnetlink_fill_info (struct sk_buff *skb,u32 pid,u32 seq,int event,const struct nf_conn *ct)
@@ -369,14 +367,14 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, nest_parms =nla_nest_start (skb,CTA_TUPLE_ORIG |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -if (ctnetlink_dump_tuples (skb,tuple (ct,IP_CT_DIR_ORIGINAL )) <0 ) +if (ctnetlink_dump_tuples (skb,nf_ct_tuple (ct,IP_CT_DIR_ORIGINAL )) <0 ) goto nla_put_failure;nla_nest_end (skb, nest_parms); nest_parms =nla_nest_start (skb,CTA_TUPLE_REPLY |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -if (ctnetlink_dump_tuples (skb,tuple (ct,IP_CT_DIR_REPLY )) <0 ) +if (ctnetlink_dump_tuples (skb,nf_ct_tuple (ct,IP_CT_DIR_REPLY )) <0 ) goto nla_put_failure;nla_nest_end (skb, nest_parms);
@@ -509,7 +507,8 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,if (!item->report && !nfnetlink_has_listeners (group))return NOTIFY_DONE ; - skb =ctnetlink_alloc_skb (tuple (ct,IP_CT_DIR_ORIGINAL ),GFP_ATOMIC ); + skb =ctnetlink_alloc_skb (nf_ct_tuple (ct,IP_CT_DIR_ORIGINAL ), +GFP_ATOMIC );if (!skb) goto errout;
@@ -528,14 +527,14 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, nest_parms =nla_nest_start (skb,CTA_TUPLE_ORIG |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -if (ctnetlink_dump_tuples (skb,tuple (ct,IP_CT_DIR_ORIGINAL )) <0 ) +if (ctnetlink_dump_tuples (skb,nf_ct_tuple (ct,IP_CT_DIR_ORIGINAL )) <0 ) goto nla_put_failure;nla_nest_end (skb, nest_parms); nest_parms =nla_nest_start (skb,CTA_TUPLE_REPLY |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -if (ctnetlink_dump_tuples (skb,tuple (ct,IP_CT_DIR_REPLY )) <0 ) +if (ctnetlink_dump_tuples (skb,nf_ct_tuple (ct,IP_CT_DIR_REPLY )) <0 ) goto nla_put_failure;nla_nest_end (skb, nest_parms);
Pablo Neira Ayuso
maintainerPATCH 4/9 netfilter: ctnetlink: use nlmsg_* helper function to build messages
In reply to Pablo Neira AyusoReplaces the old macros to build Netlink messages with the new nlmsg_*() helper functions.
---
net/netfilter/nf_conntrack_netlink.c | 84 +++++++++++++++++----------------- 1 files changed, 42 insertions(+), 42 deletions(-)
net/netfilter/nf_conntrack_netlink.c +42 -42
@@ -353,13 +353,14 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;struct nlattr *nest_parms; -unsigned char *b =skb_tail_pointer (skb); +unsigned int flags = pid ?NLM_F_MULTI :0 ; event |=NFNL_SUBSYS_CTNETLINK <<8 ; - nlh =NLMSG_PUT (skb, pid, seq, event,sizeof (struct nfgenmsg )); - nfmsg =NLMSG_DATA (nlh); + nlh =nlmsg_put (skb, pid, seq, event,sizeof (*nfmsg), flags); +if (nlh ==NULL ) + goto nlmsg_failure; - nlh->nlmsg_flags = pid ?NLM_F_MULTI :0 ; + nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family =nf_ct_l3num (ct); nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -392,12 +393,12 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, ctnetlink_dump_nat_seq_adj(skb, ct) < 0) goto nla_put_failure; - nlh->nlmsg_len =skb_tail_pointer (skb) - b; +nlmsg_end (skb, nlh);return skb->len; nlmsg_failure: nla_put_failure: -nlmsg_trim (skb, b); +nlmsg_cancel (skb, nlh);return -1 ; }
@@ -431,7 +432,7 @@ ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp)#define NLA_TYPE_SIZE (type) nla_total_size(sizeof(type))/* proto independant part */ - len =NLMSG_SPACE (sizeof (struct nfgenmsg )) + len =NLMSG_ALIGN (sizeof (struct nfgenmsg )) +3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +3 *nla_total_size (0 )/* CTA_TUPLE_IP */ +3 *nla_total_size (0 )/* CTA_TUPLE_PROTO */
@@ -471,7 +472,7 @@ ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp) len += l4proto->nla_size;rcu_read_unlock (); -return alloc_skb (len, gfp); +return nlmsg_new (len, gfp); } static int ctnetlink_conntrack_event(struct notifier_block *this,
@@ -484,7 +485,6 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,struct nf_conn *ct = item->ct;struct sk_buff *skb;unsigned int type; -sk_buff_data_t b;unsigned int flags =0 , group;/* ignore our fake conntrack entry */
@@ -512,13 +512,12 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,if (!skb) goto errout; - b = skb->tail; - type |=NFNL_SUBSYS_CTNETLINK <<8 ; - nlh =NLMSG_PUT (skb, item->pid,0 , type,sizeof (struct nfgenmsg )); - nfmsg =NLMSG_DATA (nlh); + nlh =nlmsg_put (skb, item->pid,0 , type,sizeof (*nfmsg), flags); +if (nlh ==NULL ) + goto nlmsg_failure; - nlh->nlmsg_flags = flags; + nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family =nf_ct_l3num (ct); nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -582,12 +581,13 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,#endif rcu_read_unlock (); - nlh->nlmsg_len = skb->tail - b; +nlmsg_end (skb, nlh);nfnetlink_send (skb, item->pid, group, item->report);return NOTIFY_DONE ; nla_put_failure:rcu_read_unlock (); +nlmsg_cancel (skb, nlh); nlmsg_failure:kfree_skb (skb); errout:
@@ -609,7 +609,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)struct nf_conn *ct, *last;struct nf_conntrack_tuple_hash *h;struct hlist_nulls_node *n; -struct nfgenmsg *nfmsg =NLMSG_DATA (cb->nlh); +struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);u_int8_t l3proto = nfmsg->nfgen_family;rcu_read_lock ();
@@ -789,7 +789,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,struct nf_conntrack_tuple_hash *h;struct nf_conntrack_tuple tuple;struct nf_conn *ct; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int8_t u3 = nfmsg->nfgen_family;int err =0 ;
@@ -844,7 +844,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,struct nf_conntrack_tuple tuple;struct nf_conn *ct;struct sk_buff *skb2 =NULL ; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int8_t u3 = nfmsg->nfgen_family;int err =0 ;
@@ -869,8 +869,8 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, ct =nf_ct_tuplehash_to_ctrack (h); err = -ENOMEM ; - skb2 =alloc_skb (NLMSG_GOODSIZE ,GFP_KERNEL ); -if (!skb2) { + skb2 =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (skb2 ==NULL ) {nf_ct_put (ct);return -ENOMEM ; }
@@ -1322,7 +1322,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, {struct nf_conntrack_tuple otuple, rtuple;struct nf_conntrack_tuple_hash *h =NULL ; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int8_t u3 = nfmsg->nfgen_family;int err =0 ;
@@ -1504,13 +1504,14 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, {struct nlmsghdr *nlh;struct nfgenmsg *nfmsg; -unsigned char *b =skb_tail_pointer (skb); +unsigned int flags = pid ?NLM_F_MULTI :0 ; event |=NFNL_SUBSYS_CTNETLINK_EXP <<8 ; - nlh =NLMSG_PUT (skb, pid, seq, event,sizeof (struct nfgenmsg )); - nfmsg =NLMSG_DATA (nlh); + nlh =nlmsg_put (skb, pid, seq, event,sizeof (*nfmsg), flags); +if (nlh ==NULL ) + goto nlmsg_failure; - nlh->nlmsg_flags = pid ?NLM_F_MULTI :0 ; + nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = exp->tuple.src.l3num; nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -1518,12 +1519,12 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,if (ctnetlink_exp_dump_expect (skb, exp) <0 ) goto nla_put_failure; - nlh->nlmsg_len =skb_tail_pointer (skb) - b; +nlmsg_end (skb, nlh);return skb->len; nlmsg_failure: nla_put_failure: -nlmsg_trim (skb, b); +nlmsg_cancel (skb, nlh);return -1 ; }
@@ -1537,7 +1538,6 @@ static int ctnetlink_expect_event(struct notifier_block *this,struct nf_conntrack_expect *exp = item->exp;struct sk_buff *skb;unsigned int type; -sk_buff_data_t b;int flags =0 ;if (events &IPEXP_NEW ) {
@@ -1550,17 +1550,16 @@ static int ctnetlink_expect_event(struct notifier_block *this, !nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW))return NOTIFY_DONE ; - skb =alloc_skb (NLMSG_GOODSIZE ,GFP_ATOMIC ); -if (!skb) + skb =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_ATOMIC ); +if (skb ==NULL ) goto errout; - b = skb->tail; - type |=NFNL_SUBSYS_CTNETLINK_EXP <<8 ; - nlh =NLMSG_PUT (skb, item->pid,0 , type,sizeof (struct nfgenmsg )); - nfmsg =NLMSG_DATA (nlh); + nlh =nlmsg_put (skb, item->pid,0 , type,sizeof (*nfmsg), flags); +if (nlh ==NULL ) + goto nlmsg_failure; - nlh->nlmsg_flags = flags; + nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = exp->tuple.src.l3num; nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
@@ -1570,12 +1569,13 @@ static int ctnetlink_expect_event(struct notifier_block *this, goto nla_put_failure;rcu_read_unlock (); - nlh->nlmsg_len = skb->tail - b; +nlmsg_end (skb, nlh);nfnetlink_send (skb, item->pid,NFNLGRP_CONNTRACK_EXP_NEW , item->report);return NOTIFY_DONE ; nla_put_failure:rcu_read_unlock (); +nlmsg_cancel (skb, nlh); nlmsg_failure:kfree_skb (skb); errout:
@@ -1595,7 +1595,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) {struct net *net = &init_net;struct nf_conntrack_expect *exp, *last; -struct nfgenmsg *nfmsg =NLMSG_DATA (cb->nlh); +struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);struct hlist_node *n;u_int8_t l3proto = nfmsg->nfgen_family;
@@ -1648,7 +1648,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,struct nf_conntrack_tuple tuple;struct nf_conntrack_expect *exp;struct sk_buff *skb2; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int8_t u3 = nfmsg->nfgen_family;int err =0 ;
@@ -1679,8 +1679,8 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, } err = -ENOMEM ; - skb2 =alloc_skb (NLMSG_GOODSIZE ,GFP_KERNEL ); -if (!skb2) + skb2 =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (skb2 ==NULL ) goto out;rcu_read_lock ();
@@ -1708,7 +1708,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,struct nf_conntrack_expect *exp;struct nf_conntrack_tuple tuple;struct nf_conntrack_helper *h; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);struct hlist_node *n, *next;u_int8_t u3 = nfmsg->nfgen_family;unsigned int i;
@@ -1849,7 +1849,7 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb, {struct nf_conntrack_tuple tuple;struct nf_conntrack_expect *exp; -struct nfgenmsg *nfmsg =NLMSG_DATA (nlh); +struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int8_t u3 = nfmsg->nfgen_family;int err =0 ;
Pablo Neira Ayuso
maintainerPATCH 5/9 netfilter: ctnetlink: cleanup message-size calculation
In reply to Pablo Neira AyusoThis patch cleans up the message calculation to make it similar to rtnetlink, moreover, it removes unneeded verbose information.
---
net/netfilter/nf_conntrack_netlink.c | 102 +++++++++++++--------------------- 1 files changed, 40 insertions(+), 62 deletions(-)
net/netfilter/nf_conntrack_netlink.c +40 -62
@@ -403,76 +403,55 @@ nla_put_failure: } #ifdef CONFIG_NF_CONNTRACK_EVENTS -/* - * The general structure of a ctnetlink event is - * - * CTA_TUPLE_ORIG - * <l3/l4-proto-attributes> - * CTA_TUPLE_REPLY - * <l3/l4-proto-attributes> - * CTA_ID - * ... - * CTA_PROTOINFO - * <l4-proto-attributes> - * CTA_TUPLE_MASTER - * <l3/l4-proto-attributes> - * - * Therefore the formular is - * - * size = sizeof(headers) + sizeof(generic_nlas) + 3 * sizeof(tuple_nlas) - * + sizeof(protoinfo_nlas) - */ -static struct sk_buff * -ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp) +static inline size_t +ctnetlink_proto_size(const struct nf_conn *ct) { struct nf_conntrack_l3proto *l3proto; struct nf_conntrack_l4proto *l4proto; - int len; - -#define NLA_TYPE_SIZE(type) nla_total_size(sizeof(type)) - - /* proto independant part */ - len = NLMSG_ALIGN(sizeof(struct nfgenmsg)) - + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */ - + 3 * nla_total_size(0) /* CTA_TUPLE_IP */ - + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */ - + 3 * NLA_TYPE_SIZE(u_int8_t) /* CTA_PROTO_NUM */ - + NLA_TYPE_SIZE(u_int32_t) /* CTA_ID */ - + NLA_TYPE_SIZE(u_int32_t) /* CTA_STATUS */ + size_t len = 0; + + rcu_read_lock(); + l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct)); + len += l3proto->nla_size; + + l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct)); + len += l4proto->nla_size; + rcu_read_unlock(); + + return len; +} + +static inline size_t +ctnetlink_nlmsg_size(const struct nf_conn *ct) +{ + return NLMSG_ALIGN(sizeof(struct nfgenmsg)) + + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */ + + 3 * nla_total_size(0) /* CTA_TUPLE_IP */ + + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */ + + 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */ + + nla_total_size(sizeof(u_int32_t)) /* CTA_ID */ + + nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */ #ifdef CONFIG_NF_CT_ACCT - + 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */ - + 2 * NLA_TYPE_SIZE(uint64_t) /* CTA_COUNTERS_PACKETS */ - + 2 * NLA_TYPE_SIZE(uint64_t) /* CTA_COUNTERS_BYTES */ + + 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */ + + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_PACKETS */ + + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_BYTES */ #endif - + NLA_TYPE_SIZE(u_int32_t) /* CTA_TIMEOUT */ - + nla_total_size(0) /* CTA_PROTOINFO */ - + nla_total_size(0) /* CTA_HELP */ - + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */ + + nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */ + + nla_total_size(0) /* CTA_PROTOINFO */ + + nla_total_size(0) /* CTA_HELP */ + + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */ #ifdef CONFIG_NF_CONNTRACK_SECMARK - + NLA_TYPE_SIZE(u_int32_t) /* CTA_SECMARK */ + + nla_total_size(sizeof(u_int32_t)) /* CTA_SECMARK */ #endif #ifdef CONFIG_NF_NAT_NEEDED - + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */ - + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_POS */ - + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_BEFORE */ - + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_AFTER */ + + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */ + + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */ #endif #ifdef CONFIG_NF_CONNTRACK_MARK - + NLA_TYPE_SIZE(u_int32_t) /* CTA_MARK */ + + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */ #endif - ; - -#undef NLA_TYPE_SIZE - - rcu_read_lock(); - l3proto = __nf_ct_l3proto_find(tuple->src.l3num); - len += l3proto->nla_size; - - l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum); - len += l4proto->nla_size; - rcu_read_unlock(); - - return nlmsg_new(len, gfp); + + ctnetlink_proto_size(ct) + ; } static int ctnetlink_conntrack_event(struct notifier_block *this,
@@ -507,9 +486,8 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,if (!item->report && !nfnetlink_has_listeners (group))return NOTIFY_DONE ; - skb =ctnetlink_alloc_skb (nf_ct_tuple (ct,IP_CT_DIR_ORIGINAL ), -GFP_ATOMIC ); -if (!skb) + skb =nlmsg_new (ctnetlink_nlmsg_size (ct),GFP_ATOMIC ); +if (skb ==NULL ) goto errout; type |=NFNL_SUBSYS_CTNETLINK <<8 ;
Pablo Neira Ayuso
maintainerPATCH 6/9 netfilter: conntrack: don't report events on module removal
In reply to Pablo Neira AyusoDuring the module removal there are no possible event listeners since ctnetlink must be removed before to allow removing nf_conntrack. This patch removes the event reporting for the module removal case which is not of any use in the existing code.
---
include/net/netfilter/nf_conntrack.h | 2 +- net/netfilter/nf_conntrack_core.c | 15 ++++++++++----- net/netfilter/nf_conntrack_netlink.c | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-)
include/net/netfilter/nf_conntrack.h +1 -1
@@ -203,7 +203,7 @@ __nf_conntrack_find(struct net *net, const struct nf_conntrack_tuple *tuple);extern void nf_conntrack_hash_insert (struct nf_conn *ct); -extern void nf_conntrack_flush (struct net *net,u32 pid,int report); +extern void nf_conntrack_flush_report (struct net *net,u32 pid,int report); extern bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff, u_int16_t l3num,
net/netfilter/nf_conntrack_core.c +10 -5
@@ -1001,7 +1001,7 @@ struct __nf_ct_flush_report {int report; }; -static int kill_all (struct nf_conn *i,void *data) +static int kill_report (struct nf_conn *i,void *data) {struct __nf_ct_flush_report *fr = (struct __nf_ct_flush_report *)data;
@@ -1013,6 +1013,11 @@ static int kill_all(struct nf_conn *i, void *data)return 1 ; } +static int kill_all (struct nf_conn *i,void *data) +{ +return 1 ; +} +void nf_ct_free_hashtable (void *hash,int vmalloced,unsigned int size) {if (vmalloced)
@@ -1023,15 +1028,15 @@ void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size) }EXPORT_SYMBOL_GPL (nf_ct_free_hashtable); -void nf_conntrack_flush (struct net *net,u32 pid,int report) +void nf_conntrack_flush_report (struct net *net,u32 pid,int report) {struct __nf_ct_flush_report fr = { .pid = pid, .report = report, }; -nf_ct_iterate_cleanup (net, kill_all, &fr); +nf_ct_iterate_cleanup (net, kill_report, &fr); } -EXPORT_SYMBOL_GPL (nf_conntrack_flush); +EXPORT_SYMBOL_GPL (nf_conntrack_flush_report);static void nf_conntrack_cleanup_init_net (void ) {
@@ -1045,7 +1050,7 @@ static void nf_conntrack_cleanup_net(struct net *net)nf_ct_event_cache_flush (net);nf_conntrack_ecache_fini (net); i_see_dead_people: -nf_conntrack_flush (net,0 ,0 ); +nf_ct_iterate_cleanup (net, kill_all,NULL );if (atomic_read (&net->ct.count) !=0 ) {schedule (); goto i_see_dead_people;
net/netfilter/nf_conntrack_netlink.c +3 -3
@@ -777,9 +777,9 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, err =ctnetlink_parse_tuple (cda, &tuple,CTA_TUPLE_REPLY , u3); else {/* Flush the whole table */ -nf_conntrack_flush (&init_net, -NETLINK_CB (skb).pid, -nlmsg_report (nlh)); +nf_conntrack_flush_report (&init_net, +NETLINK_CB (skb).pid, +nlmsg_report (nlh));return 0 ; }
Pablo Neira Ayuso
maintainerPATCH 7/9 netfilter: conntrack: remove events flags from userspace exposed file
In reply to Pablo Neira AyusoThis patch moves the event flags from linux/netfilter/nf_conntrack_common.h to net/netfilter/nf_conntrack_ecache.h. This flags are not of any use from userspace.
---
include/linux/netfilter/nf_conntrack_common.h | 69 ------------------------- include/net/netfilter/nf_conntrack_ecache.h | 69 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 69 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +0 -69
@@ -75,75 +75,6 @@ enum ip_conntrack_status { IPS_FIXED_TIMEOUT = (1 << IPS_FIXED_TIMEOUT_BIT), }; -/* Connection tracking event bits */ -enum ip_conntrack_events -{ -/* New conntrack */ -IPCT_NEW_BIT =0 , -IPCT_NEW = (1 <<IPCT_NEW_BIT ), - -/* Expected connection */ -IPCT_RELATED_BIT =1 , -IPCT_RELATED = (1 <<IPCT_RELATED_BIT ), - -/* Destroyed conntrack */ -IPCT_DESTROY_BIT =2 , -IPCT_DESTROY = (1 <<IPCT_DESTROY_BIT ), - -/* Timer has been refreshed */ -IPCT_REFRESH_BIT =3 , -IPCT_REFRESH = (1 <<IPCT_REFRESH_BIT ), - -/* Status has changed */ -IPCT_STATUS_BIT =4 , -IPCT_STATUS = (1 <<IPCT_STATUS_BIT ), - -/* Update of protocol info */ -IPCT_PROTOINFO_BIT =5 , -IPCT_PROTOINFO = (1 <<IPCT_PROTOINFO_BIT ), - -/* Volatile protocol info */ -IPCT_PROTOINFO_VOLATILE_BIT =6 , -IPCT_PROTOINFO_VOLATILE = (1 <<IPCT_PROTOINFO_VOLATILE_BIT ), - -/* New helper for conntrack */ -IPCT_HELPER_BIT =7 , -IPCT_HELPER = (1 <<IPCT_HELPER_BIT ), - -/* Update of helper info */ -IPCT_HELPINFO_BIT =8 , -IPCT_HELPINFO = (1 <<IPCT_HELPINFO_BIT ), - -/* Volatile helper info */ -IPCT_HELPINFO_VOLATILE_BIT =9 , -IPCT_HELPINFO_VOLATILE = (1 <<IPCT_HELPINFO_VOLATILE_BIT ), - -/* NAT info */ -IPCT_NATINFO_BIT =10 , -IPCT_NATINFO = (1 <<IPCT_NATINFO_BIT ), - -/* Counter highest bit has been set, unused */ -IPCT_COUNTER_FILLING_BIT =11 , -IPCT_COUNTER_FILLING = (1 <<IPCT_COUNTER_FILLING_BIT ), - -/* Mark is set */ -IPCT_MARK_BIT =12 , -IPCT_MARK = (1 <<IPCT_MARK_BIT ), - -/* NAT sequence adjustment */ -IPCT_NATSEQADJ_BIT =13 , -IPCT_NATSEQADJ = (1 <<IPCT_NATSEQADJ_BIT ), - -/* Secmark is set */ -IPCT_SECMARK_BIT =14 , -IPCT_SECMARK = (1 <<IPCT_SECMARK_BIT ), -}; - -enum ip_conntrack_expect_events { -IPEXP_NEW_BIT =0 , -IPEXP_NEW = (1 <<IPEXP_NEW_BIT ), -}; -#ifdef __KERNEL__struct ip_conntrack_stat {
include/net/netfilter/nf_conntrack_ecache.h +69 -0
75 lines not on this page · raw message
Pablo Neira Ayuso
maintainerPATCH 8/9 netfilter: conntrack: simplify event caching system
In reply to Pablo Neira AyusoThis patch simplifies the conntrack event caching system by removing several events:
* IPCT_[*]_VOLATILE, IPCT_HELPINFO and IPCT_NATINFO has been deleted since the have no clients.
* IPCT_COUNTER_FILLING which is a leftover of the 32-bits counter days.
* IPCT_REFRESH which is not of any use since we always include the timeout in the messages.
After this patch, the existing events are:
* IPCT_NEW, IPCT_RELATED and IPCT_DESTROY, that are used to identify addition and deletion of entries.
* IPCT_STATUS, that notes that the status bits have changes, eg. IPS_SEEN_REPLY and IPS_ASSURED.
* IPCT_PROTOINFO, that reports that internal protocol information has changed, eg. the TCP, DCCP and SCTP protocol state.
* IPCT_HELPER, that a helper has been assigned or unassigned to this entry.
* IPCT_MARK and IPCT_SECMARK, that reports that the mark has changed, this covers the case when a mark is set to zero.
* IPCT_NATSEQADJ, to report that there's updates in the NAT sequence adjustment.
---
include/net/netfilter/nf_conntrack_ecache.h | 36 ++++-------------------- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 1 - net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 1 - net/netfilter/nf_conntrack_core.c | 14 +-------- net/netfilter/nf_conntrack_ftp.c | 2 - net/netfilter/nf_conntrack_netlink.c | 2 + net/netfilter/nf_conntrack_proto_tcp.c | 1 - 7 files changed, 8 insertions(+), 49 deletions(-)
include/net/netfilter/nf_conntrack_ecache.h +6 -30
@@ -26,52 +26,28 @@ enum ip_conntrack_eventsIPCT_DESTROY_BIT =2 ,IPCT_DESTROY = (1 <<IPCT_DESTROY_BIT ), -/* Timer has been refreshed */ -IPCT_REFRESH_BIT =3 , -IPCT_REFRESH = (1 <<IPCT_REFRESH_BIT ), -/* Status has changed */ -IPCT_STATUS_BIT =4 , +IPCT_STATUS_BIT =3 ,IPCT_STATUS = (1 <<IPCT_STATUS_BIT ),/* Update of protocol info */ -IPCT_PROTOINFO_BIT =5 , +IPCT_PROTOINFO_BIT =4 ,IPCT_PROTOINFO = (1 <<IPCT_PROTOINFO_BIT ), -/* Volatile protocol info */ -IPCT_PROTOINFO_VOLATILE_BIT =6 , -IPCT_PROTOINFO_VOLATILE = (1 <<IPCT_PROTOINFO_VOLATILE_BIT ), -/* New helper for conntrack */ -IPCT_HELPER_BIT =7 , +IPCT_HELPER_BIT =5 ,IPCT_HELPER = (1 <<IPCT_HELPER_BIT ), -/* Update of helper info */ -IPCT_HELPINFO_BIT =8 , -IPCT_HELPINFO = (1 <<IPCT_HELPINFO_BIT ), - -/* Volatile helper info */ -IPCT_HELPINFO_VOLATILE_BIT =9 , -IPCT_HELPINFO_VOLATILE = (1 <<IPCT_HELPINFO_VOLATILE_BIT ), - -/* NAT info */ -IPCT_NATINFO_BIT =10 , -IPCT_NATINFO = (1 <<IPCT_NATINFO_BIT ), - -/* Counter highest bit has been set, unused */ -IPCT_COUNTER_FILLING_BIT =11 , -IPCT_COUNTER_FILLING = (1 <<IPCT_COUNTER_FILLING_BIT ), -/* Mark is set */ -IPCT_MARK_BIT =12 , +IPCT_MARK_BIT =6 ,IPCT_MARK = (1 <<IPCT_MARK_BIT ),/* NAT sequence adjustment */ -IPCT_NATSEQADJ_BIT =13 , +IPCT_NATSEQADJ_BIT =7 ,IPCT_NATSEQADJ = (1 <<IPCT_NATSEQADJ_BIT ),/* Secmark is set */ -IPCT_SECMARK_BIT =14 , +IPCT_SECMARK_BIT =8 , IPCT_SECMARK = (1 << IPCT_SECMARK_BIT), };
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +0 -1
@@ -91,7 +91,6 @@ static int icmp_packet(struct nf_conn *ct,nf_ct_kill_acct (ct, ctinfo, skb); }else {atomic_inc (&ct->proto.icmp.count); -nf_conntrack_event_cache (IPCT_PROTOINFO_VOLATILE , ct);nf_ct_refresh_acct (ct, ctinfo, skb, nf_ct_icmp_timeout); }
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -1
@@ -104,7 +104,6 @@ static int icmpv6_packet(struct nf_conn *ct,nf_ct_kill_acct (ct, ctinfo, skb); }else {atomic_inc (&ct->proto.icmp.count); -nf_conntrack_event_cache (IPCT_PROTOINFO_VOLATILE , ct);nf_ct_refresh_acct (ct, ctinfo, skb, nf_ct_icmpv6_timeout); }
net/netfilter/nf_conntrack_core.c +1 -13
@@ -398,11 +398,7 @@ __nf_conntrack_confirm(struct sk_buff *skb) help =nfct_help (ct);if (help && help->helper)nf_conntrack_event_cache (IPCT_HELPER , ct); -#ifdef CONFIG_NF_NAT_NEEDED -if (test_bit (IPS_SRC_NAT_DONE_BIT , &ct->status) || -test_bit (IPS_DST_NAT_DONE_BIT , &ct->status)) -nf_conntrack_event_cache (IPCT_NATINFO , ct); -#endif +nf_conntrack_event_cache (master_ct (ct) ?IPCT_RELATED :IPCT_NEW , ct);return NF_ACCEPT ;
@@ -807,8 +803,6 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,unsigned long extra_jiffies, int do_acct) { - int event = 0; - NF_CT_ASSERT(ct->timeout.data == (unsigned long)ct);NF_CT_ASSERT (skb);
@@ -821,7 +815,6 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,/* If not in hash table, timer will not be active yet */ if (!nf_ct_is_confirmed (ct)) { ct->timeout.expires = extra_jiffies; - event =IPCT_REFRESH ; }else {unsigned long newtime = jiffies + extra_jiffies;
@@ -832,7 +825,6 @@ void __nf_ct_refresh_acct(struct nf_conn *ct, && del_timer(&ct->timeout)) { ct->timeout.expires = newtime;add_timer (&ct->timeout); - event =IPCT_REFRESH ; } }
@@ -849,10 +841,6 @@ acct: }spin_unlock_bh (&nf_conntrack_lock); - -/* must be unlocked when calling event cache */ -if (event) -nf_conntrack_event_cache (event, ct); }EXPORT_SYMBOL_GPL (__nf_ct_refresh_acct);
net/netfilter/nf_conntrack_ftp.c +0 -2
@@ -338,11 +338,9 @@ static void update_nl_seq(struct nf_conn *ct, u32 nl_seq,if (info->seq_aft_nl_num[dir] <NUM_SEQ_TO_REMEMBER ) { info->seq_aft_nl[dir][info->seq_aft_nl_num[dir]++] = nl_seq; -nf_conntrack_event_cache (IPCT_HELPINFO_VOLATILE , ct); }else if (oldest !=NUM_SEQ_TO_REMEMBER &&after (nl_seq, info->seq_aft_nl[dir][oldest])) { info->seq_aft_nl[dir][oldest] = nl_seq; -nf_conntrack_event_cache (IPCT_HELPINFO_VOLATILE , ct); } }
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -477,7 +477,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, type =IPCTNL_MSG_CT_NEW ; flags =NLM_F_CREATE |NLM_F_EXCL ; group =NFNLGRP_CONNTRACK_NEW ; - }else if (events & (IPCT_STATUS |IPCT_PROTOINFO )) { + }else if (events) { type =IPCTNL_MSG_CT_NEW ; group =NFNLGRP_CONNTRACK_UPDATE ; }else
net/netfilter/nf_conntrack_proto_tcp.c +0 -1
@@ -974,7 +974,6 @@ static int tcp_packet(struct nf_conn *ct, timeout = tcp_timeouts[new_state];write_unlock_bh (&tcp_lock); -nf_conntrack_event_cache (IPCT_PROTOINFO_VOLATILE , ct);if (new_state != old_state)nf_conntrack_event_cache (IPCT_PROTOINFO , ct);
Pablo Neira Ayuso
maintainerPATCH 9/9 netfilter: conntrack: replace notify chain by function pointer
In reply to Pablo Neira AyusoThis patch removes the notify chain infrastructure and replace it by a simple function pointer. This issue has been mentioned in the mailing list several times: the use of the notify chain adds too much overhead for something that is only used by ctnetlink.
This patch also changes nfnetlink_send(). It seems that gfp_any() returns GFP_KERNEL for user-context request, like those via ctnetlink, inside the RCU read-side section which is not valid. Using GFP_KERNEL is also evil since netlink may schedule(), this leads to "scheduling while atomic" bug reports.
---
include/linux/netfilter/nfnetlink.h | 2 - include/net/netfilter/nf_conntrack_ecache.h | 68 +++++++++++++----- net/netfilter/nf_conntrack_ecache.c | 101 +++++++++++++++++++++++---- net/netfilter/nf_conntrack_netlink.c | 42 +++++------ net/netfilter/nfnetlink.c | 5 + 5 files changed, 157 insertions(+), 61 deletions(-)
include/linux/netfilter/nfnetlink.h +1 -1
@@ -75,7 +75,7 @@ extern int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);extern int nfnetlink_has_listeners (unsigned int group);extern int nfnetlink_send (struct sk_buff *skb,u32 pid,unsigned group, -int echo); +int echo,gfp_t flags);extern void nfnetlink_set_err (u32 pid,u32 group,int error);extern int nfnetlink_unicast (struct sk_buff *skb,u_int32_t pid,int flags);
include/net/netfilter/nf_conntrack_ecache.h +48 -20
98 lines not on this page · raw message
net/netfilter/nf_conntrack_ecache.c +85 -16
149 lines not on this page · raw message
net/netfilter/nf_conntrack_netlink.c +20 -22
122 lines not on this page · raw message
net/netfilter/nfnetlink.c +3 -2
@@ -107,9 +107,10 @@ int nfnetlink_has_listeners(unsigned int group) }EXPORT_SYMBOL_GPL (nfnetlink_has_listeners); -int nfnetlink_send (struct sk_buff *skb,u32 pid,unsigned group,int echo) +int nfnetlink_send (struct sk_buff *skb,u32 pid, +unsigned group,int echo,gfp_t flags) { -return nlmsg_notify (nfnl, skb, pid, group, echo,gfp_any ()); +return nlmsg_notify (nfnl, skb, pid, group, echo, flags); }EXPORT_SYMBOL_GPL (nfnetlink_send);
Re: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
net/netfilter/nf_conntrack_ecache.c void nf_conntrack_ecache_fini(struct net *net) · line 196
Quoted 13 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_ecache.c +10
-2-int nf_ct_expect_unregister_notifier (struct notifier_block *nb) +int nf_ct_expect_unregister_notifier (struct nf_exp_event_notifier *new) { -return atomic_notifier_chain_unregister (&nf_ct_expect_chain, nb); +int ret =0 ; +struct nf_exp_event_notifier *notify; + +mutex_lock (&nf_ct_ecache_mutex); + notify =rcu_dereference (nf_expect_event_cb); +if (notify != new) { + ret = -EINVAL ; + goto out_unlock; + }
I think these unregistration functions should return void. The only reason why they don't currently is because the notifier_chain_unregister function for some unknown reasons don't return void, but there's
a) nothing the caller could possibly do to handle this and b) a bug anyways. So I'd suggest to just unconditionally assign NULL.
Sorry for not bringing this up earlier.
BTW, you might also consider marking the callback pointers read_mostly.
Quoted 9 lines
net/netfilter/nf_conntrack_ecache.c +7
-0+rcu_assign_pointer (nf_expect_event_cb,NULL ); +mutex_unlock (&nf_ct_ecache_mutex); +return ret; + +out_unlock: +mutex_unlock (&nf_ct_ecache_mutex); +return ret; }EXPORT_SYMBOL_GPL (nf_ct_expect_unregister_notifier);
Pablo Neira Ayuso
maintainerRe: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
Quoted 12 lines · Patrick McHardy
Quoted 11 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_ecache.c +8
-2-int nf_ct_expect_unregister_notifier (struct notifier_block *nb) +int nf_ct_expect_unregister_notifier (struct nf_exp_event_notifier *new) { -return atomic_notifier_chain_unregister (&nf_ct_expect_chain, nb); +int ret =0 ; +struct nf_exp_event_notifier *notify; + +mutex_lock (&nf_ct_ecache_mutex); + notify =rcu_dereference (nf_expect_event_cb); +if (notify != new) { + ret = -EINVAL ;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ goto out_unlock; + }I think these unregistration functions should return void. The only reason why they don't currently is because the
notifier_chain_unregisterfunction for some unknown reasons don't return void, but there's
a) nothing the caller could possibly do to handle this and b) a bug anyways. So I'd suggest to just unconditionally assign NULL.
Would you be OK with something like:
BUG_ON(notify != new);
So we can catch this very unlikely bug, if so.
Quoted 3 lines
Sorry for not bringing this up earlier.
BTW, you might also consider marking the callback pointers
read_mostly.
Done.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
Re: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
Quoted 21 lines · Pablo Neira Ayuso
Quoted 11 lines · Patrick McHardy
Quoted 10 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_ecache.c +7
-2-int nf_ct_expect_unregister_notifier (struct notifier_block *nb) +int nf_ct_expect_unregister_notifier (struct nf_exp_event_notifier *new) { -return atomic_notifier_chain_unregister (&nf_ct_expect_chain, nb); +int ret =0 ; +struct nf_exp_event_notifier *notify; + +mutex_lock (&nf_ct_ecache_mutex); + notify =rcu_dereference (nf_expect_event_cb); +if (notify != new) {Quoted 8 lines
net/netfilter/nf_conntrack_ecache.c void nf_conntrack_ecache_fini(struct net *net) · line 154
Quoted 3 lines
net/netfilter/nf_conntrack_ecache.c +3
-0+ ret = -EINVAL ; + goto out_unlock; + }I think these unregistration functions should return void. The only reason why they don't currently is because the
notifier_chain_unregisterfunction for some unknown reasons don't return void, but there's
a) nothing the caller could possibly do to handle this and b) a bug anyways. So I'd suggest to just unconditionally assign NULL.
Quoted 5 lines
Would you be OK with something like:
BUG_ON(notify != new);So we can catch this very unlikely bug, if so.
Sure. We don't do this is 99% of the other unregistration functions however, so I don't think its particulary useful. It only affects out of tree code anyways, unless we've done something really stupid, like remove error checking in the initialization function :)
Pablo Neira Ayuso
maintainerRe: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
Quoted 10 lines · Patrick McHardy
Quoted 5 lines
Would you be OK with something like:
BUG_ON(notify != new);So we can catch this very unlikely bug, if so.
Sure. We don't do this is 99% of the other unregistration functions however, so I don't think its particulary useful. It only affects out of tree code anyways, unless we've done something really stupid, like remove error checking in the initialization function :)
I see. Well, I don't have very strong arguments to support this, some of
them: if I remove it the unregistration function will not use the parameter anymore and I'd like to keep the register/unregister interface symmetric. Very unlikely but it can spot other problems like memory corruptions? Although in that case, the kernel is more likely to crash.
Please, keep it there :). I'm going to send you a new version of this patch to the mailing list.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
Re: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
Quoted 11 lines · Pablo Neira Ayuso
Quoted 9 lines · Patrick McHardy
Quoted 5 lines
Would you be OK with something like:
BUG_ON(notify != new);So we can catch this very unlikely bug, if so.
Sure. We don't do this is 99% of the other unregistration functions however, so I don't think its particulary useful. It only affects out of tree code anyways, unless we've done something really stupid, like remove error checking in the initialization function :)
Quoted 8 lines
I see. Well, I don't have very strong arguments to support this, some of
them: if I remove it the unregistration function will not use the parameter anymore and I'd like to keep the register/unregister interface symmetric. Very unlikely but it can spot other problems like memory corruptions? Although in that case, the kernel is more likely to crash.Please, keep it there :). I'm going to send you a new version of this patch to the mailing list.
Sure, no objections. Please also update your git tree or change the HEAD to exclude that final patch so I can pull the remaining ones.
Pablo Neira Ayuso
maintainerRe: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
In reply to Pablo Neira AyusoQuoted 2 lines · Pablo Neira Ayuso
Please, keep it there :). I'm going to send you a new version of this patch to the mailing list.
New 9/9 patch attached.
As said, you can pull all the changes from:
git://1984.lsi.us.es/nf-next-2.6 master
people.netfilter.org is still broken, so I had to deploy the git infrastructure here in one of my servers.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
netfilter: conntrack: replace notify chain by function pointer
This patch removes the notify chain infrastructure and replace it by a simple function pointer. This issue has been mentioned in the mailing list several times: the use of the notify chain adds too much overhead for something that is only used by ctnetlink.
This patch also changes nfnetlink_send(). It seems that gfp_any() returns GFP_KERNEL for user-context request, like those via ctnetlink, inside the RCU read-side section which is not valid. Using GFP_KERNEL is also evil since netlink may schedule(), this leads to "scheduling while atomic" bug reports.
---
include/linux/netfilter/nfnetlink.h | 2 - include/net/netfilter/nf_conntrack_ecache.h | 68 ++++++++++++++++------ net/netfilter/nf_conntrack_ecache.c | 83 ++++++++++++++++++++++----- net/netfilter/nf_conntrack_netlink.c | 42 +++++++------- net/netfilter/nfnetlink.c | 5 +- 5 files changed, 139 insertions(+), 61 deletions(-)
include/linux/netfilter/nfnetlink.h +1 -1
@@ -75,7 +75,7 @@ extern int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);extern int nfnetlink_has_listeners (unsigned int group);extern int nfnetlink_send (struct sk_buff *skb,u32 pid,unsigned group, -int echo); +int echo,gfp_t flags);extern void nfnetlink_set_err (u32 pid,u32 group,int error);extern int nfnetlink_unicast (struct sk_buff *skb,u_int32_t pid,int flags);
include/net/netfilter/nf_conntrack_ecache.h +48 -20
98 lines not on this page · raw message
net/netfilter/nf_conntrack_ecache.c +67 -16
131 lines not on this page · raw message
net/netfilter/nf_conntrack_netlink.c +20 -22
122 lines not on this page · raw message
net/netfilter/nfnetlink.c +3 -2
@@ -107,9 +107,10 @@ int nfnetlink_has_listeners(unsigned int group) }EXPORT_SYMBOL_GPL (nfnetlink_has_listeners); -int nfnetlink_send (struct sk_buff *skb,u32 pid,unsigned group,int echo) +int nfnetlink_send (struct sk_buff *skb,u32 pid, +unsigned group,int echo,gfp_t flags) { -return nlmsg_notify (nfnl, skb, pid, group, echo,gfp_any ()); +return nlmsg_notify (nfnl, skb, pid, group, echo, flags); }EXPORT_SYMBOL_GPL (nfnetlink_send);
Re: [PATCH 9/9] netfilter: conntrack: replace notify chain by function pointer
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Pablo Neira Ayuso
Please, keep it there :). I'm going to send you a new version of this patch to the mailing list.
New 9/9 patch attached.
As said, you can pull all the changes from:
git://1984.lsi.us.es/nf-next-2.6master
Pulled and pushed out again, thanks Pablo.