Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Aug 2010 10:56:57 GMT
From:      Ana Kukec <anchie@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 182309 for review
Message-ID:  <201008121056.o7CAuvAn098868@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@182309?ac=10

Change 182309 by anchie@anchie_malimis on 2010/08/12 10:56:14

	Enabled demux of the right interface when exchanging packets between
	ND stack and sendd.	

Affected files ...

.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.c#9 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/icmp6.c#47 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6.c#40 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6_nbr.c#22 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/raw_ip6.c#15 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#50 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.h#24 edit

Differences ...

==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.c#9 (text+ko) ====

@@ -51,12 +51,13 @@
 #include <applog.h>
 #include <list.h>
 #include <sbuff.h>
+
 static int sndsock	= -1;
 
 /* Per-interface info */
 struct snd_ifinfo {
 	struct list_head list;
-	char	name[32];
+	char	name[IFNAMSIZ];
 	int	ifidx;
 	int	snds;
 };
@@ -76,11 +77,15 @@
 static int
 freebsd_snd_init(void)
 {
+
 	if (list_empty(&ifaces)) {
 		applog(LOG_ERR, "SEND must be active on at least one iface");
 		return (-1);
 	}
+
+#ifndef IPPROTO_SEND
 #define IPPROTO_SEND	259
+#endif
 	if ((sndsock = socket(PF_INET6, SOCK_RAW, IPPROTO_SEND)) < 0) {	
 		applog(LOG_ERR, "[%s:%d]: socket: %s", __func__, __LINE__,
 			strerror(errno));
@@ -102,11 +107,19 @@
         return (0);
 }
 
+static void
+freebsd_snd_fini(void)
+{
+
+	close(sndsock);
+}
+
 void
 os_specific_fini(void)
 {
+
+	freebsd_snd_fini();
 	linux_rand_fini();
-	close(sndsock);
 }
 
 int
@@ -124,16 +137,16 @@
 	DBG(&dbg_snd, "os_specific_handle_iface -> p->name = %s", p->name);
 	p->ifidx = ifidx;
 	DBG(&dbg_snd, "os_specific_handle_iface -> p->ifidx = %d", ifidx);
-	p->snds = -1;
 	list_add_tail(&p->list, &ifaces);
 
 	return (0);
 }
 
 static void
