PERFORCE change 176287 for review

Ana Kukec anchie at FreeBSD.org
Tue Mar 30 16:33:54 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=176287

Change 176287 by anchie at anchie_malimis on 2010/03/30 16:33:48

	Got rid of panic in soreceive_generic(). Messages flow now in both
	directions. There are still some issues -- ndp does not store ndp
	records properly yet.	

Affected files ...

.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/icmp6.c#33 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#37 edit

Differences ...

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

@@ -793,7 +793,7 @@
 		if (send_input_hook != NULL) {
 			IP6_EXTHDR_CHECK(m, off, icmp6len, IPPROTO_DONE);
                         printf("send_sendso_input_hook\n");
-                        send_sendso_input_hook(V_send_so, m, SND_IN, ip6len);
+                        send_sendso_input_hook(V_send_so, n, SND_IN, ip6len);
 			return (IPPROTO_DONE);
 		} else
 			nd6_rs_input(n, off, icmp6len);
@@ -819,7 +819,7 @@
 			goto freeit;
 		}
 		if (send_input_hook != NULL) {
-			send_sendso_input_hook(V_send_so, m, SND_IN, ip6len);	
+			send_sendso_input_hook(V_send_so, n, SND_IN, ip6len);	
 			return (IPPROTO_DONE);
 		} else
 			nd6_ra_input(n, off, icmp6len);
@@ -847,7 +847,7 @@
 		if (send_input_hook != NULL) {
 			/* Send incoming SeND/ND packet to user space. */
 			printf("%s: send_input_hook n=%p\n", __func__, n);
-			send_sendso_input_hook(V_send_so, m, SND_IN, ip6len);
+			send_sendso_input_hook(V_send_so, n, SND_IN, ip6len);
 		} else 
 			nd6_ns_input(n, off, icmp6len);
 		/* m stays. */
@@ -873,7 +873,7 @@
 			goto freeit;
 		}
 		if (send_input_hook != NULL)
-			send_sendso_input_hook(V_send_so, m, SND_IN, ip6len);
+			send_sendso_input_hook(V_send_so, n, SND_IN, ip6len);
 		else
 			nd6_na_input(n, off, icmp6len);
 		/* m stays. */
@@ -899,7 +899,7 @@
 			goto freeit;
 		}
 		if (send_input_hook != NULL) {
-			send_sendso_input_hook(V_send_so, m, SND_IN, ip6len);
+			send_sendso_input_hook(V_send_so, n, SND_IN, ip6len);
 			return (IPPROTO_DONE);
 		} else
 			icmp6_redirect_input(n, off);

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

@@ -198,34 +198,48 @@
 static int
 send_uattach(struct socket *so, int proto, struct thread *td)
 {
-	int error = 0;
 
 	printf("send_uattach: proto = %d\n", proto);
+	if (V_send_so != NULL)
+		return (EEXIST);
+
+	/* XXX: Revisit this, hardocoded! */
+	so->so_snd.sb_hiwat = 8192;
+
 	V_send_so = so;
  
-	return error;
+	return (0);
 }
 
 static int
-sosend_rcv(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
-    struct mbuf *control, struct thread *td)
+sosend_rcv(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
+	struct mbuf *control, struct thread *td)
 {
-	//struct ifnet *ifp = NULL;
+	struct ifnet *ifp;
 	struct snd_hdr *snd_hdr;
 
-	printf("sosend_rcv \n");
+	printf("sosend_rcv, mbuf len: %d \n", m->m_len);
 
 	snd_hdr = mtod(m, struct snd_hdr *);
 	printf("direction: %d, ifidx: %d \n", snd_hdr->direction, snd_hdr->ifidx);
-	//send_ifnet_setbyindex(snd_hdr->ifidx, ifp);
-#if 0
-	ifnet_setbyindex(snd_hdr->ifidx, ifp);
-	m_adj(n, sizeof(struct snd_hdr));
-	if (ifp)
-		send_output_hook(m, ifp, snd_hdr->direction);
-#endif
+
+	struct mbuf *m0;
+	m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+	if (m0 == NULL) {
+		m_freem(m);
+		return (ENOBUFS);
+	}
+	m_move_pkthdr(m, m0);
 
-	return 0;
+	ifp = ifnet_byindex_ref(snd_hdr->ifidx);
+	m_adj(m, sizeof(struct snd_hdr));
+	if (ifp) {
+		int error = send_output(m, ifp, snd_hdr->direction);
+		printf("error: %d\n", error);
+		if_rele(ifp);
+		return (0);
+	} else
+		return (ENETUNREACH);
 }
 
 /*
@@ -253,29 +267,14 @@
         if (len != msglen)
                 printf("XXX-BZ %s: (m)len=%u (ip6)msglen=%d", __func__, len, msglen);
                         
-printf("M_LEADINGSPACE(%d) >= SEND_HDR_LEN(%d)?\n", M_LEADINGSPACE(m), SEND_HDR_LEN);
-	if (M_LEADINGSPACE(m) >= SEND_HDR_LEN) {
-		M_PREPEND(m, SEND_HDR_LEN, M_PKTHDR|M_DONTWAIT);
-		snd_hdr = mtod(m, struct snd_hdr *);
-		snd_hdr->direction = direction;
-		snd_hdr->ifidx = -1;
-	} else {
-		struct mbuf *n;
-		MGET(n, M_PKTHDR|M_DONTWAIT, MT_DATA);
-		if (n == NULL) {
-			m_freem(m);
-			return ENOBUFS;
-		}	
-
-		snd_hdr = mtod(n, struct snd_hdr *);
-		snd_hdr->direction = direction;
-		snd_hdr->ifidx = -1;
-
-		n->m_len = SEND_HDR_LEN;
-		n->m_next = m->m_next;
-		m->m_next = n;
-		m->m_pkthdr.len += SEND_HDR_LEN;
+	m = m_prepend(m, SEND_HDR_LEN, M_PKTHDR|M_DONTWAIT);
+	if (m == NULL) {
+		printf("m_prepend() failed!\n");
+		return (ENOBUFS);
 	}
+	snd_hdr = mtod(m, struct snd_hdr *);
+	snd_hdr->direction = direction;
+	snd_hdr->ifidx = -1;
 
         /*
          * Send incoming or outgoing traffic to the user space either to be
@@ -286,6 +285,9 @@
 		sbappendrecord_locked(&s->so_rcv, m);
 		sorwakeup_locked(s);
 		return 0;
+	} else {
+		m_freem(m);
+		return 0;
 	}
 
     return -1;
@@ -308,7 +310,7 @@
 };
 
 struct protosw send_protosw = {
-    .pr_type =		SOCK_RAW,
+    .pr_type =			SOCK_RAW,
     .pr_protocol =		IPPROTO_SEND,
     .pr_usrreqs =		&send_usrreqs
 };


More information about the p4-projects mailing list