netns NOTRACK
Subsystems (3)
PATCH 1/1 netns NOTRACK
This is netns NOTRACK fix we discussed earlier.
The idea was to remove nf_conntrack_untracked and
declare that ->nfct=NULL and ->nfctinfo=IP_CT_UNTRACKED are untracked connections.
It wasn't tested more than "it boots, no conntracks are created" but so far so good.
include/linux/netfilter/nf_conntrack_common.h +3 -1
@@ -19,7 +19,9 @@ enum ip_conntrack_info {IP_CT_IS_REPLY ,/* Number of distinct IP_CT types (no NEW in reply dirn). */ - IP_CT_NUMBER = IP_CT_IS_REPLY * 2 - 1 +IP_CT_NUMBER =IP_CT_IS_REPLY *2 -1 , + + IP_CT_UNTRACKED, };/* Bitset representing status of connection. */
include/net/netfilter/nf_conntrack.h +1 -4
@@ -259,9 +259,6 @@ extern s16 (*nf_ct_nat_offset)(const struct nf_conn *ct,enum ip_conntrack_dir dir, u32 seq); -/* Fake conntrack entry for untracked connections */ -extern struct nf_conn nf_conntrack_untracked; -/* Iterate over all conntracks: if iter returns true, it's deleted. */ extern void nf_ct_iterate_cleanup (struct net *net,int (*iter)(struct nf_conn *i,void *data),void *data);
@@ -290,7 +287,7 @@ static inline int nf_ct_is_dying(struct nf_conn *ct)static inline int nf_ct_is_untracked (const struct sk_buff *skb) { -return (skb->nfct == &nf_conntrack_untracked.ct_general); +return !skb->nfct && skb->nfctinfo ==IP_CT_UNTRACKED ; }extern int nf_conntrack_set_hashsize (const char *val,struct kernel_param *kp);
include/net/netfilter/nf_conntrack_core.h +1 -1
@@ -59,7 +59,7 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)struct nf_conn *ct = (struct nf_conn *)skb->nfct;int ret =NF_ACCEPT ; -if (ct && ct != &nf_conntrack_untracked) { +if (ct) {if (!nf_ct_is_confirmed (ct) && !nf_ct_is_dying (ct)) ret =__nf_conntrack_confirm (skb);if (likely (ret ==NF_ACCEPT ))
net/bridge/br_netfilter.c +3 -1
@@ -792,9 +792,11 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, }#if defined(CONFIG_NF_CONNTRACK_IPV4 ) || defined(CONFIG_NF_CONNTRACK_IPV4_MODULE ) +#include <net/netfilter/nf_conntrack.h> +static int br_nf_dev_queue_xmit (struct sk_buff *skb) { -if (skb->nfct !=NULL && +if ((skb->nfct !=NULL ||nf_ct_is_untracked (skb)) && (skb->protocol ==htons (ETH_P_IP ) ||IS_VLAN_IP (skb)) && skb->len > skb->dev->mtu && !skb_is_gso (skb))
net/ipv4/netfilter/nf_defrag_ipv4.c +4 -0
@@ -17,7 +17,9 @@#include <linux/netfilter_bridge.h> #include <linux/netfilter_ipv4.h> #include <net/netfilter/ipv4/nf_defrag_ipv4.h> +#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netfilter/nf_conntrack.h> +#endif /* Returns new sk_buff, or NULL */ static int nf_ct_ipv4_gather_frags (struct sk_buff *skb,u_int32_t user)
@@ -62,6 +64,8 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,fragment check. */ if (skb->nfct && !nf_ct_is_template ((struct nf_conn *)skb->nfct))return NF_ACCEPT ; +if (nf_ct_is_untracked (skb)) +return NF_ACCEPT ;#endif #endif /* Gather fragments. */
net/ipv4/netfilter/nf_nat_core.c +0 -3
@@ -736,9 +736,6 @@ static int __init nf_nat_init(void)rcu_assign_pointer (nf_nat_protos[IPPROTO_ICMP ], &nf_nat_protocol_icmp);spin_unlock_bh (&nf_nat_lock); -/* Initialize fake conntrack so that NAT will skip it */ - nf_conntrack_untracked.status |=IPS_NAT_DONE_MASK ; - l3proto =nf_ct_l3proto_find_get ((u_int16_t )AF_INET );BUG_ON (nf_nat_seq_adjust_hook !=NULL );
net/ipv4/netfilter/nf_nat_standalone.c +1 -4
@@ -93,11 +93,8 @@ nf_nat_fn(unsigned int hooknum,have dropped it. Hence it's the user's responsibilty to packet filter it out, or implement conntrack/NAT for that protocol. 8) --RR */ -if (!ct) -return NF_ACCEPT ; -/* Don't try to NAT if this packet is not conntracked */ -if (ct == &nf_conntrack_untracked) +if (!ct)return NF_ACCEPT ; nat =nfct_nat (ct);
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +2 -0
@@ -214,6 +214,8 @@ static unsigned int ipv6_defrag(unsigned int hooknum,/* Previously seen (loopback)? */ if (skb->nfct && !nf_ct_is_template ((struct nf_conn *)skb->nfct))return NF_ACCEPT ; +if (nf_ct_is_untracked (skb)) +return NF_ACCEPT ; reasm =nf_ct_frag6_gather (skb,nf_ct6_defrag_user (hooknum, skb));/* queued */
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +2 -3
@@ -205,9 +205,8 @@ icmpv6_error(struct net *net, struct sk_buff *skb, unsigned int dataoff, type = icmp6h->icmp6_type -130 ;if (type >=0 && type <sizeof (noct_valid_new) && noct_valid_new[type]) { - skb->nfct = &nf_conntrack_untracked.ct_general; - skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); + skb->nfct =NULL ; + skb->nfctinfo =IP_CT_UNTRACKED ;return NF_ACCEPT ; }
net/netfilter/core.c +3 -1
@@ -210,6 +210,8 @@ int skb_make_writable(struct sk_buff *skb, unsigned int writable_len)EXPORT_SYMBOL (skb_make_writable);#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) +#include <net/netfilter/nf_conntrack.h> +/* This does not belong here, but locally generated errors need it if connection tracking in use: without this, connection may not be in hash table, and hence manufactured ICMP or RST packets will not be associated with it. */
@@ -220,7 +222,7 @@ void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {void (*attach)(struct sk_buff *,struct sk_buff *); -if (skb->nfct) { +if (skb->nfct ||nf_ct_is_untracked (skb)) {rcu_read_lock (); attach =rcu_dereference (ip_ct_attach);if (attach)
net/netfilter/nf_conntrack_core.c +7 -16
@@ -61,9 +60,6 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);unsigned int nf_conntrack_max__read_mostly ;EXPORT_SYMBOL_GPL (nf_conntrack_max); -struct nf_conn nf_conntrack_untracked__read_mostly ; -EXPORT_SYMBOL_GPL (nf_conntrack_untracked); -static int nf_conntrack_hash_rnd_initted;static unsigned int nf_conntrack_hash_rnd;
@@ -779,7 +775,8 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,return NF_ACCEPT ; } skb->nfct =NULL ; - } + }else if (nf_ct_is_untracked (skb)) +return NF_ACCEPT ;/* rcu_read_lock()ed by nf_hook_slow */ l3proto =__nf_ct_l3proto_find (pf);
@@ -1012,6 +1009,11 @@ static void nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb)/* This ICMP is in reverse direction to the packet which caused it */ ct =nf_ct_get (skb, &ctinfo); +if (!ct && ctinfo ==IP_CT_UNTRACKED ) { + nskb->nfct =NULL ; + nskb->nfctinfo =IP_CT_UNTRACKED ; +return ; + }if (CTINFO2DIR (ctinfo) ==IP_CT_DIR_ORIGINAL ) ctinfo =IP_CT_RELATED +IP_CT_IS_REPLY ;else
@@ -1132,10 +1134,6 @@ static void nf_ct_release_dying_list(struct net *net)static void nf_conntrack_cleanup_init_net (void ) { -/* wait until all references to nf_conntrack_untracked are dropped */ -while (atomic_read (&nf_conntrack_untracked.ct_general.use) >1 ) -schedule (); -nf_conntrack_helper_fini ();nf_conntrack_proto_fini (); }
@@ -1298,14 +1296,6 @@ static int nf_conntrack_init_init_net(void)if (ret <0 ) goto err_helper; -/* Set up fake conntrack: to never be deleted, not in any hashes */ -#ifdef CONFIG_NET_NS - nf_conntrack_untracked.ct_net = &init_net; -#endif -atomic_set (&nf_conntrack_untracked.ct_general.use,1 ); -/* - and look it like as a confirmed connection */ -set_bit (IPS_CONFIRMED_BIT , &nf_conntrack_untracked.status); -return 0 ; err_helper:
net/netfilter/nf_conntrack_netlink.c +2 -7
@@ -457,20 +457,16 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct)static int ctnetlink_conntrack_event (unsigned int events,struct nf_ct_event *item) { -struct net *net; +struct nf_conn *ct = item->ct; +struct net *net =nf_ct_net (ct);struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;struct nlattr *nest_parms; -struct nf_conn *ct = item->ct;struct sk_buff *skb;unsigned int type;unsigned int flags =0 , group;int err; -/* ignore our fake conntrack entry */ -if (ct == &nf_conntrack_untracked) -return 0 ; -if (events & (1 <<IPCT_DESTROY )) { type =IPCTNL_MSG_CT_DELETE ; group =NFNLGRP_CONNTRACK_DESTROY ;
@@ -484,7 +480,6 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) }else return 0 ; - net =nf_ct_net (ct);if (!item->report && !nfnetlink_has_listeners (net, group))return 0 ;
net/netfilter/xt_CT.c +11 -7
@@ -27,9 +27,14 @@ static unsigned int xt_ct_target(struct sk_buff *skb,if (skb->nfct !=NULL )return XT_CONTINUE ; -atomic_inc (&ct->ct_general.use); - skb->nfct = &ct->ct_general; - skb->nfctinfo =IP_CT_NEW ; +if (ct) { +atomic_inc (&ct->ct_general.use); + skb->nfct = &ct->ct_general; + skb->nfctinfo =IP_CT_NEW ; + }else { + skb->nfct =NULL ; + skb->nfctinfo =IP_CT_UNTRACKED ; + }return XT_CONTINUE ; }
@@ -64,8 +69,7 @@ static bool xt_ct_tg_check(const struct xt_tgchk_param *par)return false;if (info->flags &XT_CT_NOTRACK ) { - ct = &nf_conntrack_untracked; -atomic_inc (&ct->ct_general.use); + ct =NULL ; goto out; }
@@ -118,14 +122,14 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par)struct nf_conn *ct = info->ct;struct nf_conn_help *help; -if (ct != &nf_conntrack_untracked) { +if (ct) { help =nfct_help (ct);if (help)module_put (help->helper->me);nf_ct_l3proto_module_put (par->family); +nf_ct_put (info->ct); } -nf_ct_put (info->ct); }static struct xt_target xt_ct_tg__read_mostly = {
net/netfilter/xt_NOTRACK.c +3 -4
@@ -19,13 +19,12 @@ notrack_tg(struct sk_buff *skb, const struct xt_target_param *par)if (skb->nfct !=NULL )return XT_CONTINUE ; -/* Attach fake conntrack entry. +/* "Attach" fake conntrack entry. If there is a real ct entry correspondig to this packet, it'll hang aroun till timing out. We don't deal with it for performance reasons. JK */ - skb->nfct = &nf_conntrack_untracked.ct_general; - skb->nfctinfo =IP_CT_NEW ; -nf_conntrack_get (skb->nfct); + skb->nfct =NULL ; + skb->nfctinfo =IP_CT_UNTRACKED ;return XT_CONTINUE ; }
net/netfilter/xt_cluster.c +0 -3
@@ -119,9 +119,6 @@ xt_cluster_mt(const struct sk_buff *skb, const struct xt_match_param *par)if (ct ==NULL )return false; -if (ct == &nf_conntrack_untracked) -return false; -if (ct->master) hash =xt_cluster_hash (ct->master, info);else
net/netfilter/xt_conntrack.c +1 -1
@@ -123,7 +123,7 @@ conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par, ct =nf_ct_get (skb, &ctinfo); -if (ct == &nf_conntrack_untracked) +if (!ct && ctinfo ==IP_CT_UNTRACKED ) statebit =XT_CONNTRACK_STATE_UNTRACKED ;else if (ct !=NULL ) statebit =XT_CONNTRACK_STATE_BIT (ctinfo);
net/netfilter/xt_socket.c +1 -1
@@ -127,7 +127,7 @@ socket_match(const struct sk_buff *skb, const struct xt_match_param *par,* reply packet of an established SNAT-ted connection. */ ct =nf_ct_get (skb, &ctinfo); - if (ct && (ct != &nf_conntrack_untracked) && + if (ct && ((iph->protocol != IPPROTO_ICMP && ctinfo == IP_CT_IS_REPLY + IP_CT_ESTABLISHED) || (iph->protocol == IPPROTO_ICMP &&
Quoted 8 lines · Alexey Dobriyan
This is netns NOTRACK fix we discussed earlier.
The idea was to remove
nf_conntrack_untrackedand
declare that ->nfct=NULL and ->nfctinfo=IP_CT_UNTRACKED are untracked connections.It wasn't tested more than "it boots, no conntracks are created" but so far so good.
No major objections. Comments inline:
include/net/netfilter/nf_conntrack.h static inline int nf_ct_is_dying(struct nf_conn *ct) · line 290
Quoted 6 lines
include/net/netfilter/nf_conntrack.h +1
-1@@ -290,7 +287,7 @@ static inline int nf_ct_is_dying(struct nf_conn *ct)static inline int nf_ct_is_untracked (const struct sk_buff *skb) { -return (skb->nfct == &nf_conntrack_untracked.ct_general); +return !skb->nfct && skb->nfctinfo ==IP_CT_UNTRACKED ;
Checking just nfctinfo should be enough, its invalid to assign a new conntrack without assigning nfctinfo.
What's missing however is clearing of nfctinfo in nf_reset().
Quoted 5 lines
net/bridge/br_netfilter.c +0
-0
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, · line 799
Quoted 9 lines
net/bridge/br_netfilter.c +3
-1@@ -792,9 +792,11 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, }#if defined(CONFIG_NF_CONNTRACK_IPV4 ) || defined(CONFIG_NF_CONNTRACK_IPV4_MODULE ) +#include <net/netfilter/nf_conntrack.h> +static int br_nf_dev_queue_xmit (struct sk_buff *skb) { - if (skb->nfct != NULL && + if ((skb->nfct != NULL || nf_ct_is_untracked(skb)) &&
Seems unnecessary since nfct should be NULL when the conntrack is untracked.
net/netfilter/nf_conntrack_core.c static void nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb) · line 1012
Quoted 9 lines
net/netfilter/nf_conntrack_core.c +1
-0@@ -1012,6 +1009,11 @@ static void nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb)/* This ICMP is in reverse direction to the packet which caused it */ ct =nf_ct_get (skb, &ctinfo); +if (!ct && ctinfo ==IP_CT_UNTRACKED ) {
!ct also should be unnecessary.
Quoted 16 lines
net/netfilter/nf_conntrack_core.c +4
-0+ nskb->nfct =NULL ; + nskb->nfctinfo =IP_CT_UNTRACKED ; +return ; + }if (CTINFO2DIR (ctinfo) ==IP_CT_DIR_ORIGINAL ) ctinfo =IP_CT_RELATED +IP_CT_IS_REPLY ;else net/netfilter/xt_CT.c +0
-0@@ -27,9 +27,14 @@ static unsigned int xt_ct_target(struct sk_buff *skb,if (skb->nfct !=NULL )return XT_CONTINUE ;
net/netfilter/xt_CT.c static unsigned int xt_ct_target(struct sk_buff *skb, · line 36
Quoted 10 lines
net/netfilter/xt_CT.c +7
-3-atomic_inc (&ct->ct_general.use); - skb->nfct = &ct->ct_general; - skb->nfctinfo =IP_CT_NEW ; +if (ct) { +atomic_inc (&ct->ct_general.use); + skb->nfct = &ct->ct_general; + skb->nfctinfo =IP_CT_NEW ; + }else { + skb->nfct =NULL ; + skb->nfctinfo =IP_CT_UNTRACKED ;
Perhaps use a small inline function for this reoccuring pattern. nf_ct_set_untracked()?
Quoted 1 line
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Alexey Dobriyan
This is netns NOTRACK fix we discussed earlier.
The idea was to remove
nf_conntrack_untrackedand
declare that ->nfct=NULL and ->nfctinfo=IP_CT_UNTRACKED are untracked connections.
As invalid connections used nfct=NULL, how are they now checked for?
Quoted 10 lines · Jan Engelhardt
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Alexey Dobriyan
This is netns NOTRACK fix we discussed earlier.
The idea was to remove
nf_conntrack_untrackedand
declare that ->nfct=NULL and ->nfctinfo=IP_CT_UNTRACKED are untracked connections.As invalid connections used nfct=NULL, how are they now checked for?
Sorry? if ->nfct == NULL && ->nfctinfo == IP_CT_UNTRACKED, then untracked, otherwise invalid.
Additional checks were inserted where necesary.
Quoted 9 lines · Alexey Dobriyan
Quoted 8 lines · Jan Engelhardt
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Alexey Dobriyan
This is netns NOTRACK fix we discussed earlier.
The idea was to remove
nf_conntrack_untrackedand
declare that ->nfct=NULL and ->nfctinfo=IP_CT_UNTRACKED are untracked connections.
Quoted 6 lines
Quoted 2 lines
As invalid connections used nfct=NULL, how are they now checked for?
Sorry? if ->nfct == NULL && ->nfctinfo ==
IP_CT_UNTRACKED, then untracked, otherwise invalid.
Additional checks were inserted where necesary.
I was under the impression that (before your commit), when ->nfct is NULL, then ->nfctinfo is undefined, but in fact, net/core/skbuff.c explicitly zeroes it, so invalid conncetions will have nfctinfo==IP_CT_ESTABLISHED in practice.
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Alexey Dobriyan
net/bridge/br_netfilter.c +0
-0@@ -792,9 +792,11 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, }
Quoted 10 lines
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, · line 799
Quoted 7 lines
net/bridge/br_netfilter.c +3
-1#if defined(CONFIG_NF_CONNTRACK_IPV4) || defined(CONFIG_NF_CONNTRACK_IPV4_MODULE) +#include <net/netfilter/nf_conntrack.h> + static int br_nf_dev_queue_xmit(struct sk_buff *skb) { - if (skb->nfct != NULL && + if ((skb->nfct != NULL || nf_ct_is_untracked(skb)) &&Seems unnecessary since nfct should be NULL when the conntrack is untracked.
Before untracked connections would pass the test, so additional check required. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Alexey Dobriyan
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Alexey Dobriyan
net/bridge/br_netfilter.c +0
-0@@ -792,9 +792,11 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, }Quoted 9 lines
net/bridge/br_netfilter.c static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb, · line 799
Quoted 7 lines
net/bridge/br_netfilter.c +3
-1#if defined(CONFIG_NF_CONNTRACK_IPV4 ) || defined(CONFIG_NF_CONNTRACK_IPV4_MODULE ) +#include <net/netfilter/nf_conntrack.h> +static int br_nf_dev_queue_xmit (struct sk_buff *skb) { - if (skb->nfct != NULL && + if ((skb->nfct != NULL || nf_ct_is_untracked(skb)) &&Seems unnecessary since nfct should be NULL when the conntrack is untracked.
Quoted 1 line
Before untracked connections would pass the test, so additional check required.
Actually they are supposed to pass this test since they are also defragmented.
Quoted 1 line · Patrick McHardy
What's missing however is clearing of nfctinfo in
nf_reset().
And apparently __nf_copy() should be tweaked too. :(