]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Add concept of a network device index
authorMichael Brown <mcb30@ipxe.org>
Thu, 29 Aug 2013 13:10:16 +0000 (14:10 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 3 Sep 2013 00:24:15 +0000 (01:24 +0100)
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>
src/include/ipxe/netdevice.h
src/net/netdevice.c

index d0e628a430d42c72e2a3abf3b6463f8d60cafd63..7288ad86dc554aa5b00c9a416c29180185aea548 100644 (file)
@@ -300,6 +300,8 @@ struct net_device {
        struct list_head list;
        /** List of open network devices */
        struct list_head open_list;
+       /** Index of this network device */
+       unsigned int index;
        /** Name of this network device */
        char name[12];
        /** Underlying hardware device */
index 5af9c6dc8b6d297a4b791a15174208e53f4074d9..283632f62f3465b219aa2bfadd1df0ff013050df 100644 (file)
@@ -498,10 +498,11 @@ int register_netdev ( struct net_device *netdev ) {
        uint32_t seed;
        int rc;
 
-       /* Create device name */
+       /* Record device index and create device name */
+       netdev->index = ifindex++;
        if ( netdev->name[0] == '\0' ) {
                snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
-                          ifindex++ );
+                          netdev->index );
        }
 
        /* Set initial link-layer address, if not already set */