summaryrefslogtreecommitdiffstats
path: root/src/net/netdevice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/netdevice.c')
-rw-r--r--src/net/netdevice.c68
1 files changed, 19 insertions, 49 deletions
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index 5df306e8d..07961bf20 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -55,9 +55,6 @@ struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
/** List of open network devices, in reverse order of opening */
static struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
-/** Network device index */
-static unsigned int netdev_index = 0;
-
/** Network polling profiler */
static struct profiler net_poll_profiler __profiler = { .name = "net.poll" };
@@ -723,6 +720,7 @@ int register_netdev ( struct net_device *netdev ) {
struct ll_protocol *ll_protocol = netdev->ll_protocol;
struct net_driver *driver;
struct net_device *duplicate;
+ unsigned int i;
uint32_t seed;
int rc;
@@ -737,18 +735,6 @@ int register_netdev ( struct net_device *netdev ) {
ll_protocol->ll_header_len );
}
- /* Reject network devices that are already available via a
- * different hardware device.
- */
- duplicate = find_netdev_by_ll_addr ( ll_protocol, netdev->ll_addr );
- if ( duplicate && ( duplicate->dev != netdev->dev ) ) {
- DBGC ( netdev, "NETDEV rejecting duplicate (phys %s) of %s "
- "(phys %s)\n", netdev->dev->name, duplicate->name,
- duplicate->dev->name );
- rc = -EEXIST;
- goto err_duplicate;
- }
-
/* Reject named network devices that already exist */
if ( netdev->name[0] && ( duplicate = find_netdev ( netdev->name ) ) ) {
DBGC ( netdev, "NETDEV rejecting duplicate name %s\n",
@@ -757,12 +743,21 @@ int register_netdev ( struct net_device *netdev ) {
goto err_duplicate;
}
- /* Record device index and create device name */
+ /* Assign a unique device name, if not already set */
if ( netdev->name[0] == '\0' ) {
- snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
- netdev_index );
+ for ( i = 0 ; ; i++ ) {
+ snprintf ( netdev->name, sizeof ( netdev->name ),
+ "net%d", i );
+ if ( find_netdev ( netdev->name ) == NULL )
+ break;
+ }
+ }
+
+ /* Assign a unique non-zero scope ID */
+ for ( netdev->scope_id = 1 ; ; netdev->scope_id++ ) {
+ if ( find_netdev_by_scope_id ( netdev->scope_id ) == NULL )
+ break;
}
- netdev->index = ++netdev_index;
/* Use least significant bits of the link-layer address to
* improve the randomness of the (non-cryptographic) random
@@ -916,10 +911,6 @@ void unregister_netdev ( struct net_device *netdev ) {
DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
list_del ( &netdev->list );
netdev_put ( netdev );
-
- /* Reset network device index if no devices remain */
- if ( list_empty ( &net_devices ) )
- netdev_index = 0;
}
/** Enable or disable interrupts
@@ -962,17 +953,17 @@ struct net_device * find_netdev ( const char *name ) {
}
/**
- * Get network device by index
+ * Get network device by scope ID
*
* @v index Network device index
* @ret netdev Network device, or NULL
*/
-struct net_device * find_netdev_by_index ( unsigned int index ) {
+struct net_device * find_netdev_by_scope_id ( unsigned int scope_id ) {
struct net_device *netdev;
/* Identify network device by index */
list_for_each_entry ( netdev, &net_devices, list ) {
- if ( netdev->index == index )
+ if ( netdev->scope_id == scope_id )
return netdev;
}
@@ -1000,27 +991,6 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type,
}
/**
- * Get network device by link-layer address
- *
- * @v ll_protocol Link-layer protocol
- * @v ll_addr Link-layer address
- * @ret netdev Network device, or NULL
- */
-struct net_device * find_netdev_by_ll_addr ( struct ll_protocol *ll_protocol,
- const void *ll_addr ) {
- struct net_device *netdev;
-
- list_for_each_entry ( netdev, &net_devices, list ) {
- if ( ( netdev->ll_protocol == ll_protocol ) &&
- ( memcmp ( netdev->ll_addr, ll_addr,
- ll_protocol->ll_addr_len ) == 0 ) )
- return netdev;
- }
-
- return NULL;
-}
-
-/**
* Get most recently opened network device
*
* @ret netdev Most recently opened network device, or NULL
@@ -1171,12 +1141,12 @@ static void net_step ( struct process *process __unused ) {
}
/**
- * Get the VLAN tag (when VLAN support is not present)
+ * Get the VLAN tag control information (when VLAN support is not present)
*
* @v netdev Network device
* @ret tag 0, indicating that device is not a VLAN device
*/
-__weak unsigned int vlan_tag ( struct net_device *netdev __unused ) {
+__weak unsigned int vlan_tci ( struct net_device *netdev __unused ) {
return 0;
}