Browse Source

[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 years ago
parent
commit
4ad3c73b30
4 changed files with 31 additions and 2 deletions
  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 View File

238
 	addr->s6_addr[15] = 2;
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
 /** IPv6 link-local address settings block name */
253
 /** IPv6 link-local address settings block name */
242
 #define IPV6_SETTINGS_NAME "link"
254
 #define IPV6_SETTINGS_NAME "link"
243
 
255
 

+ 1
- 0
src/net/ipv6.c View File

1185
 	ref_init ( &ipv6set->refcnt, NULL );
1185
 	ref_init ( &ipv6set->refcnt, NULL );
1186
 	settings_init ( &ipv6set->settings, &ipv6_settings_operations,
1186
 	settings_init ( &ipv6set->settings, &ipv6_settings_operations,
1187
 			&ipv6set->refcnt, &ipv6_scope );
1187
 			&ipv6set->refcnt, &ipv6_scope );
1188
+	ipv6set->settings.order = IPV6_ORDER_LINK_LOCAL;
1188
 
1189
 
1189
 	/* Register settings */
1190
 	/* Register settings */
1190
 	if ( ( rc = register_settings ( &ipv6set->settings, parent,
1191
 	if ( ( rc = register_settings ( &ipv6set->settings, parent,

+ 17
- 2
src/net/ndp.c View File

981
 	size_t option_len;
981
 	size_t option_len;
982
 	unsigned int prefixes;
982
 	unsigned int prefixes;
983
 	unsigned int instance;
983
 	unsigned int instance;
984
+	int order;
984
 	int rc;
985
 	int rc;
985
 
986
 
986
 	/* Count number of prefix options.  We can assume that the
987
 	/* Count number of prefix options.  We can assume that the
987
 	 * options are well-formed, otherwise they would have been
988
 	 * options are well-formed, otherwise they would have been
988
 	 * rejected prior to being stored.
989
 	 * rejected prior to being stored.
989
 	 */
990
 	 */
991
+	order = IPV6_ORDER_PREFIX_ONLY;
990
 	for ( prefixes = 0, offset = 0 ; offset < len ; offset += option_len ) {
992
 	for ( prefixes = 0, offset = 0 ; offset < len ; offset += option_len ) {
993
+
994
+		/* Skip non-prefix options */
991
 		option = ( ( ( void * ) options ) + offset );
995
 		option = ( ( ( void * ) options ) + offset );
992
 		option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
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
 	/* Allocate and initialise structure */
1008
 	/* Allocate and initialise structure */
1004
 	ref_init ( &ndpset->refcnt, NULL );
1015
 	ref_init ( &ndpset->refcnt, NULL );
1005
 	settings_init ( &ndpset->settings, &ndp_settings_operations,
1016
 	settings_init ( &ndpset->settings, &ndp_settings_operations,
1006
 			&ndpset->refcnt, &ndp_settings_scope );
1017
 			&ndpset->refcnt, &ndp_settings_scope );
1018
+	ndpset->settings.order = order;
1007
 	memcpy ( &ndpset->router, router, sizeof ( ndpset->router ) );
1019
 	memcpy ( &ndpset->router, router, sizeof ( ndpset->router ) );
1008
 	ndpset->lifetime = lifetime;
1020
 	ndpset->lifetime = lifetime;
1009
 	ndpset->len = len;
1021
 	ndpset->len = len;
1028
 		settings_init ( &prefset->settings,
1040
 		settings_init ( &prefset->settings,
1029
 				&ndp_prefix_settings_operations,
1041
 				&ndp_prefix_settings_operations,
1030
 				&ndpset->refcnt, &ndp_settings_scope );
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
 		prefset->prefix = &option->prefix;
1046
 		prefset->prefix = &option->prefix;
1032
 		snprintf ( prefset->name, sizeof ( prefset->name ), "%d",
1047
 		snprintf ( prefset->name, sizeof ( prefset->name ), "%d",
1033
 			   instance++ );
1048
 			   instance++ );

+ 1
- 0
src/net/udp/dhcpv6.c View File

375
 	ref_init ( &dhcpv6set->refcnt, NULL );
375
 	ref_init ( &dhcpv6set->refcnt, NULL );
376
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
376
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
377
 			&dhcpv6set->refcnt, &dhcpv6_scope );
377
 			&dhcpv6set->refcnt, &dhcpv6_scope );
378
+	dhcpv6set->settings.order = IPV6_ORDER_DHCPV6;
378
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
379
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
379
 	len = options->len;
380
 	len = options->len;
380
 	memcpy ( data, options->data, len );
381
 	memcpy ( data, options->data, len );

Loading…
Cancel
Save