Procházet zdrojové kódy

[netdevice] Allow driver to preinitialise the link-layer address

Drivers are currently expected to initialise only the hardware
address, with the link-layer protocol code taking care of converting
this into a valid link-layer address.  Some drivers (e.g. undinet) can
legitimately determine both the hardware and link-layer addresses,
which may differ.

Allow for this situation by checking to see if the link-layer address
is empty before initialising it from the hardware address.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown před 13 roky
rodič
revize
4f4369064b
1 změnil soubory, kde provedl 22 přidání a 2 odebrání
  1. 22
    2
      src/net/netdevice.c

+ 22
- 2
src/net/netdevice.c Zobrazit soubor

@@ -62,6 +62,23 @@ struct errortab netdev_errors[] __errortab = {
62 62
 	__einfo_errortab ( EINFO_ENOTCONN_LINK_DOWN ),
63 63
 };
64 64
 
65
+/**
66
+ * Check whether or not network device has a link-layer address
67
+ *
68
+ * @v netdev		Network device
69
+ * @ret has_ll_addr	Network device has a link-layer address
70
+ */
71
+static int netdev_has_ll_addr ( struct net_device *netdev ) {
72
+	uint8_t *ll_addr = netdev->ll_addr;
73
+	size_t remaining = sizeof ( netdev->ll_addr );
74
+
75
+	while ( remaining-- ) {
76
+		if ( *(ll_addr++) != 0 )
77
+			return 1;
78
+	}
79
+	return 0;
80
+}
81
+
65 82
 /**
66 83
  * Notify drivers of network device or link state change
67 84
  *
@@ -432,8 +449,11 @@ int register_netdev ( struct net_device *netdev ) {
432 449
 			   ifindex++ );
433 450
 	}
434 451
 
435
-	/* Set initial link-layer address */
436
-	netdev->ll_protocol->init_addr ( netdev->hw_addr, netdev->ll_addr );
452
+	/* Set initial link-layer address, if not already set */
453
+	if ( ! netdev_has_ll_addr ( netdev ) ) {
454
+		netdev->ll_protocol->init_addr ( netdev->hw_addr,
455
+						 netdev->ll_addr );
456
+	}
437 457
 
438 458
 	/* Add to device list */
439 459
 	netdev_get ( netdev );

Načítá se…
Zrušit
Uložit