PERFORCE change 167414 for review

Bjoern A. Zeeb bz at FreeBSD.org
Sun Aug 16 19:46:44 UTC 2009


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

Change 167414 by bz at bz_zoo on 2009/08/16 19:46:39

	 - sort includes
	 - make sre functions are defined before use to make the quieten
	   compiler warnings.
	 - save rtm_version, rtm_type and rtm_seq (direction) from the
	   ifan to be able to send it back with the rtm.
	 - remove a bit of dead code and polish debugging messages.

Affected files ...

.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#24 edit

Differences ...

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

@@ -30,28 +30,35 @@
  *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include <sys/param.h>
 #include <sys/types.h>
+#include <sys/mbuf.h>
 #include <sys/socket.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
+
 #include <arpa/inet.h>
-#include <netinet/in.h>
+
+#include <net/if.h>
 #include <net/route.h>
-#include <net/if.h>
+
 #include <netinet/in.h>
+
 #include <netinet6/send.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "config.h"
-#include <applog.h>
-#include <sbuff.h>
 
 #include "sendd_local.h"
 #include "os_specific.h"
 #include "snd_proto.h"
 #include "dbg.h"
 
+#include <applog.h>
+#include <sbuff.h>
+
 static int icmp6sock 	= -1;
 static int sndsock	= -1;
 
@@ -63,6 +70,25 @@
 static char abuf[INET6_ADDRSTRLEN];
 #endif
 
+/* Per-interface info */
+struct snd_ifinfo {
+	struct list_head list;
+	char		name[32];
+	int		ifidx;
+	int		snds;
+};
+static DEFINE_LIST_HEAD(ifaces);
+
+/* Data packet meta data */
+struct snd_packet_info {
+	struct snd_ifinfo *ifinfo;
+	u_char		rtm_version;
+        u_char		rtm_type;
+        int		rtm_seq;
+};
+
+void snd_sock_read(struct snd_ifinfo *p);
+
 /* TODO: dynamically size according to MTU */
 struct sbuff *
 snd_get_buf(void)
@@ -77,21 +103,6 @@
 	return (b);
 }
 
-/* Per-interface info */
-struct snd_ifinfo {
-	struct list_head list;
-	char		name[32];
-	int		ifidx;
-	int		snds;
-};
-static DEFINE_LIST_HEAD(ifaces);
-
-/* Data packet meta data */
-struct snd_packet_info {
-	struct snd_ifinfo *ifinfo;
-	int 		in;
-};
-
 void
 snd_dispatch_fds(fd_set *fds)
 {
@@ -131,14 +142,13 @@
 {
 	struct snd_packet_info *pi;
 	struct rt_msghdr *rtm;
-	struct ip6_hdr *ip6;
 
 	if (drop) {
 		snd_put_buf(b);
 		return;
 	}
 	pi = (struct snd_packet_info *)(b->head);
-	DBG(&dbg_snd, "Direction, in = %d", pi->in);
+	DBG(&dbg_snd, "Direction, %s", (pi->rtm_seq == RTM_SND_OUT) ? "SND_OUT" : "SND_IN");
 
 	DBG(&dbg_snd, "rt_msghdr = %d, if_announcemsghdr = %d\n", sizeof (struct rt_msghdr), sizeof (struct if_announcemsghdr));
 
@@ -156,8 +166,12 @@
 
 	/* reusing RTM header received from kernel */
 	rtm->rtm_msglen = b->len;
+	rtm->rtm_version = pi->rtm_version;
+        rtm->rtm_type = pi->rtm_type;
+	rtm->rtm_index = pi->ifinfo->ifidx;
+        rtm->rtm_seq = pi->rtm_seq;
+        rtm->rtm_pid = getpid();
 	rtm->rtm_addrs = 0;
-	rtm->rtm_index = pi->ifinfo->ifidx;
 
 	if (rtm->rtm_flags & M_MCAST)
 		DBG(&dbg_snd, "M_MCAST!");
@@ -279,39 +293,33 @@
 		DBG(&dbg_snd, "RTM_IFANNOUNCE");
 		break;
 	case RTM_SND:
-#if 0
-		ifan = sbuff_data(b);	
+		ifan = (struct if_announcemsghdr *)rtm;
+		pi->rtm_version = ifan->ifan_version;
+		pi->rtm_type = ifan->ifan_type;
+		pi->rtm_seq = ifan->ifan_what;
+
 		switch (ifan->ifan_what) {
-#endif
-		switch (rtm->rtm_seq) {
 		case RTM_SND_IN:
 			applog(LOG_ERR, "RTM_SND_IN");
 			/* n = RTM hdr + SEND message */
-			if (sbuff_pull(b, sizeof (struct rt_msghdr)) == NULL) {
-#if 0
 			if (sbuff_pull(b, sizeof (struct if_announcemsghdr)) == NULL) {
-#endif
-				DBG(&dbg_snd, "invalid pkt (not enough for rtm hedaer");				goto done;
+				DBG(&dbg_snd, "invalid pkt (not enough for rtm hedaer");
+				goto done;
 			}
 
 			pi->ifinfo = p;
-			pi->in = SND_IN;
 
 			snd_recv_pkt(b, p->ifidx, SND_IN);		
 			break;
 		case RTM_SND_OUT:
 			applog(LOG_ERR, "RTM_SND_OUT");
 			/* n = RTM hdr + ip6_hdr + icmp6len */
-			if (sbuff_pull(b, sizeof (struct rt_msghdr)) == NULL) {
-#if 0
 			if (sbuff_pull(b, sizeof (struct if_announcemsghdr)) == NULL) {
-#endif
 				DBG(&dbg_snd, "invalid pkt (not enough for rtm header");
 				goto done;
 			}
 
 			pi->ifinfo = p;
-			pi->in = SND_OUT;
 
 			snd_recv_pkt(b, p->ifidx, SND_OUT);
 			break;


More information about the p4-projects mailing list