netfilter: skbuff: merge nfctinfo bits and nfct pointer
Subsystems (6)
Florian Westphal
maintainerv3 cover netfilter: skbuff: merge nfctinfo bits and nfct pointer
Whenever we fetch skb conntrack info, we need to access two distinct cache lines in sk_buff, #2 (nfct pointer) and #3 (nfctinfo bits). This series removes nfctinfo and joins it with the data pointer in a single ulong.
We have 3 nfctinfo bits, the slab cache used for nf_conn objects guarantees at least 8 byte alignment so there is no overlap.
For the conntrack templates most arches also guarantee an 8 byte minalign, but not all.
Patch #6 adds manual alignment of the templates if ARCH_KMALLOC_MINALIGN isn't sufficient.
A followup series to this one will resurrect an old patch from Pablo that adds an 'untracked' ctinfo status, this then allows to get rid of the conntrack template object (which in turn avoids get/put atomic ops for untracked skbs).
include/linux/skbuff.h | 32 ++++++----- include/net/ip_vs.h | 10 ++- include/net/netfilter/nf_conntrack.h | 17 +++++- include/net/netfilter/nf_conntrack_core.h | 2 include/net/netfilter/nf_conntrack_l4proto.h | 2 net/core/skbuff.c | 2 net/ipv4/netfilter/ipt_SYNPROXY.c | 11 +-- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 15 ++--- net/ipv4/netfilter/nf_defrag_ipv4.c | 4 - net/ipv4/netfilter/nf_dup_ipv4.c | 7 +- net/ipv6/netfilter/ip6t_SYNPROXY.c | 11 +-- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 20 +++---- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 4 - net/ipv6/netfilter/nf_dup_ipv6.c | 7 +- net/netfilter/core.c | 2 net/netfilter/nf_conntrack_core.c | 70 ++++++++++++++++--------- net/netfilter/nf_conntrack_proto_dccp.c | 1 net/netfilter/nf_conntrack_proto_sctp.c | 2 net/netfilter/nf_conntrack_proto_tcp.c | 1 net/netfilter/nf_conntrack_proto_udp.c | 3 - net/netfilter/nf_conntrack_standalone.c | 3 + net/netfilter/nf_nat_helper.c | 2 net/netfilter/nft_ct.c | 3 - net/netfilter/xt_CT.c | 12 +--- net/openvswitch/conntrack.c | 12 +--- net/sched/cls_flow.c | 2 26 files changed, 141 insertions(+), 116 deletions(-)
Florian Westphal
maintainerPATCH v3 1/7 netfilter: conntrack: no need to pass ctinfo to error handler
It is never accessed for reading and the only places that write to it are the icmp(6) handlers, which also set skb->nfct (and skb->nfctinfo).
The conntrack core specifically checks for attached skb->nfct after ->error() invocation and returns early in this case.
---
No changes in v1 and v2.
include/net/netfilter/nf_conntrack_l4proto.h | 2 +- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 12 ++++++------ net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 12 ++++++------ net/netfilter/nf_conntrack_core.c | 3 +-- net/netfilter/nf_conntrack_proto_dccp.c | 1 - net/netfilter/nf_conntrack_proto_sctp.c | 2 +- net/netfilter/nf_conntrack_proto_tcp.c | 1 - net/netfilter/nf_conntrack_proto_udp.c | 3 +-- 8 files changed, 16 insertions(+), 20 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +1 -1
@@ -55,7 +55,7 @@ struct nf_conntrack_l4proto {void (*destroy)(struct nf_conn *ct);int (*error)(struct net *net,struct nf_conn *tmpl,struct sk_buff *skb, -unsigned int dataoff,enum ip_conntrack_info *ctinfo, +unsigned int dataoff,u_int8_t pf,unsigned int hooknum);/* Print out the per-protocol part of the tuple. Return like seq_* */
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +6 -6
@@ -128,13 +128,13 @@ static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,/* Returns conntrack if it dealt with ICMP, and filled in skb fields */ static int icmp_error_message (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb, -enum ip_conntrack_info *ctinfo,unsigned int hooknum) {struct nf_conntrack_tuple innertuple, origtuple;const struct nf_conntrack_l4proto *innerproto;const struct nf_conntrack_tuple_hash *h;const struct nf_conntrack_zone *zone; +enum ip_conntrack_info ctinfo;struct nf_conntrack_zone tmp;NF_CT_ASSERT (skb->nfct ==NULL );
@@ -160,7 +160,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,return -NF_ACCEPT ; } - *ctinfo =IP_CT_RELATED ; + ctinfo =IP_CT_RELATED ; h =nf_conntrack_find_get (net, zone, &innertuple);if (!h) {
@@ -169,11 +169,11 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, }if (NF_CT_DIRECTION (h) ==IP_CT_DIR_REPLY ) - *ctinfo +=IP_CT_IS_REPLY ; + ctinfo +=IP_CT_IS_REPLY ;/* Update skb to refer to this connection */ skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; - skb->nfctinfo = *ctinfo; + skb->nfctinfo = ctinfo;return NF_ACCEPT ; }
@@ -181,7 +181,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,static int icmp_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb,unsigned int dataoff, -enum ip_conntrack_info *ctinfo,u_int8_t pf,unsigned int hooknum) +u8 pf,unsigned int hooknum) {const struct icmphdr *icmph;struct icmphdr _ih;
@@ -225,7 +225,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl, icmph->type != ICMP_REDIRECT)return NF_ACCEPT ; -return icmp_error_message (net, tmpl, skb, ctinfo, hooknum); +return icmp_error_message (net, tmpl, skb, hooknum); }#if IS_ENABLED (CONFIG_NF_CT_NETLINK )
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +6 -6
@@ -145,12 +145,12 @@ static int icmpv6_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, unsigned int icmp6off, - enum ip_conntrack_info *ctinfo, unsigned int hooknum) { struct nf_conntrack_tuple intuple, origtuple;const struct nf_conntrack_tuple_hash *h;const struct nf_conntrack_l4proto *inproto; +enum ip_conntrack_info ctinfo;struct nf_conntrack_zone tmp;NF_CT_ASSERT (skb->nfct ==NULL );
@@ -176,7 +176,7 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,return -NF_ACCEPT ; } - *ctinfo =IP_CT_RELATED ; + ctinfo =IP_CT_RELATED ; h =nf_conntrack_find_get (net,nf_ct_zone_tmpl (tmpl, skb, &tmp), &intuple);
@@ -185,19 +185,19 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,return -NF_ACCEPT ; }else {if (NF_CT_DIRECTION (h) ==IP_CT_DIR_REPLY ) - *ctinfo +=IP_CT_IS_REPLY ; + ctinfo +=IP_CT_IS_REPLY ; }/* Update skb to refer to this connection */ skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; - skb->nfctinfo = *ctinfo; + skb->nfctinfo = ctinfo;return NF_ACCEPT ; }static int icmpv6_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb,unsigned int dataoff, -enum ip_conntrack_info *ctinfo,u_int8_t pf,unsigned int hooknum) +u8 pf,unsigned int hooknum) {const struct icmp6hdr *icmp6h;struct icmp6hdr _ih;
@@ -232,7 +232,7 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl,if (icmp6h->icmp6_type >=128 )return NF_ACCEPT ; -return icmpv6_error_message (net, tmpl, skb, dataoff, ctinfo, hooknum); +return icmpv6_error_message (net, tmpl, skb, dataoff, hooknum); }#if IS_ENABLED (CONFIG_NF_CT_NETLINK )
net/netfilter/nf_conntrack_core.c +1 -2
@@ -1326,8 +1326,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,* inverse of the return code tells to the netfilter * core what to do with the packet. */ if (l4proto->error !=NULL ) { - ret = l4proto->error (net, tmpl, skb, dataoff, &ctinfo, - pf, hooknum); + ret = l4proto->error (net, tmpl, skb, dataoff, pf, hooknum);if (ret <=0 ) {NF_CT_STAT_INC_ATOMIC (net, error);NF_CT_STAT_INC_ATOMIC (net, invalid);
net/netfilter/nf_conntrack_proto_dccp.c +0 -1
@@ -561,7 +561,6 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,static int dccp_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb,unsigned int dataoff, -enum ip_conntrack_info *ctinfo,u_int8_t pf,unsigned int hooknum) {struct dccp_hdr _dh, *dh;
net/netfilter/nf_conntrack_proto_sctp.c +1 -1
@@ -508,7 +508,7 @@ static bool sctp_new(struct nf_conn *ct, const struct sk_buff *skb, }static int sctp_error (struct net *net,struct nf_conn *tpl,struct sk_buff *skb, -unsigned int dataoff,enum ip_conntrack_info *ctinfo, +unsigned int dataoff,u8 pf,unsigned int hooknum) {const struct sctphdr *sh;
net/netfilter/nf_conntrack_proto_tcp.c +0 -1
@@ -750,7 +750,6 @@ static const u8 tcp_valid_flags[(TCPHDR_FIN|TCPHDR_SYN|TCPHDR_RST|TCPHDR_ACK|static int tcp_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb,unsigned int dataoff, -enum ip_conntrack_info *ctinfo,u_int8_t pf,unsigned int hooknum) {
net/netfilter/nf_conntrack_proto_udp.c +1 -2
@@ -112,7 +112,6 @@ static bool udp_new(struct nf_conn *ct, const struct sk_buff *skb,static int udplite_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb,unsigned int dataoff, -enum ip_conntrack_info *ctinfo,u8 pf,unsigned int hooknum) {unsigned int udplen = skb->len - dataoff;
@@ -162,7 +161,7 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl,#endif static int udp_error (struct net *net,struct nf_conn *tmpl,struct sk_buff *skb, -unsigned int dataoff,enum ip_conntrack_info *ctinfo, +unsigned int dataoff,u_int8_t pf,unsigned int hooknum) {
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 2/7 netfilter: reset netfilter state when duplicating packet
In reply to Florian WestphalWe should also toss nf_bridge_info, if any -- packet is leaving via ip_local_out, also, this skb isn't bridged -- it is a locally generated copy. Also this avoids the need to touch this later when skb->nfct is replaced with 'unsigned long _nfct' in followup patch.
---
No changes in v1 and v2.
net/ipv4/netfilter/nf_dup_ipv4.c | 2 +- net/ipv6/netfilter/nf_dup_ipv6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_dup_ipv4.c +1 -1
@@ -68,7 +68,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,#if IS_ENABLED (CONFIG_NF_CONNTRACK )/* Avoid counting cloned packets towards the original connection. */ -nf_conntrack_put (skb->nfct); +nf_reset (skb); skb->nfct = &nf_ct_untracked_get ()->ct_general; skb->nfctinfo =IP_CT_NEW ;nf_conntrack_get (skb->nfct);
net/ipv6/netfilter/nf_dup_ipv6.c +1 -1
@@ -57,7 +57,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,return ;#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -nf_conntrack_put (skb->nfct); +nf_reset (skb); skb->nfct = &nf_ct_untracked_get ()->ct_general; skb->nfctinfo =IP_CT_NEW ;nf_conntrack_get (skb->nfct);
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 3/7 netfilter: reduce direct skb->nfct usage
In reply to Florian WestphalNext patch makes direct skb->nfct access illegal, reduce noise in next patch by using accessors we already have.
---
No changes in v1 and v2.
include/net/ip_vs.h | 9 ++++++--- net/netfilter/nf_conntrack_core.c | 15 +++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-)
include/net/ip_vs.h +6 -3
@@ -1554,10 +1554,13 @@ static inline void ip_vs_notrack(struct sk_buff *skb)struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (!ct || !nf_ct_is_untracked (ct)) { -nf_conntrack_put (skb->nfct); - skb->nfct = &nf_ct_untracked_get ()->ct_general; +struct nf_conn *untracked; + +nf_conntrack_put (&ct->ct_general); + untracked =nf_ct_untracked_get (); +nf_conntrack_get (&untracked->ct_general); + skb->nfct = &untracked->ct_general; skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); }#endif }
net/netfilter/nf_conntrack_core.c +9 -6
@@ -686,8 +686,11 @@ static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb, !nfct_nat(ct) && !nf_ct_is_dying(ct) && atomic_inc_not_zero(&ct->ct_general.use)) { -nf_ct_acct_merge (ct, ctinfo, (struct nf_conn *)skb->nfct); -nf_conntrack_put (skb->nfct); +enum ip_conntrack_info oldinfo; +struct nf_conn *loser_ct =nf_ct_get (skb, &oldinfo); + +nf_ct_acct_merge (ct, ctinfo, loser_ct); +nf_conntrack_put (&loser_ct->ct_general);/* Assign conntrack already in hashes to this skbuff. Don't * modify skb->nfctinfo to ensure consistent stateful filtering. */
@@ -1288,7 +1291,7 @@ unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, struct sk_buff *skb) { - struct nf_conn *ct, *tmpl = NULL; + struct nf_conn *ct, *tmpl;enum ip_conntrack_info ctinfo;struct nf_conntrack_l3proto *l3proto;struct nf_conntrack_l4proto *l4proto;
@@ -1298,9 +1301,9 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,int set_reply =0 ;int ret; -if (skb->nfct) { + tmpl =nf_ct_get (skb, &ctinfo); +if (tmpl) {/* Previously seen (loopback or untracked)? Ignore. */ - tmpl = (struct nf_conn *)skb->nfct;if (!nf_ct_is_template (tmpl)) {NF_CT_STAT_INC_ATOMIC (net, ignore);return NF_ACCEPT ;
@@ -1364,7 +1367,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,/* Invalid: inverse of the return code tells * the netfilter core what to do */ pr_debug ("nf_conntrack_in: Can't track with proto module\n" ); -nf_conntrack_put (skb->nfct); +nf_conntrack_put (&ct->ct_general); skb->nfct =NULL ;NF_CT_STAT_INC_ATOMIC (net, invalid);if (ret == -NF_DROP )
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 4/7 skbuff: add and use skb_nfct helper
In reply to Florian WestphalFollowup patch renames skb->nfct and changes its type so add a helper to avoid intrusive rename change later.
---
changes since v2: this patch is new, it was split from v2 'netfilter: merge ctinfo into nfct pointer storage area'.
include/linux/skbuff.h | 13 ++++++++++--- include/net/netfilter/nf_conntrack_core.h | 2 +- net/core/skbuff.c | 2 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 8 ++++---- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 2 +- net/ipv4/netfilter/nf_defrag_ipv4.c | 4 ++-- net/ipv4/netfilter/nf_dup_ipv4.c | 2 +- net/ipv6/netfilter/ip6t_SYNPROXY.c | 8 ++++---- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 4 ++-- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 4 ++-- net/netfilter/core.c | 2 +- net/netfilter/nf_conntrack_core.c | 4 ++-- net/netfilter/nf_nat_helper.c | 2 +- net/netfilter/xt_CT.c | 2 +- net/openvswitch/conntrack.c | 6 +++--- net/sched/cls_flow.c | 2 +- 16 files changed, 37 insertions(+), 30 deletions(-)
include/linux/skbuff.h +10 -3
@@ -3553,6 +3553,15 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr, skb->csum =csum_add (skb->csum, delta); } +static inline struct nf_conntrack *skb_nfct (const struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_NF_CONNTRACK ) +return skb->nfct; +#else +return NULL ; +#endif +} +#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )void nf_conntrack_destroy (struct nf_conntrack *nfct);static inline void nf_conntrack_put (struct nf_conntrack *nfct)
@@ -3652,9 +3661,7 @@ static inline bool skb_irq_freeable(const struct sk_buff *skb)#if IS_ENABLED (CONFIG_XFRM ) !skb->sp && #endif -#if IS_ENABLED (CONFIG_NF_CONNTRACK ) - !skb->nfct && -#endif + !skb_nfct (skb) && !skb->_skb_refdst && !skb_has_frag_list(skb); }
include/net/netfilter/nf_conntrack_core.h +1 -1
@@ -62,7 +62,7 @@ int __nf_conntrack_confirm(struct sk_buff *skb);/* Confirm a connection: returns NF_DROP if packet must be dropped. */ static inline int nf_conntrack_confirm (struct sk_buff *skb) { -struct nf_conn *ct = (struct nf_conn *)skb->nfct; +struct nf_conn *ct = (struct nf_conn *)skb_nfct (skb);int ret =NF_ACCEPT ;if (ct && !nf_ct_is_untracked (ct)) {
net/core/skbuff.c +1 -1
@@ -655,7 +655,7 @@ static void skb_release_head_state(struct sk_buff *skb) skb->destructor (skb); }#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -nf_conntrack_put (skb->nfct); +nf_conntrack_put (skb_nfct (skb));#endif #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )nf_bridge_put (skb->nf_bridge);
net/ipv4/netfilter/ipt_SYNPROXY.c +4 -4
@@ -107,8 +107,8 @@ synproxy_send_client_synack(struct net *net,synproxy_build_options (nth, opts); -synproxy_send_tcp (net, skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , - niph, nth, tcp_hdr_size); +synproxy_send_tcp (net, skb, nskb,skb_nfct (skb), +IP_CT_ESTABLISHED_REPLY , niph, nth, tcp_hdr_size); } static void
@@ -230,8 +230,8 @@ synproxy_send_client_ack(struct net *net,synproxy_build_options (nth, opts); -synproxy_send_tcp (net, skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , - niph, nth, tcp_hdr_size); +synproxy_send_tcp (net, skb, nskb,skb_nfct (skb), +IP_CT_ESTABLISHED_REPLY , niph, nth, tcp_hdr_size); } static bool
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +1 -1
@@ -137,7 +137,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_info ctinfo;struct nf_conntrack_zone tmp; -NF_CT_ASSERT (skb->nfct ==NULL ); +NF_CT_ASSERT (!skb_nfct (skb)); zone =nf_ct_zone_tmpl (tmpl, skb, &tmp);/* Are they talking about one of our connections? */
net/ipv4/netfilter/nf_defrag_ipv4.c +2 -2
@@ -45,7 +45,7 @@ static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum, {u16 zone_id =NF_CT_DEFAULT_ZONE_ID ;#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -if (skb->nfct) { +if (skb_nfct (skb)) {enum ip_conntrack_info ctinfo;const struct nf_conn *ct =nf_ct_get (skb, &ctinfo);
@@ -75,7 +75,7 @@ static unsigned int ipv4_conntrack_defrag(void *priv,#if !IS_ENABLED (CONFIG_NF_NAT )/* Previously seen (loopback)? Ignore. Do this before fragment check. */ -if (skb->nfct && !nf_ct_is_template ((struct nf_conn *)skb->nfct)) +if (skb_nfct (skb) && !nf_ct_is_template ((struct nf_conn *)skb_nfct (skb)))return NF_ACCEPT ;#endif #endif
net/ipv4/netfilter/nf_dup_ipv4.c +1 -1
@@ -71,7 +71,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,nf_reset (skb); skb->nfct = &nf_ct_untracked_get ()->ct_general; skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); +nf_conntrack_get (skb_nfct (skb));#endif /* * If we are in PREROUTING/INPUT, decrease the TTL to mitigate potential
net/ipv6/netfilter/ip6t_SYNPROXY.c +4 -4
@@ -121,8 +121,8 @@ synproxy_send_client_synack(struct net *net,synproxy_build_options (nth, opts); -synproxy_send_tcp (net, skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , - niph, nth, tcp_hdr_size); +synproxy_send_tcp (net, skb, nskb,skb_nfct (skb), +IP_CT_ESTABLISHED_REPLY , niph, nth, tcp_hdr_size); } static void
@@ -244,8 +244,8 @@ synproxy_send_client_ack(struct net *net,synproxy_build_options (nth, opts); -synproxy_send_tcp (net, skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , - niph, nth, tcp_hdr_size); +synproxy_send_tcp (net, skb, nskb,skb_nfct (skb), +IP_CT_ESTABLISHED_REPLY , niph, nth, tcp_hdr_size); } static bool
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +2 -2
@@ -153,7 +153,7 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,enum ip_conntrack_info ctinfo;struct nf_conntrack_zone tmp; -NF_CT_ASSERT (skb->nfct ==NULL ); +NF_CT_ASSERT (!skb_nfct (skb));/* Are they talking about one of our connections? */ if (!nf_ct_get_tuplepr(skb,
@@ -224,7 +224,7 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl, noct_valid_new[type]) { skb->nfct = &nf_ct_untracked_get ()->ct_general; skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); +nf_conntrack_get (skb_nfct (skb));return NF_ACCEPT ; }
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c +2 -2
@@ -37,7 +37,7 @@ static enum ip6_defrag_users nf_ct6_defrag_user(unsigned int hooknum, {u16 zone_id =NF_CT_DEFAULT_ZONE_ID ;#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -if (skb->nfct) { +if (skb_nfct (skb)) {enum ip_conntrack_info ctinfo;const struct nf_conn *ct =nf_ct_get (skb, &ctinfo);
@@ -61,7 +61,7 @@ static unsigned int ipv6_defrag(void *priv,#if IS_ENABLED (CONFIG_NF_CONNTRACK )/* Previously seen (loopback)? */ -if (skb->nfct && !nf_ct_is_template ((struct nf_conn *)skb->nfct)) +if (skb_nfct (skb) && !nf_ct_is_template ((struct nf_conn *)skb_nfct (skb)))return NF_ACCEPT ;#endif
net/netfilter/core.c +1 -1
@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb->nfct) { +if (skb_nfct (skb)) {rcu_read_lock (); attach =rcu_dereference (ip_ct_attach);if (attach)
net/netfilter/nf_conntrack_core.c +2 -2
@@ -1357,7 +1357,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, goto out; } -NF_CT_ASSERT (skb->nfct); +NF_CT_ASSERT (skb_nfct (skb));/* Decide what timeout policy we want to apply to this flow. */ timeouts =nf_ct_timeout_lookup (net, ct, l4proto);
@@ -1528,7 +1528,7 @@ static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb)/* Attach to new skbuff, and increment count */ nskb->nfct = &ct->ct_general; nskb->nfctinfo = ctinfo; -nf_conntrack_get (nskb->nfct); +nf_conntrack_get (skb_nfct (nskb)); }/* Bring out ya dead! */
net/netfilter/nf_nat_helper.c +1 -1
@@ -60,7 +60,7 @@ static void mangle_contents(struct sk_buff *skb,__skb_trim (skb, skb->len + rep_len - match_len); } -if (nf_ct_l3num ((struct nf_conn *)skb->nfct) ==NFPROTO_IPV4 ) { +if (nf_ct_l3num ((struct nf_conn *)skb_nfct (skb)) ==NFPROTO_IPV4 ) {/* fix IP hdr checksum information */ ip_hdr (skb)->tot_len =htons (skb->len);ip_send_check (ip_hdr (skb));
net/netfilter/xt_CT.c +1 -1
@@ -415,7 +415,7 @@ notrack_tg(struct sk_buff *skb, const struct xt_action_param *par) skb->nfct = &nf_ct_untracked_get ()->ct_general; skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); +nf_conntrack_get (skb_nfct (skb));return XT_CONTINUE ; }
net/openvswitch/conntrack.c +3 -3
@@ -721,8 +721,8 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,/* Associate skb with specified zone. */ if (tmpl) { -if (skb->nfct) -nf_conntrack_put (skb->nfct); +if (skb_nfct (skb)) +nf_conntrack_put (skb_nfct (skb));nf_conntrack_get (&tmpl->ct_general); skb->nfct = &tmpl->ct_general; skb->nfctinfo =IP_CT_NEW ;
@@ -819,7 +819,7 @@ static int ovs_ct_lookup(struct net *net, struct sw_flow_key *key,if (err)return err; - ct = (struct nf_conn *)skb->nfct; + ct = (struct nf_conn *)skb_nfct (skb);if (ct)nf_ct_deliver_cached_events (ct); }
net/sched/cls_flow.c +1 -1
@@ -129,7 +129,7 @@ static u32 flow_get_mark(const struct sk_buff *skb)static u32 flow_get_nfct (const struct sk_buff *skb) {#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -return addr_fold (skb->nfct); +return addr_fold (skb_nfct (skb));#else return 0 ;#endif
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 5/7 netfilter: add and use nf_ct_set helper
In reply to Florian WestphalAdd a helper to assign a nf_conn entry and the ctinfo bits to an sk_buff. This avoids changing code in followup patch that merges skb->nfct and skb->nfctinfo into skb->_nfct.
---
Not part of v2.
include/net/ip_vs.h | 3 +-- include/net/netfilter/nf_conntrack.h | 8 ++++++++ net/ipv4/netfilter/ipt_SYNPROXY.c | 3 +-- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 3 +-- net/ipv4/netfilter/nf_dup_ipv4.c | 3 +-- net/ipv6/netfilter/ip6t_SYNPROXY.c | 3 +-- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 6 ++---- net/ipv6/netfilter/nf_dup_ipv6.c | 3 +-- net/netfilter/core.c | 2 +- net/netfilter/nf_conntrack_core.c | 11 +++-------- net/netfilter/nft_ct.c | 3 +-- net/netfilter/xt_CT.c | 6 ++---- net/openvswitch/conntrack.c | 6 ++---- 13 files changed, 25 insertions(+), 35 deletions(-)
include/net/ip_vs.h +1 -2
@@ -1559,8 +1559,7 @@ static inline void ip_vs_notrack(struct sk_buff *skb)nf_conntrack_put (&ct->ct_general); untracked =nf_ct_untracked_get ();nf_conntrack_get (&untracked->ct_general); - skb->nfct = &untracked->ct_general; - skb->nfctinfo = IP_CT_NEW; + nf_ct_set(skb, untracked, IP_CT_NEW); }#endif }
include/net/netfilter/nf_conntrack.h +8 -0
@@ -34,6 +34,7 @@ union nf_conntrack_proto {struct ip_ct_sctp sctp;struct ip_ct_tcp tcp;struct nf_ct_gre gre; +unsigned int tmpl_padto; };union nf_conntrack_expect_proto {
@@ -341,6 +342,13 @@ struct nf_conn *nf_ct_tmpl_alloc(struct net *net, gfp_t flags);void nf_ct_tmpl_free (struct nf_conn *tmpl); +static inline void +nf_ct_set (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info info) +{ + skb->nfct = &ct->ct_general; + skb->nfctinfo = info; +} +#define NF_CT_STAT_INC (net, count) __this_cpu_inc((net)->ct.stat->count)#define NF_CT_STAT_INC_ATOMIC (net, count) this_cpu_inc((net)->ct.stat->count)#define NF_CT_STAT_ADD_ATOMIC (net, count, v) this_cpu_add((net)->ct.stat->count, (v))
net/ipv4/netfilter/ipt_SYNPROXY.c +1 -2
@@ -57,8 +57,7 @@ synproxy_send_tcp(struct net *net, goto free_nskb;if (nfct) { - nskb->nfct = nfct; - nskb->nfctinfo = ctinfo; +nf_ct_set (nskb, (struct nf_conn *)nfct, ctinfo);nf_conntrack_get (nfct); }
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +1 -2
@@ -172,8 +172,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, ctinfo +=IP_CT_IS_REPLY ;/* Update skb to refer to this connection */ - skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; - skb->nfctinfo = ctinfo; +nf_ct_set (skb,nf_ct_tuplehash_to_ctrack (h), ctinfo);return NF_ACCEPT ; }
net/ipv4/netfilter/nf_dup_ipv4.c +1 -2
@@ -69,8 +69,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,#if IS_ENABLED (CONFIG_NF_CONNTRACK )/* Avoid counting cloned packets towards the original connection. */ nf_reset (skb); - skb->nfct = &nf_ct_untracked_get ()->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW );nf_conntrack_get (skb_nfct (skb));#endif /*
net/ipv6/netfilter/ip6t_SYNPROXY.c +1 -2
@@ -71,8 +71,7 @@ synproxy_send_tcp(struct net *net,skb_dst_set (nskb, dst);if (nfct) { - nskb->nfct = nfct; - nskb->nfctinfo = ctinfo; +nf_ct_set (nskb, (struct nf_conn *)nfct, ctinfo);nf_conntrack_get (nfct); }
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +2 -4
@@ -189,8 +189,7 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl, }/* Update skb to refer to this connection */ - skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; - skb->nfctinfo = ctinfo; +nf_ct_set (skb,nf_ct_tuplehash_to_ctrack (h), ctinfo);return NF_ACCEPT ; }
@@ -222,8 +221,7 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl, type = icmp6h->icmp6_type -130 ;if (type >=0 && type <sizeof (noct_valid_new) && noct_valid_new[type]) { - skb->nfct = &nf_ct_untracked_get ()->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW );nf_conntrack_get (skb_nfct (skb));return NF_ACCEPT ; }
net/ipv6/netfilter/nf_dup_ipv6.c +1 -2
@@ -58,8 +58,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,#if IS_ENABLED (CONFIG_NF_CONNTRACK )nf_reset (skb); - skb->nfct = &nf_ct_untracked_get ()->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW );nf_conntrack_get (skb->nfct);#endif if (hooknum == NF_INET_PRE_ROUTING ||
net/netfilter/core.c +1 -1
@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb_nfct (skb)) { +if (skb->nfct) {rcu_read_lock (); attach =rcu_dereference (ip_ct_attach);if (attach)
net/netfilter/nf_conntrack_core.c +3 -8
@@ -691,10 +691,7 @@ static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb,nf_ct_acct_merge (ct, ctinfo, loser_ct);nf_conntrack_put (&loser_ct->ct_general); -/* Assign conntrack already in hashes to this skbuff. Don't -* modify skb->nfctinfo to ensure consistent stateful filtering. -*/ - skb->nfct = &ct->ct_general; +nf_ct_set (skb, ct, oldinfo);return NF_ACCEPT ; }NF_CT_STAT_INC (net, drop);
@@ -1282,8 +1279,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl, } *set_reply =0 ; } - skb->nfct = &ct->ct_general; - skb->nfctinfo = *ctinfo; +nf_ct_set (skb, ct, *ctinfo);return ct; }
@@ -1526,8 +1522,7 @@ static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb) ctinfo =IP_CT_RELATED ;/* Attach to new skbuff, and increment count */ - nskb->nfct = &ct->ct_general; - nskb->nfctinfo = ctinfo; +nf_ct_set (nskb, ct, ctinfo);nf_conntrack_get (skb_nfct (nskb)); }
net/netfilter/nft_ct.c +1 -2
@@ -554,8 +554,7 @@ static void nft_notrack_eval(const struct nft_expr *expr, ct =nf_ct_untracked_get ();atomic_inc (&ct->ct_general.use); - skb->nfct = &ct->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb, ct,IP_CT_NEW ); }static struct nft_expr_type nft_notrack_type;
net/netfilter/xt_CT.c +2 -4
@@ -30,8 +30,7 @@ static inline int xt_ct_target(struct sk_buff *skb, struct nf_conn *ct)if (!ct) ct =nf_ct_untracked_get ();atomic_inc (&ct->ct_general.use); - skb->nfct = &ct->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb, ct,IP_CT_NEW );return XT_CONTINUE ; }
@@ -413,8 +412,7 @@ notrack_tg(struct sk_buff *skb, const struct xt_action_param *par)if (skb->nfct !=NULL )return XT_CONTINUE ; - skb->nfct = &nf_ct_untracked_get ()->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW );nf_conntrack_get (skb_nfct (skb));return XT_CONTINUE ;
net/openvswitch/conntrack.c +2 -4
@@ -460,8 +460,7 @@ ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone, ct =nf_ct_tuplehash_to_ctrack (h); - skb->nfct = &ct->ct_general; - skb->nfctinfo =ovs_ct_get_info (h); +nf_ct_set (skb, ct,ovs_ct_get_info (h));return ct; }
@@ -724,8 +723,7 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,if (skb_nfct (skb))nf_conntrack_put (skb_nfct (skb));nf_conntrack_get (&tmpl->ct_general); - skb->nfct = &tmpl->ct_general; - skb->nfctinfo =IP_CT_NEW ; +nf_ct_set (skb, tmpl,IP_CT_NEW ); } err = nf_conntrack_in(net, info->family,
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 6/7 netfilter: guarantee 8 byte minalign for template addresses
In reply to Florian WestphalThe next change will merge skb->nfct pointer and skb->nfctinfo status bits into single skb->_nfct (unsigned long) area.
For this to work nf_conn addresses must always be aligned at least on an 8 byte boundary since we will need the lower 3bits to store nfctinfo.
Conntrack templates are allocated via kmalloc.
kbuild test robot reportedBUILD_BUG_ON failed: NFCT_INFOMASK >= ARCH_KMALLOC_MINALIGN on v1 of this patchset, so not all platforms meet this requirement.
Do manual alignment if needed, the alignment offset is stored in the nf_conn entry protocol area. This works because templates are not handed off to L4 protocol trackers.
---
Not part of earlier series.
include/net/netfilter/nf_conntrack.h | 2 ++ net/netfilter/nf_conntrack_core.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
include/net/netfilter/nf_conntrack.h +2 -0
@@ -163,6 +163,8 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,int nf_conntrack_tuple_taken (const struct nf_conntrack_tuple *tuple,const struct nf_conn *ignored_conntrack); +#define NFCT_INFOMASK 7UL +/* Return conntrack_info and tuple hash for given skb. */ static inline struct nf_conn *nf_ct_get (const struct sk_buff *skb,enum ip_conntrack_info *ctinfo)
net/netfilter/nf_conntrack_core.c +24 -5
@@ -350,16 +350,31 @@ static void nf_ct_del_from_dying_or_unconfirmed_list(struct nf_conn *ct)spin_unlock (&pcpu->lock); } +#define NFCT_ALIGN (len) (((len) + NFCT_INFOMASK) & ~NFCT_INFOMASK) +/* Released via destroy_conntrack() */ struct nf_conn *nf_ct_tmpl_alloc (struct net *net,const struct nf_conntrack_zone *zone,gfp_t flags) { -struct nf_conn *tmpl; +struct nf_conn *tmpl, *p; - tmpl =kzalloc (sizeof (*tmpl), flags); -if (tmpl ==NULL ) -return NULL ; +if (ARCH_KMALLOC_MINALIGN <=NFCT_INFOMASK ) { + tmpl =kzalloc (sizeof (*tmpl) +NFCT_INFOMASK , flags); +if (!tmpl) +return NULL ; + + p = tmpl; + tmpl = (struct nf_conn *)NFCT_ALIGN ((unsigned long )p); +if (tmpl != p) { + tmpl = (struct nf_conn *)NFCT_ALIGN ((unsigned long )p); + tmpl->proto.tmpl_padto = (char *)tmpl - (char *)p; + } + }else { + tmpl =kzalloc (sizeof (*tmpl), flags); +if (!tmpl) +return NULL ; + } tmpl->status =IPS_TEMPLATE ;write_pnet (&tmpl->ct_net, net);
@@ -374,7 +389,11 @@ void nf_ct_tmpl_free(struct nf_conn *tmpl) {nf_ct_ext_destroy (tmpl);nf_ct_ext_free (tmpl); -kfree (tmpl); + +if (ARCH_KMALLOC_MINALIGN <=NFCT_INFOMASK ) +kfree ((char *)tmpl - tmpl->proto.tmpl_padto); +else +kfree (tmpl); }EXPORT_SYMBOL_GPL (nf_ct_tmpl_free);
Signature · 1 line
2.7.3
Florian Westphal
maintainerPATCH v3 7/7 netfilter: merge ctinfo into nfct pointer storage area
In reply to Florian WestphalAfter this change conntrack operations (lookup, creation, matching from ruleset) only access one instead of two sk_buff cache lines.
This works for normal conntracks because those are allocated from a slab that guarantees hw cacheline or 8byte alignment (whatever is larger) so the 3 bits needed for ctinfo won't overlap with nf_conn addresses.
Template allocation now does manual address alignment (see previous change) on arches that don't have sufficent kmalloc min alignment.
Some spots intentionally use skb->_nfct instead of skb_nfct() helpers, this is to avoid undoing the skb_nfct() use when we remove untracked conntrack object in the future.
---
Changes since v2:
- split skb_nfct() helper into own change
- adjust for new skb_ct_set() helper added in earlier patch
include/linux/skbuff.h | 21 +++++++++------------ include/net/netfilter/nf_conntrack.h | 11 ++++++----- net/ipv6/netfilter/nf_dup_ipv6.c | 2 +- net/netfilter/core.c | 2 +- net/netfilter/nf_conntrack_core.c | 11 ++++++----- net/netfilter/nf_conntrack_standalone.c | 3 +++ net/netfilter/xt_CT.c | 4 ++-- 7 files changed, 28 insertions(+), 26 deletions(-)
include/linux/skbuff.h +9 -12
@@ -585,7 +585,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,* @cloned: Head may be cloned (check refcnt to be sure) * @ip_summed: Driver fed us an IP checksum * @nohdr: Payload reference only, must not modify header -* @nfctinfo: Relationship of this skb to the connection * @pkt_type: Packet class * @fclone: skbuff clone status * @ipvs_property: skbuff is owned by ipvs
@@ -594,7 +593,7 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,* @nf_trace: netfilter packet trace flag * @protocol: Packet protocol from driver * @destructor: Destruct function -* @nfct: Associated connection, if any +* @_nfct: Associated connection, if any (with nfctinfo bits) * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c * @skb_iif: ifindex of device we arrived on * @tc_index: Traffic control index
@@ -668,7 +667,7 @@ struct sk_buff {struct sec_path *sp;#endif #if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) -struct nf_conntrack *nfct; +unsigned long _nfct;#endif #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )struct nf_bridge_info *nf_bridge;
@@ -721,7 +720,6 @@ struct sk_buff { __u8 pkt_type:3; __u8 pfmemalloc:1; __u8 ignore_df:1; - __u8 nfctinfo:3; __u8 nf_trace:1; __u8 ip_summed:2;
@@ -836,6 +834,7 @@ static inline bool skb_pfmemalloc(const struct sk_buff *skb)#define SKB_DST_NOREF 1UL#define SKB_DST_PTRMASK ~(SKB_DST_NOREF) +#define SKB_NFCT_PTRMASK ~(7UL)/** * skb_dst - returns skb dst_entry * @skb: buffer
@@ -3556,7 +3555,7 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr,static inline struct nf_conntrack *skb_nfct (const struct sk_buff *skb) {#if IS_ENABLED (CONFIG_NF_CONNTRACK ) -return skb->nfct; +return (void *)(skb->_nfct &SKB_NFCT_PTRMASK );#else return NULL ;#endif
@@ -3590,8 +3589,8 @@ static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)static inline void nf_reset (struct sk_buff *skb) {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) -nf_conntrack_put (skb->nfct); - skb->nfct =NULL ; +nf_conntrack_put (skb_nfct (skb)); + skb->_nfct =0 ;#endif #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )nf_bridge_put (skb->nf_bridge);
@@ -3611,10 +3610,8 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src, bool copy) {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) - dst->nfct = src->nfct; -nf_conntrack_get (src->nfct); -if (copy) - dst->nfctinfo = src->nfctinfo; + dst->_nfct = src->_nfct; +nf_conntrack_get (skb_nfct (src));#endif #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) dst->nf_bridge = src->nf_bridge;
@@ -3629,7 +3626,7 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src,static inline void nf_copy (struct sk_buff *dst,const struct sk_buff *src) {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) -nf_conntrack_put (dst->nfct); +nf_conntrack_put (skb_nfct (dst));#endif #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )nf_bridge_put (dst->nf_bridge);
include/net/netfilter/nf_conntrack.h +6 -5
@@ -76,7 +76,7 @@ struct nf_conn {/* Usage count in here is 1 for hash table, 1 per skb, * plus 1 for any connection(s) we are `master' for * -* Hint, SKB address this struct and refcnt via skb->nfct and +* Hint, SKB address this struct and refcnt via skb->_nfct and * helpers nf_conntrack_get() and nf_conntrack_put(). * Helper nf_ct_put() equals nf_conntrack_put() by dec refcnt, * beware nf_ct_get() is different and don't inc refcnt.
@@ -164,13 +164,15 @@ int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple, const struct nf_conn *ignored_conntrack);#define NFCT_INFOMASK 7UL +#define NFCT_PTRMASK ~(NFCT_INFOMASK)/* Return conntrack_info and tuple hash for given skb. */ static inline struct nf_conn *nf_ct_get (const struct sk_buff *skb,enum ip_conntrack_info *ctinfo) { - *ctinfo = skb->nfctinfo; -return (struct nf_conn *)skb->nfct; + *ctinfo = skb->_nfct &NFCT_INFOMASK ; + +return (struct nf_conn *)(skb->_nfct &NFCT_PTRMASK ); }/* decrement reference count on a conntrack */
@@ -347,8 +349,7 @@ void nf_ct_tmpl_free(struct nf_conn *tmpl);static inline void nf_ct_set (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info info) { - skb->nfct = &ct->ct_general; - skb->nfctinfo = info; + skb->_nfct = (unsigned long )ct | info; }#define NF_CT_STAT_INC (net, count) __this_cpu_inc((net)->ct.stat->count)
net/ipv6/netfilter/nf_dup_ipv6.c +1 -1
@@ -59,7 +59,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,#if IS_ENABLED (CONFIG_NF_CONNTRACK )nf_reset (skb);nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW ); -nf_conntrack_get (skb->nfct); +nf_conntrack_get (skb_nfct (skb));#endif if (hooknum ==NF_INET_PRE_ROUTING || hooknum ==NF_INET_LOCAL_IN ) {
net/netfilter/core.c +1 -1
@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb->nfct) { +if (skb->_nfct) {rcu_read_lock (); attach =rcu_dereference (ip_ct_attach);if (attach)
net/netfilter/nf_conntrack_core.c +6 -5
@@ -1239,7 +1239,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,return &ct->tuplehash[IP_CT_DIR_ORIGINAL ]; } -/* On success, returns conntrack ptr, sets skb->nfct and ctinfo */ +/* On success, returns conntrack ptr, sets skb->_nfct | ctinfo */ static inline struct nf_conn * resolve_normal_ct(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
@@ -1323,7 +1323,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,NF_CT_STAT_INC_ATOMIC (net, ignore);return NF_ACCEPT ; } - skb->nfct =NULL ; + skb->_nfct =0 ; }/* rcu_read_lock()ed by nf_hook_thresh */
@@ -1352,7 +1352,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, goto out; }/* ICMP[v6] protocol trackers may assign one conntrack. */ -if (skb->nfct) +if (skb->_nfct) goto out; } repeat:
@@ -1383,7 +1383,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,* the netfilter core what to do */ pr_debug ("nf_conntrack_in: Can't track with proto module\n" );nf_conntrack_put (&ct->ct_general); - skb->nfct =NULL ; + skb->_nfct =0 ;NF_CT_STAT_INC_ATOMIC (net, invalid);if (ret == -NF_DROP )NF_CT_STAT_INC_ATOMIC (net, drop);
@@ -1878,7 +1878,8 @@ int nf_conntrack_init_start(void) nf_conntrack_max = max_factor * nf_conntrack_htable_size; nf_conntrack_cachep =kmem_cache_create ("nf_conntrack" , -sizeof (struct nf_conn ),0 , +sizeof (struct nf_conn ), +NFCT_INFOMASK +1 ,SLAB_DESTROY_BY_RCU |SLAB_HWCACHE_ALIGN ,NULL );if (!nf_conntrack_cachep) goto err_cachep;
net/netfilter/nf_conntrack_standalone.c +3 -0
@@ -642,6 +642,9 @@ static int __init nf_conntrack_standalone_init(void)if (ret <0 ) goto out_start; +BUILD_BUG_ON (SKB_NFCT_PTRMASK !=NFCT_PTRMASK ); +BUILD_BUG_ON (NFCT_INFOMASK <=IP_CT_NUMBER ); +#ifdef CONFIG_SYSCTL nf_ct_netfilter_header =register_net_sysctl (&init_net,"net" , nf_ct_netfilter_table);
net/netfilter/xt_CT.c +2 -2
@@ -23,7 +23,7 @@static inline int xt_ct_target (struct sk_buff *skb,struct nf_conn *ct) {/* Previously seen (loopback)? Ignore. */ -if (skb->nfct !=NULL ) +if (skb->_nfct !=0 )return XT_CONTINUE ;/* special case the untracked ct : we want the percpu object */
@@ -409,7 +409,7 @@ static unsigned int notrack_tg(struct sk_buff *skb, const struct xt_action_param *par) {/* Previously seen (loopback)? Ignore. */ -if (skb->nfct !=NULL ) +if (skb->_nfct !=0 )return XT_CONTINUE ;nf_ct_set (skb,nf_ct_untracked_get (),IP_CT_NEW );
Signature · 1 line
2.7.3
Pablo Neira Ayuso
maintainerRe: [PATCH v3 nf-next 5/7] netfilter: add and use nf_ct_set helper
In reply to Florian Westphalnet/netfilter/core.c void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) · line 378
Quoted 10 lines · Florian Westphal
net/netfilter/core.c +1
-1@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb_nfct (skb)) { +if (skb->nfct) {
I guess this slipped through accidentally. No need to resent, I can amend it here.
Quoted 3 lines
net/netfilter/core.c +0
-0rcu_read_lock (); attach =rcu_dereference (ip_ct_attach);if (attach)
Florian Westphal
maintainerRe: [PATCH v3 nf-next 5/7] netfilter: add and use nf_ct_set helper
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 lines · Florian Westphal
net/netfilter/core.c +0
-0@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *);
Quoted 5 lines
net/netfilter/core.c void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) · line 378
Quoted 2 lines
net/netfilter/core.c +1
-1-if (skb_nfct (skb)) { +if (skb->nfct) {I guess this slipped through accidentally. No need to resent, I can amend it here.
Hmm, let me review this. I thin the skb_nfct() conversion is erroneous. (Q: If original is UNTRRACKED, should the reply packet that is being
attached be UNTRACKED or INVALID?)
I think its "UNTRACKED", and then this needs testing of skb->_nfct .
(at least once the untracked object gets removed).
Re: [PATCH v3 nf-next 5/7] netfilter: add and use nf_ct_set helper
Hi Florian,
Quoted 16 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 lines · Florian Westphal
net/netfilter/core.c +0
-0@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *);Quoted 5 lines
net/netfilter/core.c void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) · line 378
Quoted 2 lines
net/netfilter/core.c +1
-1-if (skb_nfct (skb)) { +if (skb->nfct) {I guess this slipped through accidentally. No need to resent, I can amend it here.
Quoted 3 lines
Hmm, let me review this. I thin the
skb_nfct()conversion is erroneous. (Q: If original is UNTRRACKED, should the reply packet that is being
attached be UNTRACKED or INVALID?)
If the packet is UNTRACKED, then how can there be a reply packet from conntrack point of view? In my opinion it's the user responsibility to handle both directions.
Quoted 3 lines
I think its "UNTRACKED", and then this needs testing of
skb->_nfct.(at least once the untracked object gets removed).
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary
Florian Westphal
maintainerRe: [PATCH v3 nf-next 5/7] netfilter: add and use nf_ct_set helper
Quoted 12 lines · Jozsef Kadlecsik
Quoted 12 lines
Quoted 11 lines
net/netfilter/core.c void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) · line 378
Quoted 8 lines
net/netfilter/core.c +1
-1@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb_nfct (skb)) { +if (skb->nfct) {I guess this slipped through accidentally. No need to resent, I can amend it here.
Quoted 7 lines
Quoted 3 lines
Hmm, let me review this. I thin the
skb_nfct()conversion is erroneous. (Q: If original is UNTRRACKED, should the reply packet that is being
attached be UNTRACKED or INVALID?)If the packet is UNTRACKED, then how can there be a reply packet from conntrack point of view? In my opinion it's the user responsibility to handle both directions.
afaics it would happen with this:
-t raw -j UNTRACKED
-t filter -j REJECT
REJECT target ends up calling nf_ct_attach to associate the rst/icmp packet with original skb->nfct.
Re: [PATCH v3 nf-next 5/7] netfilter: add and use nf_ct_set helper
Quoted 26 lines · Florian Westphal
Quoted 12 lines · Jozsef Kadlecsik
Quoted 12 lines
Quoted 11 lines
net/netfilter/core.c void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) · line 378
Quoted 8 lines
net/netfilter/core.c +1
-1@@ -375,7 +375,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *); -if (skb_nfct (skb)) { +if (skb->nfct) {I guess this slipped through accidentally. No need to resent, I can amend it here.
Quoted 7 lines
Quoted 3 lines
Hmm, let me review this. I thin the
skb_nfct()conversion is erroneous. (Q: If original is UNTRRACKED, should the reply packet that is being
attached be UNTRACKED or INVALID?)If the packet is UNTRACKED, then how can there be a reply packet from conntrack point of view? In my opinion it's the user responsibility to handle both directions.
afaics it would happen with this:
(quoted diff) +0
-2-t raw -j UNTRACKED -t filter -j REJECT
Quoted 2 lines
REJECT target ends up calling
nf_ct_attachto associate the rst/icmp packet with originalskb->nfct.
Ohh, I see. Yes, that should then be UNTRACKED as well. Thanks for the clarification!
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary