Skip to content

Commit a3bcc23

Browse files
greearbdavem330
authored andcommitted
af-packet: Add flag to distinguish VID 0 from no-vlan.
Currently, user-space cannot determine if a 0 tcp_vlan_tci means there is no VLAN tag or the VLAN ID was zero. Add flag to make this explicit. User-space can check for TP_STATUS_VLAN_VALID || tp_vlan_tci > 0, which will be backwards compatible. Older could would have just checked for tp_vlan_tci, so it will work no worse than before. Signed-off-by: Ben Greear <greearb@candelatech.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 41be5a4 commit a3bcc23

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/linux/if_packet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct tpacket_auxdata {
7070
#define TP_STATUS_COPY 0x2
7171
#define TP_STATUS_LOSING 0x4
7272
#define TP_STATUS_CSUMNOTREADY 0x8
73+
#define TP_STATUS_VLAN_VALID 0x10 /* auxdata has valid tp_vlan_tci */
7374

7475
/* Tx ring - header status */
7576
#define TP_STATUS_AVAILABLE 0x0

net/packet/af_packet.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
798798
getnstimeofday(&ts);
799799
h.h2->tp_sec = ts.tv_sec;
800800
h.h2->tp_nsec = ts.tv_nsec;
801-
h.h2->tp_vlan_tci = vlan_tx_tag_get(skb);
801+
if (vlan_tx_tag_present(skb)) {
802+
h.h2->tp_vlan_tci = vlan_tx_tag_get(skb);
803+
status |= TP_STATUS_VLAN_VALID;
804+
} else {
805+
h.h2->tp_vlan_tci = 0;
806+
}
802807
hdrlen = sizeof(*h.h2);
803808
break;
804809
default:
@@ -1725,8 +1730,12 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
17251730
aux.tp_snaplen = skb->len;
17261731
aux.tp_mac = 0;
17271732
aux.tp_net = skb_network_offset(skb);
1728-
aux.tp_vlan_tci = vlan_tx_tag_get(skb);
1729-
1733+
if (vlan_tx_tag_present(skb)) {
1734+
aux.tp_vlan_tci = vlan_tx_tag_get(skb);
1735+
aux.tp_status |= TP_STATUS_VLAN_VALID;
1736+
} else {
1737+
aux.tp_vlan_tci = 0;
1738+
}
17301739
put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
17311740
}
17321741

0 commit comments

Comments
 (0)