[gPXE-devel] [PATCH 13/31] [ipv6] add a net_protocol to let ICMPv6 protocols check IPv6 addresses against network devices

matthew at theiselins.net matthew at theiselins.net
Fri Jul 8 10:28:22 EDT 2011


From: Matthew Iselin <matthew at theiselins.net>

Signed-off-by: Matthew Iselin <matthew at theiselins.net>
---
 src/include/gpxe/icmp6.h |   26 ++++++++++++++++++++++++++
 src/net/ipv6.c           |   25 +++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/include/gpxe/icmp6.h b/src/include/gpxe/icmp6.h
index ae309d6..e6f6ccd 100644
--- a/src/include/gpxe/icmp6.h
+++ b/src/include/gpxe/icmp6.h
@@ -12,6 +12,32 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <gpxe/ip6.h>
 #include <gpxe/ndp.h>
 
+#include <gpxe/tables.h>
+
+struct net_device;
+struct net_protocol;
+
+/** A network-layer protocol that relies upon ICMPv6 */
+struct icmp6_net_protocol {
+	/** Network-layer protocol */
+	struct net_protocol *net_protocol;
+	/** Check existence of address
+	 *
+	 * @v netdev	Network device
+	 * @v net_addr	Network-layer address
+	 * @ret rc	Return status code
+	 */
+	int ( * check ) ( struct net_device *netdev,
+			  const void *net_addr );
+};
+
+/** ICMPv6 protocol table */
+#define ICMP6_NET_PROTOCOLS \
+	__table ( struct icmp6_net_protocol, "icmp6_net_protocols" )
+
+/** Declare an ICMPv6 protocol */
+#define __icmp6_net_protocol __table_entry ( ICMP6_NET_PROTOCOLS, 01 )
+
 #define ICMP6_NSOLICIT 135
 #define ICMP6_NADVERT 136
 
diff --git a/src/net/ipv6.c b/src/net/ipv6.c
index 85f896b..c0ae68b 100644
--- a/src/net/ipv6.c
+++ b/src/net/ipv6.c
@@ -60,8 +60,8 @@ add_ipv6_miniroute ( struct net_device *netdev, struct in6_addr prefix,
 		     struct in6_addr gateway ) {
 	struct ipv6_miniroute *miniroute;
 	
-	DBG("ipv6 add: %s/%d ", inet6_ntoa(address), prefix_len);
-	DBG("gw %s\n", inet6_ntoa(gateway));
+	DBG( "ipv6 add: %s/%d ", inet6_ntoa ( address ), prefix_len );
+	DBG( "gw %s\n", inet6_ntoa( gateway ) );
 
 	miniroute = malloc ( sizeof ( *miniroute ) );
 	if ( miniroute ) {
@@ -540,6 +540,20 @@ static const char * ipv6_ntoa ( const void *net_addr ) {
 	return inet6_ntoa ( * ( ( struct in6_addr * ) net_addr ) );
 }
 
+static int ipv6_check ( struct net_device *netdev, const void *net_addr ) {
+	const struct in6_addr *address = net_addr;
+	struct ipv6_miniroute *miniroute;
+
+	list_for_each_entry ( miniroute, &miniroutes, list ) {
+		if ( ( miniroute->netdev == netdev ) &&
+		     ( ! memcmp ( &miniroute->address, address, 16 ) ) ) {
+			/* Found matching address */
+			return 0;
+		}
+	}
+	return -ENOENT;
+}
+
 /** IPv6 protocol */
 struct net_protocol ipv6_protocol __net_protocol = {
 	.name = "IPV6",
@@ -555,3 +569,10 @@ struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = {
 	.sa_family = AF_INET6,
 	.tx = ipv6_tx,
 };
+
+/** IPv6 ICMPv6 protocol, for NDP */
+struct icmp6_net_protocol ipv6_icmp6_protocol __icmp6_net_protocol = {
+	.net_protocol = &ipv6_protocol,
+	.check = ipv6_check,
+};
+
-- 
1.7.2.5



More information about the gPXE-devel mailing list