From: Vasily Averin <vvs@parallels.com>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
Patrick McHardy <kaber@trash.net>,
Pablo Neira Ayuso <pablo@netfilter.org>
Subject: [PATCH RFC v2] Bridge: do not defragment packets unless connection tracking is enabled
Date: Sat, 03 May 2014 11:18:32 +0400 [thread overview]
Message-ID: <53649848.2010506@parallels.com> (raw)
In-Reply-To: <20140502225522.GA12404@breakpoint.cc>
Currently bridge can silently drop ipv4 fragments.
If node have loaded nf_defrag_ipv4 module but have no nf_conntrack_ipv4,
br_nf_pre_routing defragments incoming ipv4 fragments, but skb->nfct check
in br_nf_dev_queue_xmit does not allow to re-fragment combined packet back,
and therefore it is dropped in br_dev_queue_push_xmit without incrementing
of any failcounters.
According to Patrick McHardy, bridge should not defragment and fragment
packets unless conntrack is enabled.
This patch adds per network namespace flag to manage ipv4 defragmentation
in bridge.
v2: added missed hooks: nf_conntrack pernet_operations hooks changes flag state
Signed-off-by: Vasily Averin <vvs@openvz.org>
---
include/net/netns/conntrack.h | 1 +
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 2 +
net/ipv4/netfilter/nf_defrag_ipv4.c | 39 +++++++++++++++++++++++-
3 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
index 773cce3..7589937 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -25,6 +25,7 @@ struct nf_proto_net {
struct nf_generic_net {
struct nf_proto_net pn;
unsigned int timeout;
+ bool br_ipv4_defrag_disabled;
};
struct nf_tcp_net {
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 8127dc8..9ca9333 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -432,6 +432,7 @@ static int ipv4_net_init(struct net *net)
pr_err("nf_conntrack_ipv4: pernet registration failed\n");
goto out_ipv4;
}
+ net->ct.nf_ct_proto.generic.br_ipv4_defrag_disabled = false;
return 0;
out_ipv4:
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmp);
@@ -445,6 +446,7 @@ out_tcp:
static void ipv4_net_exit(struct net *net)
{
+ net->ct.nf_ct_proto.generic.br_ipv4_defrag_disabled = true;
nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv4);
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmp);
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp4);
diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c
index 12e13bd..0bd499b 100644
--- a/net/ipv4/netfilter/nf_defrag_ipv4.c
+++ b/net/ipv4/netfilter/nf_defrag_ipv4.c
@@ -86,6 +86,20 @@ static unsigned int ipv4_conntrack_defrag(const struct nf_hook_ops *ops,
enum ip_defrag_users user =
nf_ct_defrag_user(ops->hooknum, skb);
+#if IS_ENABLED(CONFIG_NF_CONNTRACK) && defined (CONFIG_BRIDGE_NETFILTER)
+ if ((user >= IP_DEFRAG_CONNTRACK_BRIDGE_IN) &&
+ (user <= __IP_DEFRAG_CONNTRACK_BRIDGE_IN)) {
+#ifdef CONFIG_NET_NS
+ struct net *net = skb->sk->sk_net;
+#else
+ struct net *net = &init_net;
+#endif
+ /* A bridge should not defragment and fragment packets.
+ We only do it if connection tracking is enabled. */
+ if (net->ct.nf_ct_proto.generic.br_ipv4_defrag_disabled)
+ return NF_ACCEPT;
+ }
+#endif
if (nf_ct_ipv4_gather_frags(skb, user))
return NF_STOLEN;
}
@@ -109,14 +123,37 @@ static struct nf_hook_ops ipv4_defrag_ops[] = {
},
};
+static int nf_defrag_ipv4_net_init(struct net *net)
+{
+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
+ net->ct.nf_ct_proto.generic.br_ipv4_defrag_disabled = true;
+#endif
+ return 0;
+}
+
+static struct pernet_operations nf_defrag_ipv4_net_ops = {
+ .init = nf_defrag_ipv4_net_init,
+};
+
static int __init nf_defrag_init(void)
{
- return nf_register_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
+ int ret = 0;
+
+ ret = register_pernet_subsys(&nf_defrag_ipv4_net_ops);
+ if (ret)
+ goto out;
+
+ ret = nf_register_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
+ if (ret)
+ unregister_pernet_subsys(&nf_defrag_ipv4_net_ops);
+out:
+ return ret;
}
static void __exit nf_defrag_fini(void)
{
nf_unregister_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
+ unregister_pernet_subsys(&nf_defrag_ipv4_net_ops);
}
void nf_defrag_ipv4_enable(void)
--
1.7.5.4
next prev parent reply other threads:[~2014-05-03 7:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20140430092905.GA4318@localhost>
2014-05-02 15:40 ` [PATCH RFC] Bridge: do not defragment packets unless connection tracking is enabled Vasily Averin
2014-05-02 22:55 ` Florian Westphal
2014-05-03 7:15 ` Vasily Averin
2014-05-03 7:18 ` Vasily Averin [this message]
2014-05-03 23:39 ` Pablo Neira Ayuso
2014-05-04 0:23 ` Florian Westphal
2014-05-04 11:15 ` Pablo Neira Ayuso
2014-05-04 20:06 ` Bart De Schuymer
2014-05-04 23:01 ` Pablo Neira Ayuso
2014-05-05 12:55 ` [PATCH RFC 0/7] users counter to manage ipv4 defragmentation on bridge Vasily Averin
2014-05-05 20:57 ` Florian Westphal
2014-05-07 13:27 ` Vasily Averin
2014-05-07 18:49 ` Bart De Schuymer
[not found] ` <cover.1399292146.git.vvs@openvz.org>
2014-05-05 12:55 ` [PATCH 1/7] nf: added per net namespace ipv4 defragmentation users counter Vasily Averin
2014-05-05 12:55 ` [PATCH 2/7] nf: initialization of " Vasily Averin
2014-05-05 12:56 ` [PATCH 3/7] nf: increment and decrement functions for " Vasily Averin
2014-05-05 12:56 ` [PATCH 4/7] nf: ipv4 defragmentation users counter changes in nf_conntrack_ipv4 module Vasily Averin
2014-05-05 12:56 ` [PATCH 5/7] nf: ipv4 defragmentation users counter changes in TPROXY target Vasily Averin
2014-05-05 12:56 ` [PATCH 6/7] nf: ipv4 defragmentation users counter changes in xt_socket match Vasily Averin
2014-05-05 12:56 ` [PATCH 7/7] nf: use counter to manage ipv4 defragmentation on bridge Vasily Averin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53649848.2010506@parallels.com \
--to=vvs@parallels.com \
--cc=fw@strlen.de \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).