Skip to contentSkip to conversation

ip multicast, kernel 2.4.2*, 2.6.*

PATCH In review Lauri Tarkkala 2 participants 3 messages Apr 14, 2004 – Apr 15, 2004

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

PATCH 1/1 ip multicast, kernel 2.4.2*, 2.6.*

There is an obnoxious problem in the sending of both ipv4 and ipv6 multicast/broadcast packets in both the 2.4 and 2.6 series and netfilter modules.

The processing is roughly as follows:
1. If packet is multicast/broadcast, duplicate it.
2. Pass the duplicate packet through netfilter hooks using NF_HOOK_SLOW(IP_POST_ROUTING).
3. Set skb.type to PACKET_LOOPBACK in the netfilter hook callback and pass the packet to netif_rx().
4. Send the original packet out via NF_HOOK(IP_POST_ROUTING).

The reason for this processing (my guess), is that the inbound (duplicate) packet will not be sent, unless the original passes the netfilter hooks. This has the side-effect that netfilter hooks have no way of detecting whether packets are intended to or are going to be looped back. The looped-back packet will of course still go through the inbound hooks.

This is quite error-prone, both in terms of configuring policy for netfilter modules, not to mention optimization and implementation. There are also some cases that just can not be handled correctly.

My first choice would be to simply change the behaviour so that the duplicate packet is not bassed through the IP_POST_ROUTING hook. Below is a patch that does exactly this.. The patch works against recent 2.4.x and 2.6.x series kernels.

I can not think of a (good) reason for the current behaviour. If someone with more history knowledge could enlighten me, I'd be grateful.

Lauri

Signature · 43 lines
Lauri Tarkkala
Safenet Inc. 
http://www.safenet-inc.com/


diff -aur -p linux-2.4.25/net/ipv4/ip_output.c linux-2.4.25-fixed/net/ipv4/ip_output.c
--- linux-2.4.25/net/ipv4/ip_output.c	2004-04-14 06:00:52.000000000 +0300
+++ linux-2.4.25-fixed/net/ipv4/ip_output.c	2004-04-14 06:01:04.000000000 +0300
@@ -233,9 +233,7 @@ int ip_mc_output(struct sk_buff *skb)
 		) {
 			struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
 			if (newskb)
-				NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
-					newskb->dev, 
-					ip_dev_loopback_xmit);
+			        ip_dev_loopback_xmit(newskb);
 		}
 
 		/* Multicasts with ttl 0 must not go beyond the host */
@@ -249,8 +247,7 @@ int ip_mc_output(struct sk_buff *skb)
 	if (rt->rt_flags&RTCF_BROADCAST) {
 		struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
 		if (newskb)
-			NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
-				newskb->dev, ip_dev_loopback_xmit);
+		        ip_dev_loopback_xmit(newskb);
 	}
 
 	return ip_finish_output(skb);
diff -aur -p linux-2.4.25/net/ipv6/ip6_output.c linux-2.4.25-fixed/net/ipv6/ip6_output.c
--- linux-2.4.25/net/ipv6/ip6_output.c	2004-04-14 06:00:52.000000000 +0300
+++ linux-2.4.25-fixed/net/ipv6/ip6_output.c	2004-04-14 05:44:40.000000000 +0300
@@ -118,9 +118,7 @@ int ip6_output(struct sk_buff *skb)
 			   is not supported in any case.
 			 */
 			if (newskb)
-				NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, newskb, NULL,
-					newskb->dev,
-					ip6_dev_loopback_xmit);
+			        ip6_dev_loopback_xmit(newskb);
 
 			if (skb->nh.ipv6h->hop_limit == 0) {
 				kfree_skb(skb);
#1 lore raw

Lauri Tarkkala wrote on 04/13/2004 09:17:31 PM:

Quoted 6 lines

The reason for this processing (my guess), is that the inbound (duplicate) packet will not be sent, unless the original passes the netfilter hooks. This has the side-effect that netfilter hooks have no way of detecting whether packets are intended to or are going to be looped back. The looped-back packet will of course still go through the inbound hooks.

If a packet doesn't pass the outbound hooks, won't your patch still deliver it locally? Isn't that wrong?

I think the reason it creates a duplicate is because there are two cases-- one to be sent to the interface and one to be delivered locally. The one going out the interface should pass the outbound checks (only) and the one delivered locally should pass (I think) first the outbound filter and then the inbound filter. Right?

Whether a particular multicast packet should be looped back or not is not static-- it's determined by the sender (and different senders may have different IP_MULTICAST_LOOP settings for the same group on the same machine). So, there is no answer for netfilter that applies to all multicast packets or even for all for a particular <group,intf>.

Under what circumstances does netfilter need to "detect whether packets are intended to or are going to be looped back?"

Quoted 3 lines

This is quite error-prone, both in terms of configuring policy for netfilter modules, not to mention optimization and implementation. There are also some cases that just can not be handled correctly.

What does it break? Can you give an example?

I'm not saying I disagree (or agree) with your patch yet-- haven't looked at it enough. Just trying to understand what it fixes.

                                                +-DLS
#2 lore raw
Quoted 9 lines · David Stevens
Quoted 6 lines

The reason for this processing (my guess), is that the inbound (duplicate) packet will not be sent, unless the original passes the netfilter hooks. This has the side-effect that netfilter hooks have no way of detecting whether packets are intended to or are going to be looped back. The looped-back packet will of course still go through the inbound hooks.

If a packet doesn't pass the outbound hooks, won't your patch still deliver it locally? Isn't that wrong?

This boils down to how one feels about the following questions.

A)
Should it be possible to send multicast packets through a netfilter module in such a manner that a local listener receives them, but the packet does not enter the network?

B)
Should A netfilter module know if the packet it is processing is destined for the network, or for the local stack?

Personally I feel that the answer to question "B" should be YES. I do not feel so strongly about "A", but I think that should also be a YES.

I do not see much breaking, if a multicast packet is sent to the local stack even if it the network-bound packet was dropped by a packet filter. Note that even after my proposed patch is applied, having this style of behaviour is possible by putting proper processing in the inbound hooks (drop similar multicast packets that have skb.type == PACKET_LOOPBACK set
and that are not on the loopback interface).

Quoted 5 lines

I think the reason it creates a duplicate is because there are two cases-- one to be sent to the interface and one to be delivered locally. The one going out the interface should pass the outbound checks (only) and the one delivered locally should pass (I think) first the outbound filter and then the inbound filter. Right?

This is my interpretation also.

Quoted 2 lines

Under what circumstances does netfilter need to "detect whether packets are intended to or are going to be looped back?"

Well, for one thing a module can use (in the outbound case) in a netfilter hook the "skb->dev->flags & IFF_LOOPBACK" case to detect whether we are on the loopback stack.

Quoted 5 lines
Quoted 3 lines

This is quite error-prone, both in terms of configuring policy for netfilter modules, not to mention optimization and implementation. There are also some cases that just can not be handled correctly.

What does it break? Can you give an example?

Trivial case:

+ Statistics counter in netfilter module counting amount of packets sent out via an interface through the module.

More complicated case:

+ Netfilter module has a policy of not allowing multicast packets to the network, but would like them to be received by a listener bound to the same interface. If the module is actively manipulating the packet instead of just passively filtering, this can be a serious problem.

Hypotethically:

+ Any case where the processing tries to factor into account the intended destination of the packet into the policy decision.

Lauri

Signature · 3 lines
Lauri Tarkkala
Safenet Inc. 
http://www.safenet-inc.com/