[ipxe-devel] [PATCH 06/11] ndp: make IPv6 gateway user-settable

Hannes Reinecke hare at suse.de
Thu May 7 09:25:01 UTC 2015


NDP will discover the IPv6 default gateway, so we should make
it user-settable. Unfortunately the default gateway is not
part of the NDP options, so I've introduced a dummy option
'0', which will retrieve the gateway from the miniroute
associated with the 'prefix' option.

Signed-off-by: Hannes Reinecke <hare at suse.de>
---
 src/include/ipxe/ipv6.h |  2 ++
 src/include/ipxe/ndp.h  |  3 +++
 src/net/ipv6.c          |  4 ++--
 src/net/ndp.c           | 29 ++++++++++++++++++++++++++++-
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/include/ipxe/ipv6.h b/src/include/ipxe/ipv6.h
index a2b4c88..dd71df5 100644
--- a/src/include/ipxe/ipv6.h
+++ b/src/include/ipxe/ipv6.h
@@ -253,5 +253,7 @@ extern int format_ipv6_setting ( const struct setting_type *type,
 				 const void *raw, size_t raw_len, char *buf,
 				 size_t len );
 extern int ipv6_ll_route ( struct net_device *netdev );
+struct ipv6_miniroute * ipv6_miniroute ( struct net_device *netdev,
+					 struct in6_addr *address );
 
 #endif /* _IPXE_IPV6_H */
diff --git a/src/include/ipxe/ndp.h b/src/include/ipxe/ndp.h
index 1815236..bd1477b 100644
--- a/src/include/ipxe/ndp.h
+++ b/src/include/ipxe/ndp.h
@@ -26,6 +26,9 @@ struct ndp_option_header {
 /** NDP option block size */
 #define NDP_OPTION_BLKSZ 8U
 
+/** NDP RA gateway address */
+#define NDP_OPT_RA_ADDR 0
+
 /** NDP source link-layer address option */
 #define NDP_OPT_LL_SOURCE 1
 
diff --git a/src/net/ipv6.c b/src/net/ipv6.c
index 61dc5ec..4d2a053 100644
--- a/src/net/ipv6.c
+++ b/src/net/ipv6.c
@@ -145,8 +145,8 @@ static int ipv6_is_on_link ( struct ipv6_miniroute *miniroute,
  * @v address		IPv6 address
  * @ret miniroute	Routing table entry, or NULL if not found
  */
-static struct ipv6_miniroute * ipv6_miniroute ( struct net_device *netdev,
-						struct in6_addr *address ) {
+struct ipv6_miniroute * ipv6_miniroute ( struct net_device *netdev,
+					 struct in6_addr *address ) {
 	struct ipv6_miniroute *miniroute;
 
 	list_for_each_entry ( miniroute, &ipv6_miniroutes, list ) {
diff --git a/src/net/ndp.c b/src/net/ndp.c
index e4e3262..ad31258 100644
--- a/src/net/ndp.c
+++ b/src/net/ndp.c
@@ -706,8 +706,24 @@ static int ndp_fetch ( struct settings *settings,
 		/* Calculate option length */
 		option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
 
+		/* Looks for prefix if the router address is requested */
+		if ( type == NDP_OPT_RA_ADDR &&
+		     option->header.type == NDP_OPT_PREFIX ) {
+			struct in6_addr prefix;
+			struct ipv6_miniroute *route6;
+
+			memcpy( &prefix, ( ( ( void * ) option ) + offset ),
+				sizeof(prefix) );
+
+			route6 = ipv6_miniroute( netdev, &prefix );
+			if (route6) {
+				if ( len > sizeof(struct in6_addr) )
+					len = sizeof(struct in6_addr);
+				memcpy( data, &route6->router, len );
+				return sizeof(struct in6_addr);
+			}
+		} else if ( option->header.type == type ) {
 		/* If this is the requested option, return it */
-		if ( option->header.type == type ) {
 
 			/* Sanity check */
 			if ( offset > option_len ) {
@@ -776,6 +792,17 @@ static int ndp_register_settings ( struct net_device *netdev,
 }
 
 /** Prefix setting */
+const struct setting ndp_gateway6_setting __setting ( SETTING_IP_EXTRA, gateway6) = {
+	.name = "gateway6",
+	.description = "IPv6 default gateway",
+	.tag = NDP_TAG ( NDP_OPT_RA_ADDR,
+			 offsetof ( struct ndp_prefix_information_option,
+				    prefix ) ),
+	.type = &setting_type_ipv6,
+	.scope = &ndp_settings_scope,
+};
+
+/** Prefix setting */
 const struct setting ndp_prefix6_setting __setting ( SETTING_IP_EXTRA, prefix6) = {
 	.name = "prefix6",
 	.description = "IPv6 prefix",
-- 
1.8.4.5




More information about the ipxe-devel mailing list