From mboxrd@z Thu Jan 1 00:00:00 1970 From: Atzm Watanabe Subject: [PATCH] packet: Deliver VLAN TPID to userspace Date: Sat, 19 Oct 2013 02:08:11 +0900 Message-ID: <87a9i6jymc.wl%atzm@stratosphere.co.jp> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII To: netdev@vger.kernel.org Return-path: Received: from mail-pd0-f174.google.com ([209.85.192.174]:57588 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754804Ab3JRRHt (ORCPT ); Fri, 18 Oct 2013 13:07:49 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so5027319pdi.19 for ; Fri, 18 Oct 2013 10:07:49 -0700 (PDT) Received: from sayva.stratosphere.co.jp ([2001:240:2001:2901:ea40:f2ff:fe10:9f2a]) by mx.google.com with ESMTPSA id hz10sm3513076pbc.36.2013.10.18.10.07.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Oct 2013 10:07:48 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: After the 802.1AD support, userspace packet receivers (packet dumper, software switch, and the like) need how to know VLAN TPID in order to reassemble original tagged frame. Signed-off-by: Atzm Watanabe --- include/uapi/linux/if_packet.h | 5 +++-- net/packet/af_packet.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/if_packet.h b/include/uapi/linux/if_packet.h index dbf0666..6e36e0a 100644 --- a/include/uapi/linux/if_packet.h +++ b/include/uapi/linux/if_packet.h @@ -83,7 +83,7 @@ struct tpacket_auxdata { __u16 tp_mac; __u16 tp_net; __u16 tp_vlan_tci; - __u16 tp_padding; + __u16 tp_vlan_tpid; }; /* Rx ring - header status */ @@ -132,12 +132,13 @@ struct tpacket2_hdr { __u32 tp_sec; __u32 tp_nsec; __u16 tp_vlan_tci; - __u16 tp_padding; + __u16 tp_vlan_tpid; }; struct tpacket_hdr_variant1 { __u32 tp_rxhash; __u32 tp_vlan_tci; + __u32 tp_vlan_tpid; }; struct tpacket3_hdr { diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 2e8286b..fbcc882 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -895,9 +895,11 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc, { if (vlan_tx_tag_present(pkc->skb)) { ppd->hv1.tp_vlan_tci = vlan_tx_tag_get(pkc->skb); + ppd->hv1.tp_vlan_tpid = (__force __u32)ntohs(pkc->skb->vlan_proto); ppd->tp_status = TP_STATUS_VLAN_VALID; } else { ppd->hv1.tp_vlan_tci = 0; + ppd->hv1.tp_vlan_tpid = 0; ppd->tp_status = TP_STATUS_AVAILABLE; } } @@ -1836,11 +1838,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, h.h2->tp_nsec = ts.tv_nsec; if (vlan_tx_tag_present(skb)) { h.h2->tp_vlan_tci = vlan_tx_tag_get(skb); + h.h2->tp_vlan_tpid = ntohs(skb->vlan_proto); status |= TP_STATUS_VLAN_VALID; } else { h.h2->tp_vlan_tci = 0; + h.h2->tp_vlan_tpid = 0; } - h.h2->tp_padding = 0; hdrlen = sizeof(*h.h2); break; case TPACKET_V3: @@ -2788,11 +2791,12 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock, aux.tp_net = skb_network_offset(skb); if (vlan_tx_tag_present(skb)) { aux.tp_vlan_tci = vlan_tx_tag_get(skb); + aux.tp_vlan_tpid = ntohs(skb->vlan_proto); aux.tp_status |= TP_STATUS_VLAN_VALID; } else { aux.tp_vlan_tci = 0; + aux.tp_vlan_tpid = 0; } - aux.tp_padding = 0; put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux); } -- 1.8.1.5