Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ldpd * add no-default-route option into configurati...



details:   https://anonhg.NetBSD.org/src/rev/5369a99fdedf
branches:  trunk
changeset: 766051:5369a99fdedf
user:      kefren <kefren%NetBSD.org@localhost>
date:      Tue Jun 14 11:28:51 2011 +0000

description:
* 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

diffstat:

 usr.sbin/ldpd/conffile.c       |  16 ++++++++++++++--
 usr.sbin/ldpd/ldp_errors.h     |   3 ++-
 usr.sbin/ldpd/main.c           |   6 +++---
 usr.sbin/ldpd/mpls_interface.c |  10 +++++++---
 usr.sbin/ldpd/mpls_routes.c    |  15 +++++++++++----
 usr.sbin/ldpd/socketops.c      |  31 ++++++++++++++++++++++---------
 usr.sbin/ldpd/socketops.h      |   4 ++--
 7 files changed, 61 insertions(+), 24 deletions(-)

diffs (299 lines):

diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/conffile.c
--- a/usr.sbin/ldpd/conffile.c  Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/conffile.c  Tue Jun 14 11:28:51 2011 +0000
@@ -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 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 @@
        { "LDP-ID", Fldpid },
        { "neighbor", Fneighbour },
        { "neighbour", Fneighbour },
+       { "no-default-route", Fnodefault },
        { "", NULL },
 };
 
@@ -300,3 +302,13 @@
        }
        return -1;
 }
+
+int
+Fnodefault(char *line)
+{
+       int nd = atoi(line);
+       if (nd < 0)
+               return E_CONF_PARAM;
+       no_default_route = nd;
+       return 0;
+}
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/ldp_errors.h
--- a/usr.sbin/ldpd/ldp_errors.h        Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/ldp_errors.h        Tue Jun 14 11:28:51 2011 +0000
@@ -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);
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/main.c
--- a/usr.sbin/ldpd/main.c      Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/main.c      Tue Jun 14 11:28:51 2011 +0000
@@ -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 @@
        }
 
        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");
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/mpls_interface.c
--- a/usr.sbin/ldpd/mpls_interface.c    Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/mpls_interface.c    Tue Jun 14 11:28:51 2011 +0000
@@ -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 @@
        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 @@
                                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)
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/mpls_routes.c
--- a/usr.sbin/ldpd/mpls_routes.c       Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/mpls_routes.c       Tue Jun 14 11:28:51 2011 +0000
@@ -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 @@
 
        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 @@
                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 @@
                }
 
                /* 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 */
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/socketops.c
--- a/usr.sbin/ldpd/socketops.c Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/socketops.c Tue Jun 14 11:28:51 2011 +0000
@@ -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 @@
 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 @@
  * The big poll that catches every single event
  * on every socket.
  */
-void 
+int
 the_big_loop(void)
 {
        int             sock_error;
@@ -536,6 +538,8 @@
        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 @@
 
        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 @@
                /* 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 @@
                        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 @@
 
                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)
diff -r 9059b2be7e71 -r 5369a99fdedf usr.sbin/ldpd/socketops.h
--- a/usr.sbin/ldpd/socketops.h Tue Jun 14 11:23:02 2011 +0000
+++ b/usr.sbin/ldpd/socketops.h Tue Jun 14 11:28:51 2011 +0000
@@ -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_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 *);



Home | Main Index | Thread Index | Old Index