Browse Source

[ipv6] Treat a missing network device name as "netX"

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>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
41670ca2fe
2 changed files with 18 additions and 4 deletions
  1. 3
    0
      src/include/ipxe/in.h
  2. 15
    4
      src/net/ipv6.c

+ 3
- 0
src/include/ipxe/in.h View File

63
 	( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==	\
63
 	( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==	\
64
 	  htons ( 0xfe80 ) )
64
 	  htons ( 0xfe80 ) )
65
 
65
 
66
+#define IN6_IS_ADDR_NONGLOBAL( addr )					\
67
+	( IN6_IS_ADDR_LINKLOCAL (addr) || IN6_IS_ADDR_MULTICAST (addr) )
68
+
66
 /**
69
 /**
67
  * IPv4 socket address
70
  * IPv4 socket address
68
  */
71
  */

+ 15
- 4
src/net/ipv6.c View File

290
 		if ( ! ( miniroute->flags & IPV6_HAS_ADDRESS ) )
290
 		if ( ! ( miniroute->flags & IPV6_HAS_ADDRESS ) )
291
 			continue;
291
 			continue;
292
 
292
 
293
-		if ( IN6_IS_ADDR_LINKLOCAL ( *dest ) ||
294
-		     IN6_IS_ADDR_MULTICAST ( *dest ) ) {
293
+		if ( IN6_IS_ADDR_NONGLOBAL ( *dest ) ) {
295
 
294
 
296
 			/* If destination is non-global, and the scope ID
295
 			/* If destination is non-global, and the scope ID
297
 			 * matches this network device, then use this route.
296
 			 * matches this network device, then use this route.
901
 	const char *netdev_name;
900
 	const char *netdev_name;
902
 
901
 
903
 	/* Identify network device, if applicable */
902
 	/* Identify network device, if applicable */
904
-	if ( IN6_IS_ADDR_LINKLOCAL ( in ) || IN6_IS_ADDR_MULTICAST ( in ) ) {
903
+	if ( IN6_IS_ADDR_NONGLOBAL ( in ) ) {
905
 		netdev = find_netdev_by_index ( sin6->sin6_scope_id );
904
 		netdev = find_netdev_by_index ( sin6->sin6_scope_id );
906
 		netdev_name = ( netdev ? netdev->name : "UNKNOWN" );
905
 		netdev_name = ( netdev ? netdev->name : "UNKNOWN" );
907
 	} else {
906
 	} else {
956
 	if ( ( rc = inet6_aton ( in_string, &in ) ) != 0 )
955
 	if ( ( rc = inet6_aton ( in_string, &in ) ) != 0 )
957
 		goto err_inet6_aton;
956
 		goto err_inet6_aton;
958
 
957
 
959
-	/* Parse network device name, if present */
958
+	/* Parse scope ID, if applicable */
960
 	if ( netdev_string ) {
959
 	if ( netdev_string ) {
960
+
961
+		/* Parse explicit network device name, if present */
961
 		netdev = find_netdev ( netdev_string );
962
 		netdev = find_netdev ( netdev_string );
962
 		if ( ! netdev ) {
963
 		if ( ! netdev ) {
963
 			rc = -ENODEV;
964
 			rc = -ENODEV;
964
 			goto err_find_netdev;
965
 			goto err_find_netdev;
965
 		}
966
 		}
966
 		sin6->sin6_scope_id = netdev->index;
967
 		sin6->sin6_scope_id = netdev->index;
968
+
969
+	} else if ( IN6_IS_ADDR_NONGLOBAL ( &in ) ) {
970
+
971
+		/* If no network device is explicitly specified for a
972
+		 * link-local or multicast address, default to using
973
+		 * "netX" (if existent).
974
+		 */
975
+		netdev = last_opened_netdev();
976
+		if ( netdev )
977
+			sin6->sin6_scope_id = netdev->index;
967
 	}
978
 	}
968
 
979
 
969
 	/* Copy IPv6 address portion to socket address */
980
 	/* Copy IPv6 address portion to socket address */

Loading…
Cancel
Save