[ipxe-devel] [PATCH 1/2] [vlan] Move vlan_protocol to a separate file

Ladi Prosek lprosek at redhat.com
Fri Apr 15 16:19:47 UTC 2016


This commit splits VLAN functionality into protocol / inbound in
vlan_protocol.c and driver / outbound in vlan.c to make adding
support for VLAN 0 priority tagging easier.

Signed-off-by: Ladi Prosek <lprosek at redhat.com>
---
 src/include/ipxe/errfile.h |   1 +
 src/net/vlan.c             |  76 ++----------------------------
 src/net/vlan_protocol.c    | 114 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 73 deletions(-)
 create mode 100644 src/net/vlan_protocol.c

diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h
index 338ebdd..d51467c 100644
--- a/src/include/ipxe/errfile.h
+++ b/src/include/ipxe/errfile.h
@@ -262,6 +262,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define ERRFILE_peerblk			( ERRFILE_NET | 0x00460000 )
 #define ERRFILE_peermux			( ERRFILE_NET | 0x00470000 )
 #define ERRFILE_xsigo			( ERRFILE_NET | 0x00480000 )
+#define ERRFILE_vlan_protocol		( ERRFILE_NET | 0x00490000 )
 
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )
diff --git a/src/net/vlan.c b/src/net/vlan.c
index f515c2d..cc9bb51 100644
--- a/src/net/vlan.c
+++ b/src/net/vlan.c
@@ -214,79 +214,6 @@ struct net_device * vlan_find ( struct net_device *trunk, unsigned int tag ) {
 }
 
 /**
- * Process incoming VLAN packet
- *
- * @v iobuf		I/O buffer
- * @v trunk		Trunk network device
- * @v ll_dest		Link-layer destination address
- * @v ll_source		Link-layer source address
- * @v flags		Packet flags
- * @ret rc		Return status code
- */
-static int vlan_rx ( struct io_buffer *iobuf, struct net_device *trunk,
-		     const void *ll_dest, const void *ll_source,
-		     unsigned int flags __unused ) {
-	struct vlan_header *vlanhdr = iobuf->data;
-	struct net_device *netdev;
-	struct ll_protocol *ll_protocol;
-	uint8_t ll_dest_copy[ETH_ALEN];
-	uint8_t ll_source_copy[ETH_ALEN];
-	uint16_t tag;
-	int rc;
-
-	/* Sanity check */
-	if ( iob_len ( iobuf ) < sizeof ( *vlanhdr ) ) {
-		DBGC ( trunk, "VLAN %s received underlength packet (%zd "
-		       "bytes)\n", trunk->name, iob_len ( iobuf ) );
-		rc = -EINVAL;
-		goto err_sanity;
-	}
-
-	/* Identify VLAN device */
-	tag = VLAN_TAG ( ntohs ( vlanhdr->tci ) );
-	netdev = vlan_find ( trunk, tag );
-	if ( ! netdev ) {
-		DBGC2 ( trunk, "VLAN %s received packet for unknown VLAN "
-			"%d\n", trunk->name, tag );
-		rc = -EPIPE;
-		goto err_no_vlan;
-	}
-
-	/* Strip VLAN header and preserve original link-layer header fields */
-	iob_pull ( iobuf, sizeof ( *vlanhdr ) );
-	ll_protocol = trunk->ll_protocol;
-	memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
-	memcpy ( ll_source_copy, ll_source, ETH_ALEN );
-
-	/* Reconstruct link-layer header for VLAN device */
-	ll_protocol = netdev->ll_protocol;
-	if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest_copy,
-					ll_source_copy,
-					vlanhdr->net_proto ) ) != 0 ) {
-		DBGC ( netdev, "VLAN %s could not reconstruct link-layer "
-		       "header: %s\n", netdev->name, strerror ( rc ) );
-		goto err_ll_push;
-	}
-
-	/* Enqueue packet on VLAN device */
-	netdev_rx ( netdev, iob_disown ( iobuf ) );
-	return 0;
-
- err_ll_push:
- err_no_vlan:
- err_sanity:
-	free_iob ( iobuf );
-	return rc;
-}
-
-/** VLAN protocol */
-struct net_protocol vlan_protocol __net_protocol = {
-	.name = "VLAN",
-	.net_proto = htons ( ETH_P_8021Q ),
-	.rx = vlan_rx,
-};
-
-/**
  * Get the VLAN tag
  *
  * @v netdev		Network device
@@ -506,3 +433,6 @@ struct net_driver vlan_driver __net_driver = {
 	.notify = vlan_notify,
 	.remove = vlan_remove,
 };
+
+REQUIRING_SYMBOL ( vlan_driver );
+REQUIRE_OBJECT ( vlan_protocol );
diff --git a/src/net/vlan_protocol.c b/src/net/vlan_protocol.c
new file mode 100644
index 0000000..3b41cee
--- /dev/null
+++ b/src/net/vlan_protocol.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2010 Michael Brown <mbrown at fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <byteswap.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/ethernet.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/iobuf.h>
+#include <ipxe/vlan.h>
+
+/** @file
+ *
+ * Virtual LAN net protocol
+ *
+ */
+
+/**
+ * Process incoming VLAN packet
+ *
+ * @v iobuf		I/O buffer
+ * @v trunk		Trunk network device
+ * @v ll_dest		Link-layer destination address
+ * @v ll_source		Link-layer source address
+ * @v flags		Packet flags
+ * @ret rc		Return status code
+ */
+static int vlan_rx ( struct io_buffer *iobuf, struct net_device *trunk,
+		     const void *ll_dest, const void *ll_source,
+		     unsigned int flags __unused ) {
+	struct vlan_header *vlanhdr = iobuf->data;
+	struct net_device *netdev;
+	struct ll_protocol *ll_protocol;
+	uint8_t ll_dest_copy[ETH_ALEN];
+	uint8_t ll_source_copy[ETH_ALEN];
+	uint16_t tag;
+	int rc;
+
+	/* Sanity check */
+	if ( iob_len ( iobuf ) < sizeof ( *vlanhdr ) ) {
+		DBGC ( trunk, "VLAN %s received underlength packet (%zd "
+		       "bytes)\n", trunk->name, iob_len ( iobuf ) );
+		rc = -EINVAL;
+		goto err_sanity;
+	}
+
+	/* Identify VLAN device */
+	tag = VLAN_TAG ( ntohs ( vlanhdr->tci ) );
+	netdev = vlan_find ( trunk, tag );
+	if ( ! netdev ) {
+		DBGC2 ( trunk, "VLAN %s received packet for unknown VLAN "
+			"%d\n", trunk->name, tag );
+		rc = -EPIPE;
+		goto err_no_vlan;
+	}
+
+	/* Strip VLAN header and preserve original link-layer header fields */
+	iob_pull ( iobuf, sizeof ( *vlanhdr ) );
+	ll_protocol = trunk->ll_protocol;
+	memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
+	memcpy ( ll_source_copy, ll_source, ETH_ALEN );
+
+	/* Reconstruct link-layer header for VLAN device */
+	ll_protocol = netdev->ll_protocol;
+	if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest_copy,
+					ll_source_copy,
+					vlanhdr->net_proto ) ) != 0 ) {
+		DBGC ( netdev, "VLAN %s could not reconstruct link-layer "
+		       "header: %s\n", netdev->name, strerror ( rc ) );
+		goto err_ll_push;
+	}
+
+	/* Enqueue packet on VLAN device */
+	netdev_rx ( netdev, iob_disown ( iobuf ) );
+	return 0;
+
+ err_ll_push:
+ err_no_vlan:
+ err_sanity:
+	free_iob ( iobuf );
+	return rc;
+}
+
+/** VLAN protocol */
+struct net_protocol vlan_protocol __net_protocol = {
+	.name = "VLAN",
+	.net_proto = htons ( ETH_P_8021Q ),
+	.rx = vlan_rx,
+};
-- 
2.5.5




More information about the ipxe-devel mailing list