Re: Bind to protocol with AF_PACKET doesn't work for outgoing packets

From: Andi Kleen (ak@suse.de)
Date: Thu Nov 01 2001 - 11:46:56 EST


On Thu, Nov 01, 2001 at 04:18:27PM +0100, Joris van Rantwijk wrote:
> Ah, right. I suspected there was a good reason not to do it, or it
> would have been done ages ago.
> But it's still a bit weird isn't it ?
> You sure won't find this in man packet(7).
>
I would more consider it a bug. I didn't know about it while writing
packet(7)

Here is a patch.

-Andi

--- linux-2.4.13-work/net/packet/af_packet.c-PACKET Tue Aug 7 17:30:50 2001
+++ linux-2.4.13-work/net/packet/af_packet.c Thu Nov 1 17:38:12 2001
@@ -250,6 +250,9 @@
         if (skb->pkt_type == PACKET_LOOPBACK)
                 goto out;
 
+ if (sk->num != htons(ETH_P_ALL) && skb->protocol != sk->num)
+ goto out;
+
         if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
                 goto oom;
 
@@ -413,6 +416,10 @@
                 goto drop;
 
         sk = (struct sock *) pt->data;
+
+ if (sk->num != htons(ETH_P_ALL) && skb->protocol != sk->num)
+ goto drop;
+
         po = sk->protinfo.af_packet;
 
         skb->dev = dev;
@@ -824,7 +831,8 @@
         }
 
         sk->num = protocol;
- sk->protinfo.af_packet->prot_hook.type = protocol;
+ /* XXX Always bind to ETH_P_ALL to catch outgoing packets. */
+ sk->protinfo.af_packet->prot_hook.type = htons(ETH_P_ALL);
         sk->protinfo.af_packet->prot_hook.dev = dev;
 
         sk->protinfo.af_packet->ifindex = dev ? dev->ifindex : 0;
@@ -973,7 +981,7 @@
         sk->protinfo.af_packet->prot_hook.data = (void *)sk;
 
         if (protocol) {
- sk->protinfo.af_packet->prot_hook.type = protocol;
+ sk->protinfo.af_packet->prot_hook.type = htons(ETH_P_ALL);
                 dev_add_pack(&sk->protinfo.af_packet->prot_hook);
                 sock_hold(sk);
                 sk->protinfo.af_packet->running = 1;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Nov 07 2001 - 21:00:15 EST