shorten some execution paths related to check_route() and get_route()

statify a bit
don't assume AF_INET in a debug message
This commit is contained in:
kefren 2011-06-16 07:11:51 +00:00
parent 4671a6ac8d
commit 7102910ef8
1 changed files with 27 additions and 26 deletions

View File

@ -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 @@ extern int route_socket;
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 @@ extern struct sockaddr mplssockaddr;
#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 @@ get_route(struct rt_msg * rg, union sockunion * so_dest,
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 @@ get_route(struct rt_msg * rg, union sockunion * so_dest,
* 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 @@ check_route(struct rt_msg * rg, uint rlen)
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 @@ flush_mpls_routes()
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;
}