* add no-default-route option into configuration file and check it before
rejecting default-route * exit process in case of error into the main loop * complete FSM for RTM_CHANGE * Check if we overflow pollfd array
This commit is contained in:
parent
298f340a61
commit
9b733c1c9d
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: conffile.c,v 1.2 2010/12/30 21:26:00 christos Exp $ */
|
||||
/* $NetBSD: conffile.c,v 1.3 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -45,7 +45,7 @@
|
|||
#define LINEMAXSIZE 1024
|
||||
|
||||
extern int ldp_hello_time, ldp_keepalive_time, ldp_holddown_time, command_port,
|
||||
min_label, max_label;
|
||||
min_label, max_label, no_default_route;
|
||||
int confh;
|
||||
struct in_addr conf_ldp_id;
|
||||
|
||||
|
@ -61,6 +61,7 @@ static int Fminlabel(char*);
|
|||
static int Fldpid(char*);
|
||||
static int Fneighbour(char*);
|
||||
static int Gneighbour(struct conf_neighbour *, char *);
|
||||
static int Fnodefault(char*);
|
||||
|
||||
struct conf_func {
|
||||
char com[64];
|
||||
|
@ -77,6 +78,7 @@ struct conf_func main_commands[] = {
|
|||
{ "LDP-ID", Fldpid },
|
||||
{ "neighbor", Fneighbour },
|
||||
{ "neighbour", Fneighbour },
|
||||
{ "no-default-route", Fnodefault },
|
||||
{ "", NULL },
|
||||
};
|
||||
|
||||
|
@ -300,3 +302,13 @@ Gneighbour(struct conf_neighbour *nei, char *line)
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Fnodefault(char *line)
|
||||
{
|
||||
int nd = atoi(line);
|
||||
if (nd < 0)
|
||||
return E_CONF_PARAM;
|
||||
no_default_route = nd;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ldp_errors.h,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
|
||||
/* $NetBSD: ldp_errors.h,v 1.2 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -47,6 +47,7 @@
|
|||
#define LDP_E_NO_BINDING 12
|
||||
#define LDP_E_TOO_MANY_LABELS 13
|
||||
#define LDP_E_INVAL 14
|
||||
#define LDP_E_TOO_MANY_FDS 15
|
||||
#define LDP_E_GENERIC 255
|
||||
|
||||
void printtime(void);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.4 2010/12/31 06:16:17 wiz Exp $ */
|
||||
/* $NetBSD: main.c,v 1.5 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -152,12 +152,12 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (dontfork == 1)
|
||||
the_big_loop();
|
||||
return the_big_loop();
|
||||
|
||||
forkres = fork();
|
||||
if (forkres == 0) {
|
||||
syslog_f = 1;
|
||||
the_big_loop();
|
||||
return the_big_loop();
|
||||
}
|
||||
if (forkres < 0)
|
||||
perror("fork");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mpls_interface.c,v 1.5 2011/02/09 11:38:57 kefren Exp $ */
|
||||
/* $NetBSD: mpls_interface.c,v 1.6 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -50,6 +50,8 @@
|
|||
#include "mpls_interface.h"
|
||||
#include "mpls_routes.h"
|
||||
|
||||
extern int no_default_route;
|
||||
|
||||
int
|
||||
mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
|
||||
struct in_addr * addr, int len, int label, int rlookup)
|
||||
|
@ -66,8 +68,8 @@ mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
|
|||
debugp("Trying to add %s/%d as label %d to peer %s\n", inet_ntoa(*addr),
|
||||
len, label, padd);
|
||||
|
||||
/* Don't accept default route XXX: should be option-able */
|
||||
if (!len)
|
||||
/* Check if we should accept default route */
|
||||
if (!len && no_default_route != 0)
|
||||
return LDP_E_BAD_AF;
|
||||
|
||||
/* Is there a label mapping for this ? */
|
||||
|
@ -92,6 +94,8 @@ mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
|
|||
debugp("No route for this prefix\n");
|
||||
return LDP_E_NO_SUCH_ROUTE;
|
||||
}
|
||||
if (kount > 0)
|
||||
debugp("Route test hit: %d\n", kount);
|
||||
kount++;
|
||||
/* Last time give it a higher chance */
|
||||
if (kount == rlookup)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mpls_routes.c,v 1.5 2011/02/14 11:43:59 kefren Exp $ */
|
||||
/* $NetBSD: mpls_routes.c,v 1.6 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -58,6 +58,7 @@
|
|||
extern int route_socket;
|
||||
int rt_seq = 0;
|
||||
int dont_catch = 0;
|
||||
extern int no_default_route;
|
||||
|
||||
struct rt_msg replay_rt[REPLAY_MAX];
|
||||
int replay_index = 0;
|
||||
|
@ -625,7 +626,13 @@ check_route(struct rt_msg * rg, uint rlen)
|
|||
|
||||
switch (rg->m_rtm.rtm_type) {
|
||||
case RTM_CHANGE:
|
||||
warnp("XXX: RTM_CHANGE\n");
|
||||
lab = label_get(so_dest, so_pref);
|
||||
if (lab) {
|
||||
send_withdraw_tlv_to_all(&so_dest->sin.sin_addr,
|
||||
prefixlen);
|
||||
label_reattach_route(lab, LDP_READD_NODEL);
|
||||
label_del(lab);
|
||||
}
|
||||
/* Fallthrough */
|
||||
case RTM_ADD:
|
||||
/*
|
||||
|
@ -668,7 +675,7 @@ check_route(struct rt_msg * rg, uint rlen)
|
|||
if (!lab)
|
||||
break;
|
||||
send_withdraw_tlv_to_all(&so_dest->sin.sin_addr, prefixlen);
|
||||
/* No readd as IPv4. Also don't even try to delete it */
|
||||
/* No readd or delete IP route. Just delete the MPLS route */
|
||||
label_reattach_route(lab, LDP_READD_NODEL);
|
||||
label_del(lab);
|
||||
break;
|
||||
|
@ -775,7 +782,7 @@ bind_current_routes()
|
|||
}
|
||||
|
||||
/* Check if it's the default gateway */
|
||||
if (so_dst->sin.sin_addr.s_addr == 0)
|
||||
if (so_dst->sin.sin_addr.s_addr == 0 && no_default_route != 0)
|
||||
continue;
|
||||
|
||||
/* XXX: Check if it's loopback */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: socketops.c,v 1.6 2011/05/24 13:03:19 joerg Exp $ */
|
||||
/* $NetBSD: socketops.c,v 1.7 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -37,14 +37,15 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fsm.h"
|
||||
#include "ldp.h"
|
||||
|
@ -72,6 +73,7 @@ extern struct com_sock csockets[MAX_COMMAND_SOCKETS];
|
|||
int ldp_hello_time = LDP_HELLO_TIME;
|
||||
int ldp_keepalive_time = LDP_KEEPALIVE_TIME;
|
||||
int ldp_holddown_time = LDP_HOLDTIME;
|
||||
int no_default_route = 1;
|
||||
|
||||
void recv_pdu(int);
|
||||
void send_hello_alarm(int);
|
||||
|
@ -526,7 +528,7 @@ bail_out(int x)
|
|||
* The big poll that catches every single event
|
||||
* on every socket.
|
||||
*/
|
||||
void
|
||||
int
|
||||
the_big_loop(void)
|
||||
{
|
||||
int sock_error;
|
||||
|
@ -536,6 +538,8 @@ the_big_loop(void)
|
|||
struct com_sock *cs;
|
||||
struct pollfd pfd[MAX_POLL_FDS];
|
||||
|
||||
assert(MAX_POLL_FDS > 3);
|
||||
|
||||
SLIST_INIT(&hello_info_head);
|
||||
|
||||
signal(SIGALRM, send_hello_alarm);
|
||||
|
@ -545,8 +549,11 @@ the_big_loop(void)
|
|||
|
||||
route_socket = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
|
||||
|
||||
if (bind_current_routes() != LDP_E_OK)
|
||||
sock_error = bind_current_routes();
|
||||
if (sock_error != LDP_E_OK) {
|
||||
fatalp("Cannot get current routes\n");
|
||||
return sock_error;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
nfds_t pollsum = 4;
|
||||
|
@ -571,6 +578,8 @@ the_big_loop(void)
|
|||
/* Command sockets */
|
||||
for (i=0; i < MAX_COMMAND_SOCKETS; i++)
|
||||
if (csockets[i].socket != -1) {
|
||||
if (pollsum >= MAX_POLL_FDS)
|
||||
break;
|
||||
pfd[pollsum].fd = csockets[i].socket;
|
||||
pfd[pollsum].events = POLLIN;
|
||||
pfd[pollsum].revents = 0;
|
||||
|
@ -584,12 +593,16 @@ the_big_loop(void)
|
|||
switch (p->state) {
|
||||
case LDP_PEER_CONNECTED:
|
||||
case LDP_PEER_ESTABLISHED:
|
||||
if (pollsum >= MAX_POLL_FDS)
|
||||
break;
|
||||
pfd[pollsum].fd = p->socket;
|
||||
pfd[pollsum].events = POLLRDNORM;
|
||||
pfd[pollsum].revents = 0;
|
||||
pollsum++;
|
||||
break;
|
||||
case LDP_PEER_CONNECTING:
|
||||
if (pollsum >= MAX_POLL_FDS)
|
||||
break;
|
||||
pfd[pollsum].fd = p->socket;
|
||||
pfd[pollsum].events = POLLWRNORM;
|
||||
pfd[pollsum].revents = 0;
|
||||
|
@ -600,7 +613,7 @@ the_big_loop(void)
|
|||
|
||||
if (pollsum >= MAX_POLL_FDS) {
|
||||
fatalp("Too many sockets. Increase MAX_POLL_FDS\n");
|
||||
return;
|
||||
return LDP_E_TOO_MANY_FDS;
|
||||
}
|
||||
if (poll(pfd, pollsum, INFTIM) < 0) {
|
||||
if (errno != EINTR)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: socketops.h,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
|
||||
/* $NetBSD: socketops.h,v 1.2 2011/06/14 11:28:51 kefren Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -50,7 +50,7 @@ int create_hello_socket(void);
|
|||
int create_listening_socket(void);
|
||||
void send_hello(void);
|
||||
int get_message_id(void);
|
||||
void the_big_loop(void);
|
||||
int the_big_loop(void);
|
||||
void new_peer_connection(void);
|
||||
void send_initialize(struct ldp_peer *);
|
||||
void keep_alive(struct ldp_peer *);
|
||||
|
|
Loading…
Reference in New Issue