PERFORCE change 167470 for review

Ana Kukec anchie at FreeBSD.org
Tue Aug 18 12:52:48 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=167470

Change 167470 by anchie at anchie_malimis on 2009/08/18 12:52:38

	- Bug fixes in handling the incoming packets coming from the user land
	  into kernel (netinet6/send.c: send_output()).
	- Added calls of nd6_??_input() functions.
	- Added call of icmp6_rip6_input() function with appropriate
	  arguments.	

Affected files ...

.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#25 edit

Differences ...

==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#25 (text+ko) ====

@@ -18,6 +18,7 @@
 #include <net/if.h>
 
 #include <netinet6/in6_var.h>
+#include <netinet6/nd6.h>
 #include <netinet6/scope6_var.h>
 #include <netinet6/send.h>
 
@@ -29,7 +30,7 @@
 	struct ip6_hdr *ip6;
 	struct sockaddr_in6 dst;
 	struct icmp6_hdr *icmp6;
-	int icmp6len;
+	int icmp6len, *offp = NULL;
 
 	printf("send.c: send_output()\n");
 
@@ -41,26 +42,58 @@
 
 	switch (direction) {
 	case SND_IN:
-		icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);	
-		printf("send_output: m_pkthdr.len = %d\n", m->m_pkthdr.len);
+		/* XXX-BZ can there be extension headers? */
+		if (m->m_len < (sizeof(struct ip6_hdr) +
+		    sizeof(struct icmp6_hdr))) {
+			m = m_pullup(m, sizeof(struct ip6_hdr) +
+			    sizeof(struct icmp6_hdr));
+			if (!m)
+				return (ENOBUFS);
+		}
+
+		if (m->m_flags & M_PKTHDR)
+			icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);	
+		else
+			panic("Doh! not the first mbuf.");
 
 		ip6 = mtod(m, struct ip6_hdr *);
 		icmp6 = (struct icmp6_hdr *)(ip6 + 1);
-		switch (icmp6->icmp6_code) {
+
+		/*
+		 * Output the packet as icmp6.c:incpm6_input() would do.
+		 * The mbuf is always consumed, so we do not have to
+		 * care about that.
+		 */
+		switch (icmp6->icmp6_type) {
 		case ND_NEIGHBOR_SOLICIT:
-			/* From icmp6.c: incpm6_input(). */
-			//nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
+			nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
+			break;
+		case ND_NEIGHBOR_ADVERT:
+			nd6_na_input(m, sizeof(struct ip6_hdr), icmp6len);
 			break;
+		default:
+			/* XXX-BZ TODO */
+			printf("%s:%d: icmp6_code=%u\n",
+			    __func__, __LINE__, icmp6->icmp6_code);
+			m_print(m, m->m_pkthdr.len);
+			return (ENOSYS);
 		}
 
+		*offp = sizeof (struct ip6_hdr);
 		//icmp6_rip6_input(&m, *offp);	
-		/* XXX-BZ TODO */
-		return (ENOSYS);
+
+		/*
+		 * No error returned from nd6_??_input() so the only thing
+		 * we can do is to pretend that it worked.
+		 */
+		return (0);
 
 	case SND_OUT:
-		m = m_pullup(m, sizeof(struct ip6_hdr));
-		if (!m)
-			return (ENOBUFS);
+		if (m->m_len < sizeof(struct ip6_hdr)) {
+			m = m_pullup(m, sizeof(struct ip6_hdr));
+			if (!m)
+				return (ENOBUFS);
+		}
 		ip6 = mtod(m, struct ip6_hdr *);
 		if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst))
 			m->m_flags |= M_MCAST;


More information about the p4-projects mailing list