Преглед изворни кода

[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 година
родитељ
комит
d5f69e9388
2 измењених фајлова са 5 додато и 2 уклоњено
  1. 2
    0
      src/include/ipxe/netdevice.h
  2. 3
    2
      src/net/netdevice.c

+ 2
- 0
src/include/ipxe/netdevice.h Прегледај датотеку

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

+ 3
- 2
src/net/netdevice.c Прегледај датотеку

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

Loading…
Откажи
Сачувај