PERFORCE change 166318 for review

Ana Kukec anchie at FreeBSD.org
Mon Jul 20 17:59:25 UTC 2009


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

Change 166318 by anchie at anchie_malimis on 2009/07/20 17:59:04

	Bug fix - in case of RTM_SND, rtsock.c calculates now the length of
	if_announcemsghdr, and not rt_msghdr.	

Affected files ...

.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#20 edit
.. //depot/projects/soc2009/anchie_send/src/sys/net/rtsock.c#10 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#19 edit

Differences ...

==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#20 (text+ko) ====

@@ -41,7 +41,6 @@
 #include <net/if.h>
 #include <netinet/in.h>
 #include <netinet6/send.h>
-
 #include "config.h"
 #include <applog.h>
 #include <sbuff.h>
@@ -129,6 +128,7 @@
 {
 	struct snd_packet_info *pi;
 	struct rt_msghdr *rtm;
+	struct ip6_hdr *ip6;
 
 	if (drop) {
 		snd_put_buf(b);
@@ -137,19 +137,38 @@
 	pi = (struct snd_packet_info *)(b->head);
 	DBG(&dbg_snd, "Direction, in = %d", pi->in);
 
+#if 0
+	ip6 = sbuff_data(b);	
+	DBG(&dbg_snd, "SRC: %s", inet_ntop(AF_INET6, &ip6->ip6_src, abuf, sizeof (abuf)));
+	DBG(&dbg_snd, "DST: %s", inet_ntop(AF_INET6, &ip6->ip6_dst, abuf, sizeof (abuf)));
+	struct nd_neighbor_solicit *ns;
+	struct in6_addr *tgt;
+	b->data += sizeof (struct ip6_hdr);
+	ns = (struct nd_neighbor_solicit *)(b->data);
+	tgt = &ns->nd_ns_target;
+	DBG(&dbg_snd, "DST: %s", inet_ntop(AF_INET6, tgt, abuf, sizeof (abuf)));
+#endif
+
+	DBG(&dbg_snd, "rt_msghdr = %d, if_announcemsghdr = %d\n", sizeof (struct rt_msghdr), sizeof (struct if_announcemsghdr));
+
 	/* buffer starts with IPv6 hdr, roll back to include rtm header */	
+#if 0
 	b->data -= sizeof (struct rt_msghdr);
 	b->len += sizeof (struct rt_msghdr);
+#endif
+	b->data -= sizeof (struct if_announcemsghdr);
+	b->len += sizeof (struct if_announcemsghdr);
 
 	DBG(&dbg_snd, "%d bytes on %s", b->len, pi->ifinfo->name);
 
 	rtm = sbuff_data(b);
 
-	/* RTM header already has rtm version, type, etc. set up */
+	/* reusing RTM header received from kernel */
 	rtm->rtm_msglen = b->len;
 	rtm->rtm_addrs = 0;
+	rtm->rtm_index = pi->ifinfo->ifidx;
 
-	if (send(sndsock, rtm, rtm->rtm_msglen, 0) < 0) {
+	if (send(sndsock, rtm, b->len, 0) < 0) {
 		DBG(&dbg_snd, "Failed to send routing message back to kernel.");
 		perror("Failed");
 		snd_put_buf(b);
@@ -263,6 +282,7 @@
 	switch (rtm->rtm_type) {
 	case RTM_IFANNOUNCE:
 		/* XXX: Do we need this? */
+		DBG(&dbg_snd, "RTM_IFANNOUNCE");
 		break;
 	case RTM_SND:
 		ifan = sbuff_data(b);	
@@ -282,8 +302,11 @@
 		case RTM_SND_OUT:
 			applog(LOG_ERR, "RTM_SND_OUT");
 			/* n = RTM hdr + ip6_hdr + icmp6len */
+#if 0
 			if (sbuff_pull(b, sizeof (struct rt_msghdr)) == NULL) {
-				DBG(&dbg_snd, "invalid pkt (not enough for rtm hedaer");
+#endif
+			if (sbuff_pull(b, sizeof (struct if_announcemsghdr)) == NULL) {
+				DBG(&dbg_snd, "invalid pkt (not enough for rtm header");
 				goto done;
 			}
 

==== //depot/projects/soc2009/anchie_send/src/sys/net/rtsock.c#10 (text+ko) ====

@@ -65,6 +65,7 @@
 #include <netinet6/scope6_var.h>
 #endif
 #include <netinet6/send.h>
+#include <netinet6/in6_var.h>
 
 #if defined(INET) || defined(INET6)
 #ifdef SCTP
@@ -523,27 +524,34 @@
 		struct rtentry *saved_nrt;
 
 	case RTM_SND:
-		printf("RTM_SND!");
+		printf("RTM_SND!\n");
 		struct if_announcemsghdr *ifan;
 		ifan = mtod(m, struct if_announcemsghdr *);
 
 		switch (ifan->ifan_what) {
 		case RTM_SND_IN: 
 			ifp = ifnet_byindex(rtm->rtm_index);
-			m_adj(m, sizeof (struct rt_msghdr));
-			printf("rtm->rtm_index = %d\n", rtm->rtm_index);
-			if (ifp)
+			if (ifp) {
+				m_adj(m, sizeof (struct if_announcemsghdr));
+				printf("rtm->rtm_index = %d\n", rtm->rtm_index);
 				send_output_hook(m, ifp, SND_IN);
+			} else {
+				printf("route_output: ifp == NULL");
+			}
+			return (0);
 			break;
 		case RTM_SND_OUT:
-			ifp = m->m_pkthdr.rcvif;
-			printf("rtm->rtm_index = %d\n", rtm->rtm_index);
+			ifp = ifnet_byindex(rtm->rtm_index);
+			if (ifp) {
 #if 0
-			ifp = ifnet_byindex(rtm->rtm_index);
+				m_adj(m, sizeof (struct if_announcemsghdr));
 #endif
-			m_adj(m, sizeof (struct rt_msghdr));
-			if (ifp)
+				printf("if_index = %u\n", ifp->if_index);
+				m->m_data += sizeof (struct if_announcemsghdr);
 				send_output_hook(m, ifp, SND_OUT);
+			} else
+				printf("route_output: ifp == NULL");
+			return (0);
 			break;
 		}
 
@@ -913,6 +921,7 @@
 
 	case RTM_IFANNOUNCE:
 	case RTM_IEEE80211:
+	case RTM_SND:
 		len = sizeof(struct if_announcemsghdr);
 		break;
 

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

@@ -10,19 +10,20 @@
 
 #include <netinet/in.h>
 #include <netinet/ip6.h>
+#include <netinet/icmp6.h>
 
 #include <net/route.h>
 #include <net/if.h>
 
 #include <netinet6/send.h>
-#include <netinet6/ip6_var.h>
+#include <netinet6/in6_var.h>
 
 static int
 send_output(struct mbuf *m, struct ifnet *ifp, int in)
 {
 	struct ip6_hdr *ip6;
 	struct sockaddr_in6 *dst;
-	struct icmp6_hdr *icmp6
+	struct icmp6_hdr *icmp6;
 	int icmp6len;
 
 	printf("send_output\n");
@@ -38,11 +39,12 @@
 		icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);	
 		printf("send_output: m_pkthdr.len = %d\n", m->m_pkthdr.len);
 
-		icmp6 = (struct icmp6_hdr *)((caddr_t)ip6 + sizeof(struct ip6_hdr));
+		ip6 = mtod(m, struct ip6_hdr *);
+		icmp6 = (struct icmp6_hdr *)(ip6 + 1);
 		switch (icmp6->icmp6_code) {
 		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;
 		}
 
@@ -52,19 +54,32 @@
 	case SND_OUT:
 		ip6 = mtod(m, struct ip6_hdr *);
 
+                {
+                char ip6buf[INET6_ADDRSTRLEN];
+                printf("XXX-AK, send.c: ifp=%p, xname=%s, dst=%s\n", ifp, ifp->if_xname, ip6_sprintf(ip6buf, &ip6->ip6_dst));
+                }
+
+
         	dst = malloc (sizeof (struct sockaddr_in6), M_TEMP, M_NOWAIT);
+		bzero(dst, sizeof(*dst));
         	dst->sin6_len = sizeof(struct sockaddr_in6);
         	dst->sin6_family = AF_INET6;
         	dst->sin6_addr = ip6->ip6_dst;
 
+		{
+		char ip6buf[INET6_ADDRSTRLEN];
+		printf("XXX-BZ, send.c: ifp=%p, xname=%s, dst=%s\n", ifp, ifp->if_xname, ip6_sprintf(ip6buf, &((struct sockaddr_in6 *)dst)->sin6_addr)); 
+		}
+
 		/* 
 	 	 * From nd6.c: nd6_output_lle(). 
-	 	 * ToFix: kernel panic: Duplicate free of item (mbuf). 
 	 	 */
 		return (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, NULL);
 		//return (0);
 		break;
 	}	
+
+	return (0);
 }
 
 static int


More information about the p4-projects mailing list