]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Avoid using zero as a network device index
authorMichael Brown <mcb30@ipxe.org>
Tue, 21 Jul 2015 13:51:16 +0000 (14:51 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 28 Jul 2015 12:48:29 +0000 (13:48 +0100)
Avoid using zero as a network device index, so that a zero
sin6_scope_id can be used to mean "unspecified" (rather than
unintentionally meaning "net0").

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/netdevice.c

index 889b00c1a471f048335d7c365ea41b1a6e8ab6d9..7c40a2ac87d247c860efcce21be49fefe6ecb13d 100644 (file)
@@ -676,11 +676,11 @@ int register_netdev ( struct net_device *netdev ) {
        }
 
        /* Record device index and create device name */
-       netdev->index = netdev_index++;
        if ( netdev->name[0] == '\0' ) {
                snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
-                          netdev->index );
+                          netdev_index );
        }
+       netdev->index = ++netdev_index;
 
        /* Use least significant bits of the link-layer address to
         * improve the randomness of the (non-cryptographic) random