From: "Jan Grashöfer" <jan.grashoefer@gmail.com>
To: netdev@vger.kernel.org
Cc: aeppert@gmail.com
Subject: Receiving raw packets (incl. VLAN tags) on raw sockets
Date: Wed, 14 Jun 2017 14:47:56 +0200 [thread overview]
Message-ID: <e06dbb47-2d1c-03ca-4cd7-cc958b6a939e@gmail.com> (raw)
Hello,
trying to ingest packets to a network monitoring tool using AF_Packet, I
noticed that VLAN tags are stripped off even if VLAN offloading is
disabled. As described in [1] the tags are stripped that early in the
receive path that raw sockets do not receive the packets as seen on the
wire. However, the man pages [2] state:
> SOCK_RAW packets are passed to and from the device driver without any
> changes in the packet data.
So at least the docs are wrong here. While the VLAN information is
present in the tpacket_hdr, the packets themselves are manipulated by
the kernel. In my case, for example, I need to pass on each packet (in
form of a packet) and thus would have to reinsert the tag manually,
which is definitely undesirable.
As I am dealing with a monitoring application, the following patch that
disables untagging VLANs in promisc mode fixes the issue for me:
diff --git a/net/core/dev.c b/net/core/dev.c
index 54f8c16..ec5b1c5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4104,8 +4104,9 @@ static int __netif_receive_skb_core(struct sk_buff
*skb, bool pfmemalloc)
__this_cpu_inc(softnet_data.processed);
- if (skb->protocol == cpu_to_be16(ETH_P_8021Q) ||
- skb->protocol == cpu_to_be16(ETH_P_8021AD)) {
+ if ((skb->protocol == cpu_to_be16(ETH_P_8021Q) ||
+ skb->protocol == cpu_to_be16(ETH_P_8021AD)) &&
+ skb->dev->promiscuity < 1) {
skb = skb_vlan_untag(skb);
if (unlikely(!skb))
goto out;
next reply other threads:[~2017-06-14 12:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-14 12:47 Jan Grashöfer [this message]
2017-06-14 14:41 ` Receiving raw packets (incl. VLAN tags) on raw sockets Eric W. Biederman
2017-06-14 16:03 ` Jan Grashöfer
2017-06-14 16:54 ` Eric W. Biederman
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=e06dbb47-2d1c-03ca-4cd7-cc958b6a939e@gmail.com \
--to=jan.grashoefer@gmail.com \
--cc=aeppert@gmail.com \
--cc=netdev@vger.kernel.org \
/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).