Skip to contentSkip to conversation

netfilter using Read Copy Update

PTCH 2.5.68 Applied Stephen Hemminger 4 participants 12 messages Apr 24, 2003 – Apr 30, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

This is an update to netfilter core that uses the read-copy-update instead of brlock. The code is similar to my earlier patch but less invasive.

There should be no visible change to the semantics, and the performance should be the same or better.

Ran a basic test with iptables and NAT, but needs some more through usage.

Reviewed by Paul McKenney for RCU.
Sent to Dave and Andrew for inclusion in next -mm tree.

include/linux/list.h +10 -0
diff -urN -X dontdiff linux-2.5.68/include/linux/list.h linux-2.5-nf/include/linux/list.h
@@ -320,6 +320,16 @@
 	for (pos = (head)->next, n = pos->next; pos != (head); \
 		pos = n, ({ smp_read_barrier_depends(); 0;}), n = pos->next)
 
+/**
+ * list_for_each_continue_rcu	-	iterate over an rcu-protected list 
+ *			continuing from existing point.
+ * @pos:	the &struct list_head to use as a loop counter.
+ * @head:	the head for your list.
+ */
+#define list_for_each_continue_rcu(pos, head) \
+	for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
+        	(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
+
 /* 
  * Double linked lists with a single pointer list head. 
  * Mostly useful for hash tables where the two pointer list head is 
net/core/netfilter.c +43 -29

180 lines not on this page · raw message

#1 lore raw

The motivation for this is to eventually get rid of all use's of brlock in the 2.5 kernel. The existing netfilter code uses the standard doubly linked list structure so converting to RCU was not hard.

The only non-obvious change was introducing list_for_each_continue_rcu which is just a way to move the loop used in nf_iterate up into the include file where the other RCU list magic is held.

The netfilter hooks run in the same context as before (no preempt) and have the same restrictions (can't sleep).

#2 lore raw
In reply to Stephen Hemminger
Quoted 3 lines · Stephen Hemminger

This is an update to netfilter core that uses the read-copy-update instead of brlock. The code is similar to my earlier patch but less invasive.

I will try to review this patch and eventually push it to David Miller.

Quoted 5 lines

There should be no visible change to the semantics, and the performance should be the same or better.

Ran a basic test with iptables and NAT, but needs some more through usage.

We will distribute it with our patch-o-matic system, this should give it more users.

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#3 lore raw

In message <[email protected]> you write:

Quoted 6 lines

--K0mDTbuGRobClnW5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Quoted 6 lines
Quoted 3 lines · Stephen Hemminger

This is an update to netfilter core that uses the read-copy-update instead of brlock. The code is similar to my earlier patch but less invasive.

I will try to review this patch and eventually push it to David Miller.

There is a fundamental flaw in the nf_reinject code: when a packet is reinjected, it makes an attempt to figure out if the hook which sent it to queue in the first place has vanished, and if so it drops the packet.

Of course, this is racy (it compares nf_hook_ops addresses) but "mostly works". The best solution is to hold a reference to the hook so it can't vanish.

Stephen, it should be simple for you to rework your patch on top of this one.

Dave, please apply unless someone has objections. Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Add owner field to nf_hook_ops
Author: Rusty Russell
Status: Trivial

D: Adds an owner field to nf_hook_ops, and use it to hold the hook in place
D: for queued packets.

include/linux/netfilter.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/include/linux/netfilter.h .18005-linux-2.5.68-bk8.updated/include/linux/netfilter.h
@@ -47,6 +47,7 @@ struct nf_hook_ops
 
 	/* User fills in from here down. */
 	nf_hookfn *hook;
+	struct module *owner;
 	int pf;
 	int hooknum;
 	/* Hooks are ordered in ascending priority. */
net/bridge/br_netfilter.c +9 -9
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/bridge/br_netfilter.c .18005-linux-2.5.68-bk8.updated/net/bridge/br_netfilter.c
@@ -572,15 +572,15 @@ static unsigned int ipv4_sabotage_out(un
  * ip_refrag() can return NF_STOLEN.
  */
 static struct nf_hook_ops br_nf_ops[] = {
-	{ { NULL, NULL }, br_nf_pre_routing, PF_BRIDGE, NF_BR_PRE_ROUTING, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_local_in, PF_BRIDGE, NF_BR_LOCAL_IN, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_forward, PF_BRIDGE, NF_BR_FORWARD, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_local_out, PF_BRIDGE, NF_BR_LOCAL_OUT, NF_BR_PRI_FIRST },
-	{ { NULL, NULL }, br_nf_post_routing, PF_BRIDGE, NF_BR_POST_ROUTING, NF_BR_PRI_LAST },
-	{ { NULL, NULL }, ipv4_sabotage_in, PF_INET, NF_IP_PRE_ROUTING, NF_IP_PRI_FIRST },
-	{ { NULL, NULL }, ipv4_sabotage_out, PF_INET, NF_IP_FORWARD, NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD },
-	{ { NULL, NULL }, ipv4_sabotage_out, PF_INET, NF_IP_LOCAL_OUT, NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT },
-	{ { NULL, NULL }, ipv4_sabotage_out, PF_INET, NF_IP_POST_ROUTING, NF_IP_PRI_FIRST }
+	{ { NULL, NULL }, br_nf_pre_routing, THIS_MODULE, PF_BRIDGE, NF_BR_PRE_ROUTING, NF_BR_PRI_BRNF },
+	{ { NULL, NULL }, br_nf_local_in, THIS_MODULE, PF_BRIDGE, NF_BR_LOCAL_IN, NF_BR_PRI_BRNF },
+	{ { NULL, NULL }, br_nf_forward, THIS_MODULE, PF_BRIDGE, NF_BR_FORWARD, NF_BR_PRI_BRNF },
+	{ { NULL, NULL }, br_nf_local_out, THIS_MODULE, PF_BRIDGE, NF_BR_LOCAL_OUT, NF_BR_PRI_FIRST },
+	{ { NULL, NULL }, br_nf_post_routing, THIS_MODULE, PF_BRIDGE, NF_BR_POST_ROUTING, NF_BR_PRI_LAST },
+	{ { NULL, NULL }, ipv4_sabotage_in, THIS_MODULE, PF_INET, NF_IP_PRE_ROUTING, NF_IP_PRI_FIRST },
+	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_FORWARD, NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD },
+	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_LOCAL_OUT, NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT },
+	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_POST_ROUTING, NF_IP_PRI_FIRST }
 };
 
 #define NUMHOOKS (sizeof(br_nf_ops)/sizeof(br_nf_ops[0]))
