netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: packet: option to only pass skb protocol
@ 2010-01-05 18:57 Michael S. Tsirkin
  2010-01-05 19:27 ` Eric Dumazet
  2010-01-05 21:28 ` Chris Friesen
  0 siblings, 2 replies; 15+ messages in thread
From: Michael S. Tsirkin @ 2010-01-05 18:57 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Neil Horman, linux-kernel, netdev

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@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-01-07  8:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-05 18:57 [PATCH] net: packet: option to only pass skb protocol Michael S. Tsirkin
2010-01-05 19:27 ` Eric Dumazet
2010-01-05 20:50   ` Michael S. Tsirkin
2010-01-05 21:40     ` David Miller
2010-01-05 21:50       ` Michael S. Tsirkin
2010-01-05 21:28 ` Chris Friesen
2010-01-05 21:42   ` David Miller
2010-01-05 21:45     ` Michael S. Tsirkin
2010-01-05 22:05       ` Michael S. Tsirkin
2010-01-05 22:13     ` Chris Friesen
2010-01-05 22:27       ` Michael S. Tsirkin
2010-01-05 23:51       ` David Miller
2010-01-06  9:12         ` Michael S. Tsirkin
2010-01-06 19:24           ` Michael S. Tsirkin
2010-01-07  8:27           ` Michał Mirosław

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).