Netfilter updates for nf-next tree (2.6.31)
Subsystems (2)
Pablo Neira Ayuso
maintainercover Netfilter updates for nf-next tree (2.6.31)
Hi Patrick,
Here it follows the first bunch of updates for your nf-next tree. This patchset is mostly oriented to cleanups and the conntrack event subsystem.
Wait for your comments! Thanks!
---
Pablo Neira Ayuso (7):
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 building and size calculation
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 | 8 + 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 | 262 +++++++++++------------- net/netfilter/nf_conntrack_proto_tcp.c | 1 net/netfilter/nfnetlink.c | 28 +-- 12 files changed, 326 insertions(+), 291 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: ctnetlink: remove nowait parameter from *fill_info()
This 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/7 netfilter: ctnetlink: cleanup message building and size calculation
In reply to Pablo Neira AyusoThis patch is a cleanup. It removes unneeded verbose information about the size calculation and it also replaces the old macros to build Netlink messages with the new nlmsg_*() helper functions.
---
include/net/netfilter/nf_conntrack.h | 6 + net/netfilter/nf_conntrack_netlink.c | 192 +++++++++++++++------------------- 2 files changed, 91 insertions(+), 107 deletions(-)
include/net/netfilter/nf_conntrack.h +6 -0
@@ -144,6 +144,12 @@ static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)return ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum; } +static inline const struct nf_conntrack_tuple * +nf_ct_tuple (const struct nf_conn *ct,enum ip_conntrack_dir dir) +{ +return &ct->tuplehash[dir].tuple; +} +/* get master conntrack via master expectation */ #define master_ct (conntr) (conntr->master)
net/netfilter/nf_conntrack_netlink.c +85 -107
395 lines not on this page · raw message
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: nfnetlink: cleanup for nfnetlink_rcv_msg() function
In reply to Pablo Neira AyusoThis 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 4/7 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
@@ -207,7 +207,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
@@ -778,9 +778,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 5/7 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 6/7 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
@@ -478,7 +478,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 7/7 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);
Quoted 7 lines · Pablo Neira Ayuso
Hi Patrick,
Here it follows the first bunch of updates for your nf-next tree. This patchset is mostly oriented to cleanups and the conntrack event subsystem.
Wait for your comments! Thanks!
I'll review them now. One question though - since you appear to be using git, could you make your tree (well, the parts you want to merge) accessible somewhere? Doing a git pull saves a lot of time compared to applying each patch individually ...
Re: [PATCH 3/7] netfilter: ctnetlink: cleanup message building and size calculation
In reply to Pablo Neira AyusoQuoted 3 lines · Pablo Neira Ayuso
This patch is a cleanup. It removes unneeded verbose information about the size calculation and it also replaces the old macros to build Netlink messages with the new nlmsg_*() helper functions.
This one is really hard to review because of the mixed renames and code movals. Please split this into two patches.
include/net/netfilter/nf_conntrack.h static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct) · line 151
Quoted 13 lines
include/net/netfilter/nf_conntrack.h +5
-0@@ -144,6 +144,12 @@ static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)return ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum; } +static inline const struct nf_conntrack_tuple * +nf_ct_tuple (const struct nf_conn *ct,enum ip_conntrack_dir dir) +{ +return &ct->tuplehash[dir].tuple; +}
This is a useful helper for other situations as well, so I think it shouldn't be const.
include/net/netfilter/nf_conntrack.h static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)
Quoted 7 lines
include/net/netfilter/nf_conntrack.h +6
-1+static inline size_t +ctnetlink_nlmsg_size (const struct nf_conn *ct) +{ + ... -return alloc_skb (len, gfp); + +ctnetlink_proto_size (ct); + ;
^^ stray semicolon
Pablo Neira Ayuso
maintainerQuoted 7 lines · Patrick McHardy
Quoted 6 lines · Pablo Neira Ayuso
Hi Patrick,
Here it follows the first bunch of updates for your nf-next tree. This patchset is mostly oriented to cleanups and the conntrack event subsystem.
Quoted 6 lines
Quoted 1 line
Wait for your comments! Thanks!
I'll review them now. One question though - since you appear to be using git, could you make your tree (well, the parts you want to merge) accessible somewhere? Doing a git pull saves a lot of time compared to applying each patch individually ...
OK, I'm setting up a git tree now so you can pull from it.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
Pablo Neira Ayuso
maintainerRe: [PATCH 3/7] netfilter: ctnetlink: cleanup message building and size calculation
In reply to Patrick McHardyQuoted 7 lines · Patrick McHardy
Quoted 3 lines · Pablo Neira Ayuso
This patch is a cleanup. It removes unneeded verbose information about the size calculation and it also replaces the old macros to build Netlink messages with the new nlmsg_*() helper functions.
This one is really hard to review because of the mixed renames and code movals. Please split this into two patches.
OK, I'm splitting them now.
Quoted 10 lines
Quoted 10 lines
include/net/netfilter/nf_conntrack.h +0
-0@@ -144,6 +144,12 @@ static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)return ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum; }
Quoted 8 lines
include/net/netfilter/nf_conntrack.h static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct) · line 151
Quoted 5 lines
include/net/netfilter/nf_conntrack.h +5
-0+static inline const struct nf_conntrack_tuple * +nf_ct_tuple (const struct nf_conn *ct,enum ip_conntrack_dir dir) +{ +return &ct->tuplehash[dir].tuple; +}This is a useful helper for other situations as well, so I think it shouldn't be const.
I get:
net/netfilter/nf_conntrack_netlink.c:370: warning: passing argument 1 of 'nf_ct_tuple' discards qualifiers from pointer target type net/netfilter/nf_conntrack_netlink.c:377: warning: passing argument 1 of 'nf_ct_tuple' discards qualifiers from pointer target type
So I have to remove the 'const' from the last parameter of ctnetlink_fill_info().
Or do some ugly casting in the nf_ct_tuple() calls to avoid the warning, in that case I would prefer to leave that macro there.
Please, let me know what you prefer.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
Re: [PATCH 3/7] netfilter: ctnetlink: cleanup message building and size calculation
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Patrick McHardy
This one is really hard to review because of the mixed renames and code movals. Please split this into two patches.
OK, I'm splitting them now.
Thanks.
Quoted 15 lines
Quoted 7 lines
include/net/netfilter/nf_conntrack.h static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct) · line 151
Quoted 5 lines
include/net/netfilter/nf_conntrack.h +5
-0+static inline const struct nf_conntrack_tuple * +nf_ct_tuple (const struct nf_conn *ct,enum ip_conntrack_dir dir) +{ +return &ct->tuplehash[dir].tuple; +}This is a useful helper for other situations as well, so I think it shouldn't be const.
I get:
net/netfilter/nf_conntrack_netlink.c:370: warning: passing argument 1 of 'nf_ct_tuple' discards qualifiers from pointer target typenet/netfilter/nf_conntrack_netlink.c:377: warning: passing argument 1 of 'nf_ct_tuple' discards qualifiers from pointer target type
Quoted 7 lines
So I have to remove the 'const' from the last parameter of
ctnetlink_fill_info().Or do some ugly casting in the
nf_ct_tuple()calls to avoid the warning, in that case I would prefer to leave that macro there.Please, let me know what you prefer.
The best way is probably to keep using a macro since there's no other way to handle this properly. But I'm all in favour of renaming that macro and making it globally available as you did.