Ver código fonte

[ipv6] Match user expectations for IPv6 settings priorities

A reasonable user expectation is that ${net0/ip6} should show the
"highest-priority" of the IPv6 addresses, even when multiple IPv6
addresses are active.  The expected order of priority is likely to be
manually-assigned addresses first, then stateful DHCPv6 addresses,
then SLAAC addresses, and lastly link-local addresses.

Using ${priority} to enforce an ordering is undesirable since that
would affect the priority assigned to each of the net<N> blocks as a
whole, so use the sibling ordering capability instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 anos atrás
pai
commit
4ad3c73b30
4 arquivos alterados com 31 adições e 2 exclusões
  1. 12
    0
      src/include/ipxe/ipv6.h
  2. 1
    0
      src/net/ipv6.c
  3. 17
    2
      src/net/ndp.c
  4. 1
    0
      src/net/udp/dhcpv6.c

+ 12
- 0
src/include/ipxe/ipv6.h Ver arquivo

@@ -238,6 +238,18 @@ static inline void ipv6_all_routers ( struct in6_addr *addr ) {
238 238
 	addr->s6_addr[15] = 2;
239 239
 }
240 240
 
241
+/** IPv6 settings sibling order */
242
+enum ipv6_settings_order {
243
+	/** No address */
244
+	IPV6_ORDER_PREFIX_ONLY = -4,
245
+	/** Link-local address */
246
+	IPV6_ORDER_LINK_LOCAL = -3,
247
+	/** Address assigned via SLAAC */
248
+	IPV6_ORDER_SLAAC = -2,
249
+	/** Address assigned via DHCPv6 */
250
+	IPV6_ORDER_DHCPV6 = -1,
251
+};
252
+
241 253
 /** IPv6 link-local address settings block name */
242 254
 #define IPV6_SETTINGS_NAME "link"
243 255
 

+ 1
- 0
src/net/ipv6.c Ver arquivo

@@ -1185,6 +1185,7 @@ static int ipv6_register_settings ( struct net_device *netdev ) {
1185 1185
 	ref_init ( &ipv6set->refcnt, NULL );
1186 1186
 	settings_init ( &ipv6set->settings, &ipv6_settings_operations,
1187 1187
 			&ipv6set->refcnt, &ipv6_scope );
1188
+	ipv6set->settings.order = IPV6_ORDER_LINK_LOCAL;
1188 1189
 
1189 1190
 	/* Register settings */
1190 1191
 	if ( ( rc = register_settings ( &ipv6set->settings, parent,

+ 17
- 2
src/net/ndp.c Ver arquivo

@@ -981,17 +981,28 @@ static int ndp_register_settings ( struct net_device *netdev,
981 981
 	size_t option_len;
982 982
 	unsigned int prefixes;
983 983
 	unsigned int instance;
984
+	int order;
984 985
 	int rc;
985 986
 
986 987
 	/* Count number of prefix options.  We can assume that the
987 988
 	 * options are well-formed, otherwise they would have been
988 989
 	 * rejected prior to being stored.
989 990
 	 */
991
+	order = IPV6_ORDER_PREFIX_ONLY;
990 992
 	for ( prefixes = 0, offset = 0 ; offset < len ; offset += option_len ) {
993
+
994
+		/* Skip non-prefix options */
991 995
 		option = ( ( ( void * ) options ) + offset );
992 996
 		option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
993
-		if ( option->header.type == NDP_OPT_PREFIX )
994
-			prefixes++;
997
+		if ( option->header.type != NDP_OPT_PREFIX )
998
+			continue;
999
+
1000
+		/* Count number of prefixes */
1001
+		prefixes++;
1002
+
1003
+		/* Increase overall order if we have SLAAC addresses */
1004
+		if ( option->prefix.flags & NDP_PREFIX_AUTONOMOUS )
1005
+			order = IPV6_ORDER_SLAAC;
995 1006
 	}
996 1007
 
997 1008
 	/* Allocate and initialise structure */
@@ -1004,6 +1015,7 @@ static int ndp_register_settings ( struct net_device *netdev,
1004 1015
 	ref_init ( &ndpset->refcnt, NULL );
1005 1016
 	settings_init ( &ndpset->settings, &ndp_settings_operations,
1006 1017
 			&ndpset->refcnt, &ndp_settings_scope );
1018
+	ndpset->settings.order = order;
1007 1019
 	memcpy ( &ndpset->router, router, sizeof ( ndpset->router ) );
1008 1020
 	ndpset->lifetime = lifetime;
1009 1021
 	ndpset->len = len;
@@ -1028,6 +1040,9 @@ static int ndp_register_settings ( struct net_device *netdev,
1028 1040
 		settings_init ( &prefset->settings,
1029 1041
 				&ndp_prefix_settings_operations,
1030 1042
 				&ndpset->refcnt, &ndp_settings_scope );
1043
+		prefset->settings.order =
1044
+			( ( option->prefix.flags & NDP_PREFIX_AUTONOMOUS ) ?
1045
+			  IPV6_ORDER_SLAAC : IPV6_ORDER_PREFIX_ONLY );
1031 1046
 		prefset->prefix = &option->prefix;
1032 1047
 		snprintf ( prefset->name, sizeof ( prefset->name ), "%d",
1033 1048
 			   instance++ );

+ 1
- 0
src/net/udp/dhcpv6.c Ver arquivo

@@ -375,6 +375,7 @@ static int dhcpv6_register ( struct in6_addr *lease,
375 375
 	ref_init ( &dhcpv6set->refcnt, NULL );
376 376
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
377 377
 			&dhcpv6set->refcnt, &dhcpv6_scope );
378
+	dhcpv6set->settings.order = IPV6_ORDER_DHCPV6;
378 379
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
379 380
 	len = options->len;
380 381
 	memcpy ( data, options->data, len );

Carregando…
Cancelar
Salvar