Module Name:    src
Committed By:   kefren
Date:           Thu Jun 16 07:11:52 UTC 2011

Modified Files:
        src/usr.sbin/ldpd: mpls_routes.c

Log Message:
shorten some execution paths related to check_route() and get_route()
statify a bit
don't assume AF_INET in a debug message


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/mpls_routes.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/mpls_routes.c
diff -u src/usr.sbin/ldpd/mpls_routes.c:1.6 src/usr.sbin/ldpd/mpls_routes.c:1.7
--- src/usr.sbin/ldpd/mpls_routes.c:1.6	Tue Jun 14 11:28:51 2011
+++ src/usr.sbin/ldpd/mpls_routes.c	Thu Jun 16 07:11:51 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.c,v 1.6 2011/06/14 11:28:51 kefren Exp $ */
+/* $NetBSD: mpls_routes.c,v 1.7 2011/06/16 07:11:51 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -59,11 +59,12 @@
 int             rt_seq = 0;
 int		dont_catch = 0;
 extern int	no_default_route;
+extern int	debug_f, warn_f;
 
 struct rt_msg   replay_rt[REPLAY_MAX];
 int             replay_index = 0;
 
-int	read_route_socket(char *, int);
+static int read_route_socket(char *, int);
 void	mask_addr(union sockunion *);
 int	compare_sockunion(union sockunion *, union sockunion *);
 char *	mpls_ntoa(union mpls_shim);
@@ -79,7 +80,7 @@
 #define GETNEXT(sunion) \
 	(union sockunion *) ((char *) (sunion)  + RT_ROUNDUP((sunion)->sa.sa_len))
 
-int 
+static int 
 read_route_socket(char *s, int max)
 {
 	int             rv, to_read;
@@ -509,7 +510,7 @@
 		    rlen, l, strerror(errno));
 		return LDP_E_NO_SUCH_ROUTE;
 	} else
-		do {
+		for ( ; ; ) {
 			rlen = read_route_socket((char *) rg,
 			    sizeof(struct rt_msg));
 			if (rlen < 1)
@@ -519,27 +520,20 @@
 			 * For now I just try to save this messages and replay
 			 * them later
 			 */
-			if ((rg->m_rtm.rtm_pid != getpid()) ||
-			    (rg->m_rtm.rtm_seq != myseq)) {
-				/*
-				 * Shortcut: my pid but not
-				 * the expected sequence
-				 */
-				if (rg->m_rtm.rtm_pid == getpid())
-					continue;
-
-				debugp("Added to replay PID: %d, SEQ: %d\n",
-				    rg->m_rtm.rtm_pid, rg->m_rtm.rtm_seq);
-				memcpy(&replay_rt[replay_index], rg,
-				    sizeof(struct rt_msg));
-				if (replay_index < REPLAY_MAX - 1)
-					replay_index++;
-				continue;
-			}
-		} while ((rg->m_rtm.rtm_seq != myseq) ||
-			(rg->m_rtm.rtm_pid != getpid()));
+			if (rg->m_rtm.rtm_pid == getpid() &&
+			    rg->m_rtm.rtm_seq == myseq)
+				break;
+			debugp("Added to replay PID: %d, SEQ: %d\n",
+			    rg->m_rtm.rtm_pid, rg->m_rtm.rtm_seq);
+			memcpy(&replay_rt[replay_index], rg,
+			    sizeof(struct rt_msg));
+			if (replay_index < REPLAY_MAX - 1)
+				replay_index++;
+			else
+				fatalp("Replay index is full\n");
+		}
 
-	if ((uint)rlen <= sizeof(struct rt_msghdr)) {
+	if (rlen <= (int)sizeof(struct rt_msghdr)) {
 		debugp("Got only %d bytes, expecting at least %u\n", rlen,
 		    sizeof(struct rt_msghdr));
 		return LDP_E_ROUTE_ERROR;
@@ -681,6 +675,12 @@
 		break;
 	}
 
+	if (!debug_f && !warn_f) {
+		if(so_pref_allocated)
+			free(so_pref);
+		return LDP_E_OK;
+	}
+
 	/* Rest is just for debug */
 
 	if (so_dest)
@@ -880,8 +880,9 @@
 			so_pref = GETNEXT(so_dst);
 
 		if (so_gate->sa.sa_family == AF_MPLS) {
-			debugp("MPLS route to %s deleted.\n",
-			    inet_ntoa(so_dst->sin.sin_addr));
+			if (so_dst->sa.sa_family == AF_INET)
+				debugp("MPLS route to %s deleted.\n",
+				    inet_ntoa(so_dst->sin.sin_addr));
 			delete_route(so_dst, so_pref, NO_FREESO);
 			continue;
 		}

Reply via email to