Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
mcb30 committed Oct 28, 2011
1 parent b0d65b5 commit 4f43690
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/net/netdevice.c
Expand Up @@ -62,6 +62,23 @@ struct errortab netdev_errors[] __errortab = {
__einfo_errortab ( EINFO_ENOTCONN_LINK_DOWN ),
};

/**
* Check whether or not network device has a link-layer address
*
* @v netdev Network device
* @ret has_ll_addr Network device has a link-layer address
*/
static int netdev_has_ll_addr ( struct net_device *netdev ) {
uint8_t *ll_addr = netdev->ll_addr;
size_t remaining = sizeof ( netdev->ll_addr );

while ( remaining-- ) {
if ( *(ll_addr++) != 0 )
return 1;
}
return 0;
}

/**
* Notify drivers of network device or link state change
*
Expand Down Expand Up @@ -432,8 +449,11 @@ int register_netdev ( struct net_device *netdev ) {
ifindex++ );
}

/* Set initial link-layer address */
netdev->ll_protocol->init_addr ( netdev->hw_addr, netdev->ll_addr );
/* Set initial link-layer address, if not already set */
if ( ! netdev_has_ll_addr ( netdev ) ) {
netdev->ll_protocol->init_addr ( netdev->hw_addr,
netdev->ll_addr );
}

/* Add to device list */
netdev_get ( netdev );
Expand Down

0 comments on commit 4f43690

Please sign in to comment.