Browse Source

[vlan] Provide vlan_can_be_trunk()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
b4706c88c9
2 changed files with 24 additions and 8 deletions
  1. 1
    0
      src/include/ipxe/vlan.h
  2. 23
    8
      src/net/vlan.c

+ 1
- 0
src/include/ipxe/vlan.h View File

59
  */
59
  */
60
 #define VLAN_PRIORITY_IS_VALID( priority ) ( (priority) <= 7 )
60
 #define VLAN_PRIORITY_IS_VALID( priority ) ( (priority) <= 7 )
61
 
61
 
62
+extern int vlan_can_be_trunk ( struct net_device *trunk );
62
 extern int vlan_create ( struct net_device *trunk, unsigned int tag,
63
 extern int vlan_create ( struct net_device *trunk, unsigned int tag,
63
 			 unsigned int priority );
64
 			 unsigned int priority );
64
 extern int vlan_destroy ( struct net_device *netdev );
65
 extern int vlan_destroy ( struct net_device *netdev );

+ 23
- 8
src/net/vlan.c View File

280
 };
280
 };
281
 
281
 
282
 /**
282
 /**
283
- * Create VLAN device
283
+ * Check if network device can be used as a VLAN trunk device
284
  *
284
  *
285
  * @v trunk		Trunk network device
285
  * @v trunk		Trunk network device
286
- * @v tag		VLAN tag
287
- * @v priority		Default VLAN priority
288
- * @ret rc		Return status code
286
+ * @ret is_ok		Trunk network device is usable
289
  *
287
  *
290
- * The VLAN device will be created as an Ethernet device.  (We cannot
288
+ * VLAN devices will be created as Ethernet devices.  (We cannot
291
  * simply clone the link layer of the trunk network device, because
289
  * simply clone the link layer of the trunk network device, because
292
  * this link layer may expect the network device structure to contain
290
  * this link layer may expect the network device structure to contain
293
  * some link-layer-private data.)  The trunk network device must
291
  * some link-layer-private data.)  The trunk network device must
294
  * therefore have a link layer that is in some sense 'compatible' with
292
  * therefore have a link layer that is in some sense 'compatible' with
295
  * Ethernet; specifically, it must have link-layer addresses that are
293
  * Ethernet; specifically, it must have link-layer addresses that are
296
  * the same length as Ethernet link-layer addresses.
294
  * the same length as Ethernet link-layer addresses.
295
+ *
296
+ * As an additional check, and primarily to assist with the sanity of
297
+ * the FCoE code, we refuse to allow nested VLANs.
298
+ */
299
+int vlan_can_be_trunk ( struct net_device *trunk ) {
300
+
301
+	return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
302
+		 ( trunk->op != &vlan_operations ) );
303
+}
304
+
305
+/**
306
+ * Create VLAN device
307
+ *
308
+ * @v trunk		Trunk network device
309
+ * @v tag		VLAN tag
310
+ * @v priority		Default VLAN priority
311
+ * @ret rc		Return status code
297
  */
312
  */
298
 int vlan_create ( struct net_device *trunk, unsigned int tag,
313
 int vlan_create ( struct net_device *trunk, unsigned int tag,
299
 		  unsigned int priority ) {
314
 		  unsigned int priority ) {
313
 	}
328
 	}
314
 
329
 
315
 	/* Sanity checks */
330
 	/* Sanity checks */
316
-	if ( trunk->ll_protocol->ll_addr_len != ETH_ALEN ) {
317
-		DBGC ( trunk, "VLAN %s cannot create VLAN for %s device\n",
318
-		       trunk->name, trunk->ll_protocol->name );
331
+	if ( ! vlan_can_be_trunk ( trunk ) ) {
332
+		DBGC ( trunk, "VLAN %s cannot create VLAN on non-trunk "
333
+		       "device\n", trunk->name );
319
 		rc = -ENOTTY;
334
 		rc = -ENOTTY;
320
 		goto err_sanity;
335
 		goto err_sanity;
321
 	}
336
 	}

Loading…
Cancel
Save