Blame 0003-Strip-802.1Q-VLAN-0-priority-tags.patch

5929173
From 1a921ececb22bbc41d1fda34576564e84d124a83 Mon Sep 17 00:00:00 2001
5929173
From: Ladi Prosek <lprosek@redhat.com>
5929173
Date: Mon, 11 Jul 2016 14:17:36 +0200
5929173
Subject: Strip 802.1Q VLAN 0 priority tags
5929173
5929173
RH-Author: Ladi Prosek <lprosek@redhat.com>
5929173
Message-id: <1468246656-15560-1-git-send-email-lprosek@redhat.com>
5929173
Patchwork-id: 71112
5929173
O-Subject: [RHEL7.3 ipxe PATCH] [netdevice] Strip 802.Q VLAN 0 priority tags
5929173
Bugzilla: 1316329
5929173
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
5929173
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
5929173
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
5929173
5929173
iPXE was unable to receive priority tagged packets specified in
5929173
the 802.1Q standard and supported by all major networking stacks.
5929173
5929173
This commit adds a new function net_pull_tags which is called by
5929173
all consumers of incoming packets after stripping their link-layer
5929173
headers.
5929173
5929173
Upstream patch:
5929173
http://lists.ipxe.org/pipermail/ipxe-devel/2016-July/005099.html
5929173
5929173
There is a difference between the upstream patch and this patch in the
5929173
path prefix of "interface/pxe/pxe_undi.c" because we don't have upstream
5929173
commit f468f12b1eca.
5929173
5929173
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
5929173
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5929173
---
5929173
 src/arch/x86/interface/pxe/pxe_undi.c |  6 +++++
5929173
 src/include/ipxe/netdevice.h          |  2 ++
5929173
 src/interface/efi/efi_snp.c           |  7 ++++++
5929173
 src/net/netdevice.c                   | 44 +++++++++++++++++++++++++++++++++++
5929173
 4 files changed, 59 insertions(+)
5929173
5929173
diff --git a/src/arch/x86/interface/pxe/pxe_undi.c b/src/arch/x86/interface/pxe/pxe_undi.c
5929173
index 2eb6817..2ea1451 100644
5929173
--- a/src/arch/x86/interface/pxe/pxe_undi.c
5929173
+++ b/src/arch/x86/interface/pxe/pxe_undi.c
5929173
@@ -976,6 +976,12 @@ static PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
5929173
 		}
5929173
 		ll_hlen = ( len - iob_len ( iobuf ) );
5929173
 
5929173
+		/* Strip link-layer-independent headers */
5929173
+		if ( ( rc = net_pull_tags ( iobuf, pxe_netdev, &net_proto ) ) != 0 ) {
5929173
+			/* Assume unknown net_proto */
5929173
+			net_proto = 0;
5929173
+		}
5929173
+
5929173
 		/* Determine network-layer protocol */
5929173
 		switch ( net_proto ) {
5929173
 		case htons ( ETH_P_IP ):
5929173
diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h
5929173
index a1d207f..cea87f7 100644
5929173
--- a/src/include/ipxe/netdevice.h
5929173
+++ b/src/include/ipxe/netdevice.h
5929173
@@ -719,6 +719,8 @@ extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
5929173
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
5929173
 		    uint16_t net_proto, const void *ll_dest,
5929173
 		    const void *ll_source, unsigned int flags );
5929173
+extern int net_pull_tags ( struct io_buffer *iobuf, struct net_device *netdev,
5929173
+			   uint16_t *net_proto );
5929173
 extern void net_poll ( void );
5929173
 extern struct net_device_configurator *
5929173
 find_netdev_configurator ( const char *name );
5929173
diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c
5929173
index e6388bf..d1a1a44 100644
5929173
--- a/src/interface/efi/efi_snp.c
5929173
+++ b/src/interface/efi/efi_snp.c
5929173
@@ -745,6 +745,13 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
5929173
 		goto out_bad_ll_header;
5929173
 	}
5929173
 
5929173
+	/* Strip link-layer-independent headers */
5929173
+	if ( ( rc = net_pull_tags ( iobuf, snpdev->netdev, &iob_net_proto ) ) ) {
5929173
+		DBGC ( snpdev, "SNPDEV %p could not parse tags: %s\n",
5929173
+		       snpdev, strerror ( rc ) );
5929173
+		goto out_bad_ll_header;
5929173
+	}
5929173
+
5929173
 	/* Return link-layer header parameters to caller, if required */
5929173
 	if ( ll_header_len )
5929173
 		*ll_header_len = ll_protocol->ll_header_len;
5929173
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
5929173
index 9df2119..c53d5e3 100644
5929173
--- a/src/net/netdevice.c
5929173
+++ b/src/net/netdevice.c
5929173
@@ -1028,6 +1028,44 @@ int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
5929173
 }
5929173
 
5929173
 /**
5929173
+ * Strip extra link-layer-independent tags from a received packet
5929173
+ *
5929173
+ * @v iobuf		I/O buffer
5929173
+ * @v netdev		Network device
5929173
+ * @v net_proto		Network-layer protocol, in network-byte order
5929173
+ * @ret rc		Return status code
5929173
+ *
5929173
+ * This function should be called after stripping link-layer headers but
5929173
+ * before inspecting the network-layer protocol.
5929173
+ */
5929173
+int net_pull_tags ( struct io_buffer *iobuf, struct net_device *netdev,
5929173
+		    uint16_t *net_proto ) {
5929173
+	struct vlan_header *vlanhdr;
5929173
+	uint16_t tag;
5929173
+
5929173
+	/* Strip 802.1Q VLAN 0 priority tags if present */
5929173
+	while ( *net_proto == htons ( ETH_P_8021Q ) ) {
5929173
+		if ( iob_len ( iobuf ) < sizeof ( *vlanhdr ) ) {
5929173
+			DBG ( "VLAN header too short at %zd bytes (min %zd bytes)\n",
5929173
+			      iob_len ( iobuf ), sizeof ( *vlanhdr ) );
5929173
+			return -EINVAL;
5929173
+		}
5929173
+		vlanhdr = ( struct vlan_header * ) iobuf->data;
5929173
+		tag = VLAN_TAG ( ntohs ( vlanhdr->tci ) );
5929173
+
5929173
+		if ( tag == 0 && ! vlan_find ( netdev, tag ) ) {
5929173
+			/* VLAN 0, strip and continue */
5929173
+			*net_proto = vlanhdr->net_proto;
5929173
+			iob_pull ( iobuf, sizeof ( *vlanhdr ) );
5929173
+		} else {
5929173
+			/* Real VLAN tag, leave it alone */
5929173
+			break;
5929173
+		}
5929173
+	}
5929173
+	return 0;
5929173
+}
5929173
+
5929173
+/**
5929173
  * Poll the network stack
5929173
  *
5929173
  * This polls all interfaces for received packets, and processes
5929173
@@ -1078,6 +1116,12 @@ void net_poll ( void ) {
5929173
 				continue;
5929173
 			}
5929173
 
5929173
+			/* Remove link-layer-independent headers */
5929173
+			if ( ( rc = net_pull_tags ( iobuf, netdev, &net_proto ) ) ) {
5929173
+				free_iob ( iobuf );
5929173
+				continue;
5929173
+			}
5929173
+
5929173
 			/* Hand packet to network layer */
5929173
 			if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
5929173
 					     net_proto, ll_dest,
5929173
-- 
5929173
1.8.3.1
5929173