[PATCH] net: packet: option to only pass skb protocol

From: Michael S. Tsirkin
Date: Tue Jan 05 2010 - 14:00:45 EST


When sending packets with a packet socket it is often necessary to set
protocol in msg_name: otherwise the protocol field in the skb will not
be set correctly. However, currently doing this also requires
supplying the interface index.

The following patch makes it possible to avoid supplying the interface
index by interpreting index 0 as "use device this socket is bound to".

Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
---
net/packet/af_packet.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index e0516a2..a81dae8 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -958,7 +958,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
+ offsetof(struct sockaddr_ll,
sll_addr)))
goto out;
- ifindex = saddr->sll_ifindex;
+ ifindex = saddr->sll_ifindex ? : po->ifindex;
proto = saddr->sll_protocol;
addr = saddr->sll_addr;
}
@@ -1074,7 +1074,7 @@ static int packet_snd(struct socket *sock,
goto out;
if (msg->msg_namelen < (saddr->sll_halen + offsetof(struct sockaddr_ll, sll_addr)))
goto out;
- ifindex = saddr->sll_ifindex;
+ ifindex = saddr->sll_ifindex ? : po->ifindex;
proto = saddr->sll_protocol;
addr = saddr->sll_addr;
}
--
1.6.6.rc1.43.gf55cc
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/