-snd_sock_read(struct snd_ifinfo *p)
+snd_sock_read()
 {
 	struct sockaddr_send sendsrc;
+	struct snd_ifinfo *p, pifinfo;
 	socklen_t len;
 	struct sbuff *b;
 	struct snd_packet_info *pi;
@@ -157,7 +170,26 @@
 
 	b->len = n;
 
-	switch(sendsrc.send_direction) {
+	/* Check if we are interested in the given interface. */
+	list_for_each_entry(p, &ifaces, list) {
+		if (p->ifidx == sendsrc.send_ifidx)
+			goto found;
+	}
+
+	/*
+	 * If not found, send the packet straight back to the kernel, as
+	 * we are not doing SeND on that interface.
+	 */
+	DBG(&dbg_snd, "Received packet for non-SeND interface. Sending back to kernel.");
+	pifinfo.ifidx = sendsrc.send_ifidx;
+	pi->ifinfo = &pifinfo;
+	pi->in = (sendsrc.send_direction == SND_IN) ? 1 : 0;
+	os_specific_deliver_pkt(NULL, b, 0, 0);
+
+	goto done;
+
+found:
+	switch (sendsrc.send_direction) {
 	case SND_IN:
 		applog(LOG_ERR, "Direction: SND_IN");
 		pi->ifinfo = p;
@@ -183,25 +215,17 @@
 void
 os_specific_add_fds(fd_set *fds, int *maxfd)
 {
-	struct snd_ifinfo *p;
 
-	list_for_each_entry(p, &ifaces, list) {
-		p->snds = sndsock;
-		FD_SET(p->snds, fds);
-		*maxfd = sendd_max(*maxfd, p->snds);
-	}
+	FD_SET(sndsock, fds);
+	*maxfd = sendd_max(*maxfd, sndsock);
 }
 
 void
 os_specific_dispatch_fds(fd_set *fds)
 {
-	struct snd_ifinfo *p;
 
-	list_for_each_entry(p, &ifaces, list) {
-		if (FD_ISSET(sndsock, fds)) {
-			snd_sock_read(p);
-		}
-	}
+	if (FD_ISSET(sndsock, fds))
+		snd_sock_read();
 }
 
 void
@@ -222,15 +246,19 @@
 	sendsrc.send_direction = pi->in;
 	sendsrc.send_ifidx = pi->ifinfo->ifidx;
 
-	DBG(&dbg_snd, "Sending %d bytes.\n", b->len);
+	DBG(&dbg_snd, "Sending %d bytes for ifidx=%d:\n", b->len, pi->ifinfo->ifidx);
 	if (sendto(sndsock, b->data, b->len, 0, (struct sockaddr *)&sendsrc,
 	    sizeof(sendsrc)) < 0) {
 		DBG(&dbg_snd, "Failed to send SEND message back to kernel.");
+		DBG(&dbg_snd, "%d %p %d %p", sndsock, b->data, b->len, &sendsrc);
+		DBG(&dbg_snd, "send_len=%d send_family=%d send_direction=%d send_ifidx=%d", sendsrc.send_len, sendsrc.send_family, sendsrc.send_direction, sendsrc.send_ifidx);
+		DBG_HEXDUMP(&dbg_snd, "data:", b->data, b->len);
 		perror("Failed");
 		snd_put_buf(b);
 		return;
 	}
 
 	snd_put_buf(b);
+
 	return;
 }

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

@@ -774,7 +774,7 @@
 			if (send_sendso_input_hook != NULL) {
 				IP6_EXTHDR_CHECK(m, off,
 				    icmp6len, IPPROTO_DONE);
-				error = send_sendso_input_hook(m,
+				error = send_sendso_input_hook(m, ifp,
 				    SND_IN, ip6len);
 				/* -1 == no app on SEND socket */
 				if (error == 0)
@@ -788,7 +788,7 @@
 		if (send_sendso_input_hook != NULL) {
 			IP6_EXTHDR_CHECK(m, off,
 			    icmp6len, IPPROTO_DONE);
-                        error = send_sendso_input_hook(n,
+                        error = send_sendso_input_hook(n, ifp,
 			    SND_IN, ip6len);
 			if (error == 0) {
 				m_freem(n);
@@ -811,7 +811,7 @@
 
 			/* Send incoming SeND-protected/ND packet to user space. */
 			if (send_sendso_input_hook != NULL) {
-				error = send_sendso_input_hook(m,
+				error = send_sendso_input_hook(m, ifp,
 				    SND_IN, ip6len);
 				if (error == 0)
 					return (IPPROTO_DONE);
@@ -823,7 +823,7 @@
 			goto freeit;
 		}
 		if (send_sendso_input_hook != NULL) {
-			error = send_sendso_input_hook(n,
+			error = send_sendso_input_hook(n, ifp,
 			    SND_IN, ip6len);
 			if (error == 0)
 				return (IPPROTO_DONE);
@@ -841,7 +841,7 @@
 			goto badlen;
 		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
 			if (send_sendso_input_hook != NULL) {
-				error = send_sendso_input_hook(m,
+				error = send_sendso_input_hook(m, ifp,
 				    SND_IN, ip6len);
 				if (error == 0)
 					return (IPPROTO_DONE);
@@ -853,7 +853,7 @@
 			goto freeit;
 		}
 		if (send_sendso_input_hook != NULL) {
-			error = send_sendso_input_hook(n,
+			error = send_sendso_input_hook(n, ifp,
 			    SND_IN, ip6len);
 			if (error == 0)
 				return (IPPROTO_DONE);
@@ -873,7 +873,7 @@
 
 			/* Send incoming SeND-protected/ND packet to user space. */
 			if (send_sendso_input_hook != NULL) {
-				error = send_sendso_input_hook(m,
+				error = send_sendso_input_hook(m, ifp,
 				    SND_IN, ip6len);
 				if (error == 0)
 					return (IPPROTO_DONE);
@@ -885,7 +885,7 @@
 			goto freeit;
 		}
 		if (send_sendso_input_hook != NULL) {
-			error = send_sendso_input_hook(n,
+			error = send_sendso_input_hook(n, ifp,
 			    SND_IN, ip6len);
 			if (error == 0)
 				return (IPPROTO_DONE);
@@ -903,7 +903,7 @@
 			goto badlen;
 		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
 			if (send_sendso_input_hook != NULL) {
-				error = send_sendso_input_hook(m,
+				error = send_sendso_input_hook(m, ifp,
 				    SND_IN, ip6len);
 		 		if (error == 0)
 					return (IPPROTO_DONE);
@@ -915,7 +915,7 @@
 			goto freeit;
 		}
 		if (send_sendso_input_hook != NULL) {
-			error = send_sendso_input_hook(n,
+			error = send_sendso_input_hook(n, ifp,
 			    SND_IN, ip6len);
 			if (error == 0)
 				return (IPPROTO_DONE);

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

@@ -122,7 +122,7 @@
 
 static struct sockaddr_in6 all1_sa;
 
-int	(*send_sendso_input_hook)(struct mbuf *, int, int);
+int	(*send_sendso_input_hook)(struct mbuf *, struct ifnet *, int, int);
 
 static int nd6_is_new_addr_neighbor __P((struct sockaddr_in6 *,
 	struct ifnet *));
@@ -1955,7 +1955,7 @@
 			ip6 = mtod(m, struct ip6_hdr *);
 			ip6len = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen);
 			/* Use the SEND socket */
-			error = send_sendso_input_hook(m, SND_OUT,
+			error = send_sendso_input_hook(m, ifp, SND_OUT,
 			    ip6len);
 			/* -1 == no app on SEND socket */
 			if (error == 0 || error != -1)

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


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


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

@@ -110,6 +110,8 @@
 	struct icmp6_hdr *icmp6;
 	int icmp6len;
 
+printf("XXX-AK: send_output \n");
+
 	/*
 	 * Receive incoming (SeND-protected) or outgoing traffic
 	 * (SeND-validated) from the SeND user space application.
@@ -163,6 +165,7 @@
 		return (0);
 
 	case SND_OUT:
+printf("XXX-AK: send_output SND_OUT \n");
 		if (m->m_len < sizeof(struct ip6_hdr)) {
 			m = m_pullup(m, sizeof(struct ip6_hdr));
 			if (!m)
@@ -210,6 +213,8 @@
 	struct ifnet *ifp;
 	int error;
 
+printf("XXX-AK: send_send \n");
+
 	KASSERT(V_send_so == so, ("%s: socket %p not send socket %p",
 		__func__, so, V_send_so));
 
@@ -246,7 +251,7 @@
  * daemon adding SeND ICMPv6 options.
  */
 static int
-send_input(struct mbuf *m, int direction, int msglen __unused)
+send_input(struct mbuf *m, struct ifnet *ifp, int direction, int msglen __unused)
 {
 	struct ip6_hdr *ip6;
 	struct sockaddr_send sendsrc;
@@ -270,7 +275,7 @@
 	sendsrc.send_len = sizeof(sendsrc);
 	sendsrc.send_family = AF_INET6;
 	sendsrc.send_direction = direction;
-	sendsrc.send_ifidx = -1;
+	sendsrc.send_ifidx = ifp->if_index;
 
 	/*
 	 * Send incoming or outgoing traffic to user space either to be

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

@@ -38,6 +38,6 @@
 	char			send_zero[8];
 };
 
-extern int (*send_sendso_input_hook)(struct mbuf *, int, int);
+extern int (*send_sendso_input_hook)(struct mbuf *, struct ifnet *, int, int);
 
 #endif /* _NETINET6_SEND_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008121056.o7CAuvAn098868>