Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ldpd shorten some execution paths related to check_...
details: https://anonhg.NetBSD.org/src/rev/710fbe3e46c9
branches: trunk
changeset: 766124:710fbe3e46c9
user: kefren <kefren%NetBSD.org@localhost>
date: Thu Jun 16 07:11:51 2011 +0000
description:
shorten some execution paths related to check_route() and get_route()
statify a bit
don't assume AF_INET in a debug message
diffstat:
usr.sbin/ldpd/mpls_routes.c | 53 ++++++++++++++++++++++----------------------
1 files changed, 27 insertions(+), 26 deletions(-)
diffs (107 lines):
diff -r ef0753baf0d2 -r 710fbe3e46c9 usr.sbin/ldpd/mpls_routes.c
--- a/usr.sbin/ldpd/mpls_routes.c Thu Jun 16 06:05:47 2011 +0000
+++ b/usr.sbin/ldpd/mpls_routes.c Thu Jun 16 07:11:51 2011 +0000
@@ -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;
+ 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");
+ }
- 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 ((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;
}
Home |
Main Index |
Thread Index |
Old Index