Browse Source

[netdevice] Add concept of a network device index

IPv6 link-local socket addresses require some way to specify a local
network device.  We cannot simply use a pointer to the network device,
since a struct sockaddr_in6 may be long-lived and has no way to hold a
reference to the network device.

Using a network device index allows a socket address to cleanly refer
to a network device without worrying about whether or not that device
continues to exist.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
d5f69e9388
2 changed files with 5 additions and 2 deletions
  1. 2
    0
      src/include/ipxe/netdevice.h
  2. 3
    2
      src/net/netdevice.c

+ 2
- 0
src/include/ipxe/netdevice.h View File

300
 	struct list_head list;
300
 	struct list_head list;
301
 	/** List of open network devices */
301
 	/** List of open network devices */
302
 	struct list_head open_list;
302
 	struct list_head open_list;
303
+	/** Index of this network device */
304
+	unsigned int index;
303
 	/** Name of this network device */
305
 	/** Name of this network device */
304
 	char name[12];
306
 	char name[12];
305
 	/** Underlying hardware device */
307
 	/** Underlying hardware device */

+ 3
- 2
src/net/netdevice.c View File

498
 	uint32_t seed;
498
 	uint32_t seed;
499
 	int rc;
499
 	int rc;
500
 
500
 
501
-	/* Create device name */
501
+	/* Record device index and create device name */
502
+	netdev->index = ifindex++;
502
 	if ( netdev->name[0] == '\0' ) {
503
 	if ( netdev->name[0] == '\0' ) {
503
 		snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
504
 		snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
504
-			   ifindex++ );
505
+			   netdev->index );
505
 	}
506
 	}
506
 
507
 
507
 	/* Set initial link-layer address, if not already set */
508
 	/* Set initial link-layer address, if not already set */

Loading…
Cancel
Save