add vlan detection on RTNET receive path
PATCH 1/1 add vlan detection on RTNET receive path
This patch allows classifying the frame in the right protocol (skb->protocol) when receiving an ethernet frame with a VLAN tag.
This allows to make raw PF_PACKET sockets be transparent to VLAN tagging when filtering on ethertype.
| MAC Dest @ | MAC Src @ | EtherType | VLAN TPID | VLAN TCI | Payload | | 11:22:33:44:55:66 | FF:FF:FF:FF:FF:FF | 8100 | 0806 | 201B | ... |
With this patch and CONFIG_VLAN_8021Q set in kconfig, the packet above will be classified as ARP (skb->protocol = 0806)
The behaviour here is somewhat different from upstream as we dont strip the tag from the frame (for performance reason) as upstream does it and return the VLAN information as out of band (with recvmsg).
--
kernel/drivers/net/stack/eth.c +14 -1
@@ -23,6 +23,9 @@#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> +#ifdef CONFIG_VLAN_8021Q +#include <linux/if_vlan.h> +#endif #include <rtdev.h> #include <rtnet_internal.h>
@@ -107,8 +110,18 @@ skb->pkt_type =PACKET_OTHERHOST ; } -if (ntohs (eth->h_proto) >=1536 ) +if (ntohs (eth->h_proto) >=1536 ) { +#ifdef CONFIG_VLAN_8021Q +if (eth->h_proto ==htons (ETH_P_8021Q )) { +struct vlan_hdr * vlan = (struct vlan_hdr *) (skb->data); +return vlan->h_vlan_encapsulated_proto; + }else { +return eth->h_proto; + } +#else return eth->h_proto; +#endif + } rawp = skb->data;
Quoted 8 lines · François Legal
This patch allows classifying the frame in the right protocol (
skb->protocol) when receiving an ethernet frame with a VLAN tag.This allows to make raw
PF_PACKETsockets be transparent to VLAN tagging when filtering on ethertype.| MAC Dest @ | MAC Src @ | EtherType | VLAN TPID | VLAN TCI | Payload | | 11:22:33:44:55:66 | FF:FF:FF:FF:FF:FF | 8100 | 0806 | 201B | ... |With this patch and
CONFIG_VLAN_8021Qset in kconfig, the packet above will be classified as ARP (skb->protocol= 0806)
We generally avoided to bind RTnet settings to regular network stack configs, just to control them independently and avoid surprises on the RTnet side when changing something on the Linux part.
Quoted 3 lines
The behaviour here is somewhat different from upstream as we dont strip the tag from the frame (for performance reason) as upstream does it and return the VLAN information as out of band (with recvmsg).
So, what is the envisioned use case with RTnet? How does the RX-side handling help when not doing anything special for TX? We should document that as well.
Jan
Quoted 37 lines
Signed-off-by François LEGAL <[email protected]>--
kernel/drivers/net/stack/eth.c +14
-1@@ -23,6 +23,9 @@#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> +#ifdef CONFIG_VLAN_8021Q +#include <linux/if_vlan.h> +#endif #include <rtdev.h> #include <rtnet_internal.h> @@ -107,8 +110,18 @@ skb->pkt_type =PACKET_OTHERHOST ; } -if (ntohs (eth->h_proto) >=1536 ) +if (ntohs (eth->h_proto) >=1536 ) { +#ifdef CONFIG_VLAN_8021Q +if (eth->h_proto ==htons (ETH_P_8021Q )) { +struct vlan_hdr * vlan = (struct vlan_hdr *) (skb->data); +return vlan->h_vlan_encapsulated_proto; + }else { +return eth->h_proto; + } +#else return eth->h_proto; +#endif + } rawp = skb->data;
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · François Legal
This patch allows classifying the frame in the right protocol (
skb->protocol) when receiving an ethernet frame with a VLAN tag.This allows to make raw
PF_PACKETsockets be transparent to VLAN tagging when filtering on ethertype.
Quoted 9 lines
Quoted 4 lines
| MAC Dest @ | MAC Src @ | EtherType | VLAN TPID | VLAN TCI | Payload | | 11:22:33:44:55:66 | FF:FF:FF:FF:FF:FF | 8100 | 0806 | 201B | ... |With this patch and
CONFIG_VLAN_8021Qset in kconfig, the packet above will be classified as ARP (skb->protocol= 0806)We generally avoided to bind RTnet settings to regular network stack configs, just to control them independently and avoid surprises on the RTnet side when changing something on the Linux part.
Ok. I'll submit a new version of the patch
Quoted 8 lines
Quoted 3 lines
The behaviour here is somewhat different from upstream as we dont strip the tag from the frame (for performance reason) as upstream does it and return the VLAN information as out of band (with recvmsg).
So, what is the envisioned use case with RTnet? How does the RX-side handling help when not doing anything special for TX? We should document that as well.
I use it in a data recorder app, where I want to capture some ethertype traffic wether or not this ethertype is in a specific vlan or not.
François
Quoted 43 lines
Jan
Quoted 27 lines
Signed-off-by François LEGAL <[email protected]>--
kernel/drivers/net/stack/eth.c +8
-1@@ -23,6 +23,9 @@#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> +#ifdef CONFIG_VLAN_8021Q +#include <linux/if_vlan.h> +#endif #include <rtdev.h> #include <rtnet_internal.h> @@ -107,8 +110,18 @@ skb->pkt_type =PACKET_OTHERHOST ; } -if (ntohs (eth->h_proto) >=1536 ) +if (ntohs (eth->h_proto) >=1536 ) { +#ifdef CONFIG_VLAN_8021Q +if (eth->h_proto ==htons (ETH_P_8021Q )) { +struct vlan_hdr * vlan = (struct vlan_hdr *) (skb->data); +return vlan->h_vlan_encapsulated_proto;kernel/drivers/net/stack/eth.c line 127
Quoted 10 lines
kernel/drivers/net/stack/eth.c +6
-0+ } else { +return eth->h_proto; + } +#else return eth->h_proto; +#endif + } rawp = skb->data;--
Siemens AG, Foundational Technologies
Linux Expert Center