]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[ipv6] Treat a missing network device name as "netX"
authorMichael Brown <mcb30@ipxe.org>
Tue, 28 Jul 2015 12:00:15 +0000 (13:00 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 28 Jul 2015 12:48:23 +0000 (13:48 +0100)
When an IPv6 socket address string specifies a link-local or multicast
address but does not specify the requisite network device name
(e.g. "fe80::69ff:fe50:5845" rather than "fe80::69ff:fe50:5845%net0"),
assume the use of "netX".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/in.h
src/net/ipv6.c

index 75f23123d8cdeeec9499add3a1df5f64c41b3b57..b29c2d74a9a724fd3faf6fbb124450d12f083d60 100644 (file)
@@ -63,6 +63,9 @@ struct in6_addr {
        ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
          htons ( 0xfe80 ) )
 
+#define IN6_IS_ADDR_NONGLOBAL( addr )                                  \
+       ( IN6_IS_ADDR_LINKLOCAL (addr) || IN6_IS_ADDR_MULTICAST (addr) )
+
 /**
  * IPv4 socket address
  */
index c5bead1c63d9d50e330683256cfdbbdc49579d91..a75e72ddba2541ce38b42c3e3a59c6b3f5383b91 100644 (file)
@@ -290,8 +290,7 @@ static struct ipv6_miniroute * ipv6_route ( unsigned int scope_id,
                if ( ! ( miniroute->flags & IPV6_HAS_ADDRESS ) )
                        continue;
 
-               if ( IN6_IS_ADDR_LINKLOCAL ( *dest ) ||
-                    IN6_IS_ADDR_MULTICAST ( *dest ) ) {
+               if ( IN6_IS_ADDR_NONGLOBAL ( *dest ) ) {
 
                        /* If destination is non-global, and the scope ID
                         * matches this network device, then use this route.
@@ -901,7 +900,7 @@ static const char * ipv6_sock_ntoa ( struct sockaddr *sa ) {
        const char *netdev_name;
 
        /* Identify network device, if applicable */
-       if ( IN6_IS_ADDR_LINKLOCAL ( in ) || IN6_IS_ADDR_MULTICAST ( in ) ) {
+       if ( IN6_IS_ADDR_NONGLOBAL ( in ) ) {
                netdev = find_netdev_by_index ( sin6->sin6_scope_id );
                netdev_name = ( netdev ? netdev->name : "UNKNOWN" );
        } else {
@@ -956,14 +955,26 @@ static int ipv6_sock_aton ( const char *string, struct sockaddr *sa ) {
        if ( ( rc = inet6_aton ( in_string, &in ) ) != 0 )
                goto err_inet6_aton;
 
-       /* Parse network device name, if present */
+       /* Parse scope ID, if applicable */
        if ( netdev_string ) {
+
+               /* Parse explicit network device name, if present */
                netdev = find_netdev ( netdev_string );
                if ( ! netdev ) {
                        rc = -ENODEV;
                        goto err_find_netdev;
                }
                sin6->sin6_scope_id = netdev->index;
+
+       } else if ( IN6_IS_ADDR_NONGLOBAL ( &in ) ) {
+
+               /* If no network device is explicitly specified for a
+                * link-local or multicast address, default to using
+                * "netX" (if existent).
+                */
+               netdev = last_opened_netdev();
+               if ( netdev )
+                       sin6->sin6_scope_id = netdev->index;
        }
 
        /* Copy IPv6 address portion to socket address */