瀏覽代碼

[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 年之前
父節點
當前提交
41670ca2fe
共有 2 個檔案被更改,包括 18 行新增4 行删除
  1. 3
    0
      src/include/ipxe/in.h
  2. 15
    4
      src/net/ipv6.c

+ 3
- 0
src/include/ipxe/in.h 查看文件

@@ -63,6 +63,9 @@ struct in6_addr {
63 63
 	( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==	\
64 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 70
  * IPv4 socket address
68 71
  */

+ 15
- 4
src/net/ipv6.c 查看文件

@@ -290,8 +290,7 @@ static struct ipv6_miniroute * ipv6_route ( unsigned int scope_id,
290 290
 		if ( ! ( miniroute->flags & IPV6_HAS_ADDRESS ) )
291 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 295
 			/* If destination is non-global, and the scope ID
297 296
 			 * matches this network device, then use this route.
@@ -901,7 +900,7 @@ static const char * ipv6_sock_ntoa ( struct sockaddr *sa ) {
901 900
 	const char *netdev_name;
902 901
 
903 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 904
 		netdev = find_netdev_by_index ( sin6->sin6_scope_id );
906 905
 		netdev_name = ( netdev ? netdev->name : "UNKNOWN" );
907 906
 	} else {
@@ -956,14 +955,26 @@ static int ipv6_sock_aton ( const char *string, struct sockaddr *sa ) {
956 955
 	if ( ( rc = inet6_aton ( in_string, &in ) ) != 0 )
957 956
 		goto err_inet6_aton;
958 957
 
959
-	/* Parse network device name, if present */
958
+	/* Parse scope ID, if applicable */
960 959
 	if ( netdev_string ) {
960
+
961
+		/* Parse explicit network device name, if present */
961 962
 		netdev = find_netdev ( netdev_string );
962 963
 		if ( ! netdev ) {
963 964
 			rc = -ENODEV;
964 965
 			goto err_find_netdev;
965 966
 		}
966 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 980
 	/* Copy IPv6 address portion to socket address */

Loading…
取消
儲存