netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Neil Horman <nhorman@tuxdriver.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH] net: packet: option to only pass skb protocol
Date: Tue, 5 Jan 2010 20:57:32 +0200	[thread overview]
Message-ID: <20100105185732.GA30346@redhat.com> (raw)

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

             reply	other threads:[~2010-01-05 19:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-05 18:57 Michael S. Tsirkin [this message]
2010-01-05 19:27 ` [PATCH] net: packet: option to only pass skb protocol 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100105185732.GA30346@redhat.com \
    --to=mst@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).