net/bridge/netfilter/ebtable_filter.c +3 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/bridge/netfilter/ebtable_filter.c .18005-linux-2.5.68-bk8.updated/net/bridge/netfilter/ebtable_filter.c
@@ -70,18 +70,21 @@ ebt_hook (unsigned int hook, struct sk_b
 static struct nf_hook_ops ebt_ops_filter[] = {
 	{
 		.hook		= ebt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_LOCAL_IN,
 		.priority	= NF_BR_PRI_FILTER_BRIDGED,
 	},
 	{
 		.hook		= ebt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_FORWARD,
 		.priority	= NF_BR_PRI_FILTER_BRIDGED,
 	},
 	{
 		.hook		= ebt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_LOCAL_OUT,
 		.priority	= NF_BR_PRI_FILTER_OTHER,
net/bridge/netfilter/ebtable_nat.c +3 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/bridge/netfilter/ebtable_nat.c .18005-linux-2.5.68-bk8.updated/net/bridge/netfilter/ebtable_nat.c
@@ -76,18 +76,21 @@ ebt_nat_src(unsigned int hook, struct sk
 static struct nf_hook_ops ebt_ops_nat[] = {
 	{
 		.hook		= ebt_nat_dst,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_LOCAL_OUT,
 		.priority	= NF_BR_PRI_NAT_DST_OTHER,
 	},
 	{
 		.hook		= ebt_nat_src,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_POST_ROUTING,
 		.priority	= NF_BR_PRI_NAT_SRC,
 	},
 	{
 		.hook		= ebt_nat_dst,
+		.owner		= THIS_MODULE,
 		.pf		= PF_BRIDGE,
 		.hooknum	= NF_BR_PRE_ROUTING,
 		.priority	= NF_BR_PRI_NAT_DST_BRIDGED,
net/core/netfilter.c +28 -21

117 lines not on this page · raw message

net/ipv4/netfilter/arptable_filter.c +2 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/arptable_filter.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/arptable_filter.c
@@ -133,11 +133,13 @@ static unsigned int arpt_hook(unsigned i
 static struct nf_hook_ops arpt_ops[] = {
 	{
 		.hook		= arpt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= NF_ARP,
 		.hooknum	= NF_ARP_IN,
 	},
 	{
 		.hook		= arpt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= NF_ARP,
 		.hooknum	= NF_ARP_OUT,
 	}
net/ipv4/netfilter/ip_conntrack_standalone.c +4 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/ip_conntrack_standalone.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/ip_conntrack_standalone.c
@@ -227,6 +227,7 @@ static unsigned int ip_conntrack_local(u
    make it the first hook. */
 static struct nf_hook_ops ip_conntrack_in_ops = {
 	.hook		= ip_conntrack_in,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_PRE_ROUTING,
 	.priority	= NF_IP_PRI_CONNTRACK,
@@ -234,6 +235,7 @@ static struct nf_hook_ops ip_conntrack_i
 
 static struct nf_hook_ops ip_conntrack_local_out_ops = {
 	.hook		= ip_conntrack_local,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_LOCAL_OUT,
 	.priority	= NF_IP_PRI_CONNTRACK,
@@ -242,6 +244,7 @@ static struct nf_hook_ops ip_conntrack_l
 /* Refragmenter; last chance. */
 static struct nf_hook_ops ip_conntrack_out_ops = {
 	.hook		= ip_refrag,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_POST_ROUTING,
 	.priority	= NF_IP_PRI_LAST,
@@ -249,6 +252,7 @@ static struct nf_hook_ops ip_conntrack_o
 
 static struct nf_hook_ops ip_conntrack_local_in_ops = {
 	.hook		= ip_confirm,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_LOCAL_IN,
 	.priority	= NF_IP_PRI_LAST-1,
net/ipv4/netfilter/ip_fw_compat.c +4 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/ip_fw_compat.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/ip_fw_compat.c
@@ -226,6 +226,7 @@ static int sock_fn(struct sock *sk, int 
 
 static struct nf_hook_ops preroute_ops = {
 	.hook		= fw_in,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_PRE_ROUTING,
 	.priority	= NF_IP_PRI_FILTER,
@@ -233,6 +234,7 @@ static struct nf_hook_ops preroute_ops =
 
 static struct nf_hook_ops postroute_ops = {
 	.hook		= fw_in,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_POST_ROUTING,
 	.priority	= NF_IP_PRI_FILTER,
@@ -240,6 +242,7 @@ static struct nf_hook_ops postroute_ops 
 
 static struct nf_hook_ops forward_ops = {
 	.hook		= fw_in,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_FORWARD,
 	.priority	= NF_IP_PRI_FILTER,
@@ -247,6 +250,7 @@ static struct nf_hook_ops forward_ops = 
 
 static struct nf_hook_ops local_in_ops = {
 	.hook		= fw_confirm,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_LOCAL_IN,
 	.priority	= NF_IP_PRI_LAST - 1,
net/ipv4/netfilter/ip_nat_standalone.c +4 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/ip_nat_standalone.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/ip_nat_standalone.c
@@ -238,6 +238,7 @@ ip_nat_local_fn(unsigned int hooknum,
 /* Before packet filtering, change destination */
 static struct nf_hook_ops ip_nat_in_ops = {
 	.hook		= ip_nat_fn,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_PRE_ROUTING,
 	.priority	= NF_IP_PRI_NAT_DST,
@@ -246,6 +247,7 @@ static struct nf_hook_ops ip_nat_in_ops 
 /* After packet filtering, change source */
 static struct nf_hook_ops ip_nat_out_ops = {
 	.hook		= ip_nat_out,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_POST_ROUTING,
 	.priority	= NF_IP_PRI_NAT_SRC,
@@ -254,6 +256,7 @@ static struct nf_hook_ops ip_nat_out_ops
 /* Before packet filtering, change destination */
 static struct nf_hook_ops ip_nat_local_out_ops = {
 	.hook		= ip_nat_local_fn,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_LOCAL_OUT,
 	.priority	= NF_IP_PRI_NAT_DST,
@@ -262,6 +265,7 @@ static struct nf_hook_ops ip_nat_local_o
 #ifdef CONFIG_IP_NF_NAT_LOCAL
 static struct nf_hook_ops ip_nat_local_in_ops = {
 	.hook		= ip_nat_fn,
+	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_LOCAL_IN,
 	.priority	= NF_IP_PRI_NAT_SRC,
net/ipv4/netfilter/iptable_filter.c +3 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/iptable_filter.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/iptable_filter.c
@@ -125,18 +125,21 @@ ipt_local_out_hook(unsigned int hook,
 static struct nf_hook_ops ipt_ops[] = {
 	{
 		.hook		= ipt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_LOCAL_IN,
 		.priority	= NF_IP_PRI_FILTER,
 	},
 	{
 		.hook		= ipt_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_FORWARD,
 		.priority	= NF_IP_PRI_FILTER,
 	},
 	{
 		.hook		= ipt_local_out_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_LOCAL_OUT,
 		.priority	= NF_IP_PRI_FILTER,
net/ipv4/netfilter/iptable_mangle.c +5 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv4/netfilter/iptable_mangle.c .18005-linux-2.5.68-bk8.updated/net/ipv4/netfilter/iptable_mangle.c
@@ -178,30 +178,35 @@ ipt_local_hook(unsigned int hook,
 static struct nf_hook_ops ipt_ops[] = {
 	{
 		.hook		= ipt_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_PRE_ROUTING, 
 		.priority	= NF_IP_PRI_MANGLE,
 	},
 	{
 		.hook		= ipt_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_LOCAL_IN,
 		.priority	= NF_IP_PRI_MANGLE,
 	},
 	{
 		.hook		= ipt_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_FORWARD,
 		.priority	= NF_IP_PRI_MANGLE,
 	},
 	{
 		.hook		= ipt_local_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_LOCAL_OUT,
 		.priority	= NF_IP_PRI_MANGLE,
 	},
 	{
 		.hook		= ipt_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET,
 		.hooknum	= NF_IP_POST_ROUTING,
 		.priority	= NF_IP_PRI_MANGLE,
net/ipv6/netfilter/ip6table_filter.c +3 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv6/netfilter/ip6table_filter.c .18005-linux-2.5.68-bk8.updated/net/ipv6/netfilter/ip6table_filter.c
@@ -123,18 +123,21 @@ ip6t_local_out_hook(unsigned int hook,
 static struct nf_hook_ops ip6t_ops[] = {
 	{
 		.hook		= ip6t_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_LOCAL_IN,
 		.priority	= NF_IP6_PRI_FILTER,
 	},
 	{
 		.hook		= ip6t_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_FORWARD,
 		.priority	= NF_IP6_PRI_FILTER,
 	},
 	{
 		.hook		= ip6t_local_out_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_LOCAL_OUT,
 		.priority	= NF_IP6_PRI_FILTER,
net/ipv6/netfilter/ip6table_mangle.c +5 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/ipv6/netfilter/ip6table_mangle.c .18005-linux-2.5.68-bk8.updated/net/ipv6/netfilter/ip6table_mangle.c
@@ -186,30 +186,35 @@ ip6t_local_hook(unsigned int hook,
 static struct nf_hook_ops ip6t_ops[] = {
 	{
 		.hook		= ip6t_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_PRE_ROUTING,
 		.priority	= NF_IP6_PRI_MANGLE,
 	},
 	{
 		.hook		= ip6t_local_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_LOCAL_IN,
 		.priority	= NF_IP6_PRI_MANGLE,
 	},
 	{
 		.hook		= ip6t_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_FORWARD,
 		.priority	= NF_IP6_PRI_MANGLE,
 	},
 	{
 		.hook		= ip6t_local_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_LOCAL_OUT,
 		.priority	= NF_IP6_PRI_MANGLE,
 	},
 	{
 		.hook		= ip6t_route_hook,
+		.owner		= THIS_MODULE,
 		.pf		= PF_INET6,
 		.hooknum	= NF_IP6_POST_ROUTING,
 		.priority	= NF_IP6_PRI_MANGLE,
net/sched/sch_ingress.c +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18005-linux-2.5.68-bk8/net/sched/sch_ingress.c .18005-linux-2.5.68-bk8.updated/net/sched/sch_ingress.c
@@ -241,6 +241,7 @@ static struct nf_hook_ops ing_ops =
 {
 	{ NULL, NULL},
 	ing_hook,
+	THIS_MODULE,
 	PF_INET,
 	NF_IP_PRE_ROUTING,
 	NF_IP_PRI_FILTER + 1
#4 lore raw

From: Rusty Russell <[email protected]>
Date: Mon, 28 Apr 2003 14:24:30 +1000

Stephen, it should be simple for you to rework your patch on top of this one.

Dave, please apply unless someone has objections.

Applied, if there is some huge objection we can revert it.

#5 lore raw
In reply to Rusty Russell
Quoted 19 lines · On Mon, 28 Apr 2003 14:24:30 +1000 Rusty Russell <[email protected]> wrote:

In message <[email protected]> you write:

Quoted 6 lines

--K0mDTbuGRobClnW5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Quoted 6 lines
Quoted 3 lines · Stephen Hemminger

This is an update to netfilter core that uses the read-copy-update instead of brlock. The code is similar to my earlier patch but less invasive.

I will try to review this patch and eventually push it to David Miller.

There is a fundamental flaw in the nf_reinject code: when a packet is reinjected, it makes an attempt to figure out if the hook which sent it to queue in the first place has vanished, and if so it drops the packet.

Quoted 7 lines

Of course, this is racy (it compares nf_hook_ops addresses) but "mostly works". The best solution is to hold a reference to the hook so it can't vanish.

Stephen, it should be simple for you to rework your patch on top of this one.

Okay, that makes sense.

#6 lore raw
In reply to Rusty Russell

Addition to Rusty's patch that uses C99 initializers for the Netfilter Ethernet bridge routing hooks table.

Dave if you apply Rusty's for the queue/module/reinject race then please apply this.

net/bridge/br_netfilter.c +45 -9
diff -Nru a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
@@ -572,15 +572,51 @@
  * ip_refrag() can return NF_STOLEN.
  */
 static struct nf_hook_ops br_nf_ops[] = {
-	{ { NULL, NULL }, br_nf_pre_routing, THIS_MODULE, PF_BRIDGE, NF_BR_PRE_ROUTING, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_local_in, THIS_MODULE, PF_BRIDGE, NF_BR_LOCAL_IN, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_forward, THIS_MODULE, PF_BRIDGE, NF_BR_FORWARD, NF_BR_PRI_BRNF },
-	{ { NULL, NULL }, br_nf_local_out, THIS_MODULE, PF_BRIDGE, NF_BR_LOCAL_OUT, NF_BR_PRI_FIRST },
-	{ { NULL, NULL }, br_nf_post_routing, THIS_MODULE, PF_BRIDGE, NF_BR_POST_ROUTING, NF_BR_PRI_LAST },
-	{ { NULL, NULL }, ipv4_sabotage_in, THIS_MODULE, PF_INET, NF_IP_PRE_ROUTING, NF_IP_PRI_FIRST },
-	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_FORWARD, NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD },
-	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_LOCAL_OUT, NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT },
-	{ { NULL, NULL }, ipv4_sabotage_out, THIS_MODULE, PF_INET, NF_IP_POST_ROUTING, NF_IP_PRI_FIRST }
+	{ .hook = br_nf_pre_routing, 
+	  .owner = THIS_MODULE, 
+	  .pf = PF_BRIDGE, 
+	  .hooknum = NF_BR_PRE_ROUTING, 
+	  .priority = NF_BR_PRI_BRNF, },
+	{ .hook = br_nf_local_in,
+	  .owner = THIS_MODULE,
+	  .pf = PF_BRIDGE,
+	  .hooknum = NF_BR_LOCAL_IN,
+	  .priority = NF_BR_PRI_BRNF, },
+	{ .hook = br_nf_forward,
+	  .owner = THIS_MODULE,
+	  .pf = PF_BRIDGE,
+	  .hooknum = NF_BR_FORWARD,
+	  .priority = NF_BR_PRI_BRNF, },
+	{ .hook = br_nf_local_out,
+	  .owner = THIS_MODULE,
+	  .pf = PF_BRIDGE,
+	  .hooknum = NF_BR_LOCAL_OUT,
+	  .priority = NF_BR_PRI_FIRST, },
+	{ .hook = br_nf_post_routing,
+	  .owner = THIS_MODULE,
+	  .pf = PF_BRIDGE,
+	  .hooknum = NF_BR_POST_ROUTING,
+	  .priority = NF_BR_PRI_LAST, },
+	{ .hook = ipv4_sabotage_in,
+	  .owner = THIS_MODULE,
+	  .pf = PF_INET,
+	  .hooknum = NF_IP_PRE_ROUTING,
+	  .priority = NF_IP_PRI_FIRST, },
+	{ .hook = ipv4_sabotage_out,
+	  .owner = THIS_MODULE,
+	  .pf = PF_INET,
+	  .hooknum = NF_IP_FORWARD,
+	  .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
+	{ .hook = ipv4_sabotage_out,
+	  .owner = THIS_MODULE,
+	  .pf = PF_INET,
+	  .hooknum = NF_IP_LOCAL_OUT,
+	  .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
+	{ .hook = ipv4_sabotage_out,
+	  .owner = THIS_MODULE,
+	  .pf = PF_INET,
+	  .hooknum = NF_IP_POST_ROUTING,
+	  .priority = NF_IP_PRI_FIRST, },
 };
 
 #define NUMHOOKS (sizeof(br_nf_ops)/sizeof(br_nf_ops[0]))
#7 lore raw

From: Stephen Hemminger <[email protected]>
Date: Mon, 28 Apr 2003 10:23:07 -0700

Addition to Rusty's patch that uses C99 initializers for the Netfilter Ethernet bridge routing hooks table.

Dave if you apply Rusty's for the queue/module/reinject race then please apply this.

Applied, thanks.

#8 lore raw
In reply to Rusty Russell
Quoted 19 lines · On Mon, 28 Apr 2003 14:24:30 +1000 Rusty Russell <[email protected]> wrote:

In message <[email protected]> you write:

Quoted 6 lines

--K0mDTbuGRobClnW5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Quoted 6 lines
Quoted 3 lines · Stephen Hemminger

This is an update to netfilter core that uses the read-copy-update instead of brlock. The code is similar to my earlier patch but less invasive.

I will try to review this patch and eventually push it to David Miller.

There is a fundamental flaw in the nf_reinject code: when a packet is reinjected, it makes an attempt to figure out if the hook which sent it to queue in the first place has vanished, and if so it drops the packet.

Quoted 7 lines

Of course, this is racy (it compares nf_hook_ops addresses) but "mostly works". The best solution is to hold a reference to the hook so it can't vanish.

Stephen, it should be simple for you to rework your patch on top of this one.

Revised RCU patch. Rusty, you forgot to kfree() the info structure if the try_module_get failed.

include/linux/list.h +10 -0
diff -Nru a/include/linux/list.h b/include/linux/list.h
@@ -335,6 +335,16 @@
 		     prefetch(pos->member.next))
 
 
+/**
+ * list_for_each_continue_rcu	-	iterate over an rcu-protected list 
+ *			continuing from existing point.
+ * @pos:	the &struct list_head to use as a loop counter.
+ * @head:	the head for your list.
+ */
+#define list_for_each_continue_rcu(pos, head) \
+	for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
+        	(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
+
 /* 
  * Double linked lists with a single pointer list head. 
  * Mostly useful for hash tables where the two pointer list head is 
net/core/netfilter.c +49 -22

187 lines not on this page · raw message

#9 lore raw

From: Stephen Hemminger <[email protected]>
Date: Mon, 28 Apr 2003 12:30:09 -0700

Quoted 2 lines · On Mon, 28 Apr 2003 14:24:30 +1000 Rusty Russell <[email protected]> wrote:

Stephen, it should be simple for you to rework your patch on top of this one.

Revised RCU patch. Rusty, you forgot to kfree() the info structure if the try_module_get failed.

Applied, thanks.

#10 lore raw
Quoted 6 lines · On Tue, 29 Apr 2003 01:29:09 -0700 (PDT) "David S. Miller" <[email protected]>…

From: Stephen Hemminger <[email protected]>
Date: Mon, 28 Apr 2003 12:30:09 -0700

On Mon, 28 Apr 2003 14:24:30 +1000
Rusty Russell <[email protected]> wrote:

Quoted 7 lines
Quoted 2 lines

Stephen, it should be simple for you to rework your patch on top of this one.

Revised RCU patch. Rusty, you forgot to kfree() the info structure if the try_module_get failed.

Applied, thanks.

Looks like one line got dropped in the patch.

net/core/netfilter.c +1 -0
diff -Nru a/net/core/netfilter.c b/net/core/netfilter.c
@@ -550,6 +550,7 @@
 		 unsigned int verdict)
 {
 	struct list_head *elem = &info->elem->list;
+	struct list_head *i;
 
 	rcu_read_lock();
 
#11 lore raw

From: Stephen Hemminger <[email protected]>
Date: Tue, 29 Apr 2003 11:58:45 -0700

Quoted 1 line · On Tue, 29 Apr 2003 01:29:09 -0700 (PDT) "David S. Miller" <[email protected]>…

Applied, thanks.

Looks like one line got dropped in the patch.

Unused local var, GCC gave a warning, so I deleted it.