Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ldpd allow setting transport addresses for interfac...



details:   https://anonhg.NetBSD.org/src/rev/5157ff28fbfe
branches:  trunk
changeset: 790559:5157ff28fbfe
user:      kefren <kefren%NetBSD.org@localhost>
date:      Thu Oct 17 18:10:23 2013 +0000

description:
allow setting transport addresses for interfaces into config file
also move passive-interface functionality under interface block
report the correct line for config parsing errors

diffstat:

 usr.sbin/ldpd/conffile.c  |  92 ++++++++++++++++++++++++++++++++++++++--------
 usr.sbin/ldpd/conffile.h  |  10 +++--
 usr.sbin/ldpd/socketops.c |  21 ++++++++--
 3 files changed, 99 insertions(+), 24 deletions(-)

diffs (243 lines):

diff -r 9d0f60bfe401 -r 5157ff28fbfe usr.sbin/ldpd/conffile.c
--- a/usr.sbin/ldpd/conffile.c  Thu Oct 17 18:04:40 2013 +0000
+++ b/usr.sbin/ldpd/conffile.c  Thu Oct 17 18:10:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */
+/* $NetBSD: conffile.c,v 1.7 2013/10/17 18:10:23 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -63,13 +63,21 @@
 static int Gneighbour(struct conf_neighbour *, char *);
 static int Fnodefault(char*);
 static int Floopdetection(char*);
-static int Fpassiveif(char*);
+static int Finterface(char*);
+static int Ginterface(struct conf_interface *, char *);
+static int Ipassive(struct conf_interface *, char *);
+static int Itaddr(struct conf_interface *, char *);
 
 struct conf_func {
        char com[64];
        int (* func)(char *);
 };
 
+struct intf_func {
+       char com[64];
+       int (* func)(struct conf_interface *, char *);
+};
+
 struct conf_func main_commands[] = {
        { "hello-time", Fhellotime },
        { "keepalive-time", Fkeepalive },
@@ -77,26 +85,33 @@
        { "command-port", Fport },
        { "min-label", Fminlabel },
        { "max-label", Fmaxlabel },
-       { "LDP-ID", Fldpid },
+       { "ldp-id", Fldpid },
        { "neighbor", Fneighbour },
        { "neighbour", Fneighbour },
        { "no-default-route", Fnodefault },
        { "loop-detection", Floopdetection },
-       { "passive-if", Fpassiveif },
+       { "interface", Finterface },
        { "", NULL },
 };
 
+struct intf_func intf_commands[] = {
+       { "passive", Ipassive },
+       { "transport-address", Itaddr },
+       { "", NULL },
+};
+
+static int parseline;
+
 /*
  * Parses config file
  */
 int
 conf_parsefile(const char *fname)
 {
-       int i;
        char buf[LINEMAXSIZE + 1];
 
        SLIST_INIT(&conei_head);
-       SLIST_INIT(&passifs_head);
+       SLIST_INIT(&coifs_head);
        conf_ldp_id.s_addr = 0;
 
        confh = open(fname, O_RDONLY, 0);
@@ -104,10 +119,10 @@
        if (confh == -1)
                return E_CONF_IO;
 
-       for (i = 1; conf_readline(buf, sizeof(buf)) >= 0; i++)
+       for (parseline = 1; conf_readline(buf, sizeof(buf)) >= 0; parseline++)
                if (conf_dispatch(buf) != 0) {
                        close(confh);
-                       return i;
+                       return parseline;
                }
 
        close(confh);
@@ -155,7 +170,7 @@
        command = NextCommand(nline);
        for (i = 0; main_commands[i].func != NULL; i++)
                if (strncasecmp(main_commands[i].com, command,
-                   strlen(command)) == 0) {
+                   strlen(main_commands[i].com)) == 0) {
                        matched++;
                        last_match = i;
                }
@@ -287,6 +302,7 @@
        SLIST_INSERT_HEAD(&conei_head, nei, neilist);
 
        while (conf_readline(buf, sizeof(buf)) >= 0) {
+               parseline++;
                if (buf[0] == '}')
                        return 0;
                if (Gneighbour(nei, buf) == -1)
@@ -328,15 +344,59 @@
        return 0;
 }
 
+/*
+ * Interface sub-commands
+ */
 int
-Fpassiveif(char *line)
+Finterface(char *line)
 {
-       struct passive_if *pif;
+       char *ifname;
+       struct conf_interface *conf_if = calloc(1, sizeof(*conf_if));
+       char buf[1024];
+
+       ifname = NextCommand(line);
+       if (conf_if == NULL || ifname == NULL)
+               return -1;
+       strlcpy(conf_if->if_name, ifname, IF_NAMESIZE);
+       SLIST_INSERT_HEAD(&coifs_head, conf_if, iflist);
 
-       if (strlen(line) > IF_NAMESIZE - 1)
-               return E_CONF_PARAM;
-       pif = calloc(1, sizeof(*pif));
-       strlcpy(pif->if_name, line, IF_NAMESIZE);
-       SLIST_INSERT_HEAD(&passifs_head, pif, listentry);
+       while (conf_readline(buf, sizeof(buf)) >= 0) {
+               parseline++;
+               if (buf[0] == '}')
+                       return 0;
+               if (Ginterface(conf_if, buf) == -1)
+                       return -1;
+       }
+       return -1;
+}
+
+int
+Ginterface(struct conf_interface *conf_if, char *buf)
+{
+       int i;
+
+       for (i = 0; intf_commands[i].func != NULL; i++)
+               if (strncasecmp(buf, intf_commands[i].com,
+                   strlen(intf_commands[i].com)) == 0)
+                       return intf_commands[i].func(conf_if, buf +
+                           strlen(intf_commands[i].com) + 1);
+       /* command not found */
+       return -1;
+}
+
+/* sets transport address */
+int
+Itaddr(struct conf_interface *conf_if, char *buf)
+{
+       if (inet_pton(AF_INET, buf, &conf_if->tr_addr) != 1)
+               return -1;
        return 0;
 }
+
+/* sets passive-interface on */
+int
+Ipassive(struct conf_interface *conf_if, char *buf)
+{
+       conf_if->passive = 1;
+       return 0;
+}
diff -r 9d0f60bfe401 -r 5157ff28fbfe usr.sbin/ldpd/conffile.h
--- a/usr.sbin/ldpd/conffile.h  Thu Oct 17 18:04:40 2013 +0000
+++ b/usr.sbin/ldpd/conffile.h  Thu Oct 17 18:10:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.h,v 1.3 2013/07/11 10:46:19 kefren Exp $ */
+/* $NetBSD: conffile.h,v 1.4 2013/10/17 18:10:23 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -51,11 +51,13 @@
 };
 SLIST_HEAD(,conf_neighbour) conei_head;
 
-struct passive_if {
+struct conf_interface {
        char if_name[IF_NAMESIZE];
-       SLIST_ENTRY(passive_if) listentry;
+       struct in_addr tr_addr;
+       int passive;
+       SLIST_ENTRY(conf_interface) iflist;
 };
-SLIST_HEAD(,passive_if) passifs_head;
+SLIST_HEAD(,conf_interface) coifs_head;
 
 int conf_parsefile(const char *fname);
 
diff -r 9d0f60bfe401 -r 5157ff28fbfe usr.sbin/ldpd/socketops.c
--- a/usr.sbin/ldpd/socketops.c Thu Oct 17 18:04:40 2013 +0000
+++ b/usr.sbin/ldpd/socketops.c Thu Oct 17 18:10:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.31 2013/07/27 14:35:41 kefren Exp $ */
+/* $NetBSD: socketops.c,v 1.32 2013/10/17 18:10:23 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -287,10 +287,11 @@
 static int
 is_passive_if(const char *if_name)
 {
-       struct passive_if *pif;
+       struct conf_interface *coif;
 
-       SLIST_FOREACH(pif, &passifs_head, listentry)
-               if (strncasecmp(if_name, pif->if_name, IF_NAMESIZE) == 0)
+       SLIST_FOREACH(coif, &coifs_head, iflist)
+               if (strncasecmp(if_name, coif->if_name, IF_NAMESIZE) == 0 &&
+                   coif->passive != 0)
                        return 1;
        return 0;
 }
@@ -408,6 +409,8 @@
        int ip4socket = -1;
        uint lastifindex;
        struct hello_socket *hs;
+       struct conf_interface *coif;
+       bool bad_tr_addr;
 #ifdef INET6
        struct sockaddr_in6 sadest6;
        int ip6socket = -1;
@@ -502,6 +505,16 @@
                /* Send only once per interface, using primary address */
                if (lastifindex == if_nametoindex(ifb->ifa_name))
                        continue;
+               /* Check if there is transport address set for this interface */
+               bad_tr_addr = false;
+               SLIST_FOREACH(coif, &coifs_head, iflist)
+                       if (strncasecmp(coif->if_name, ifb->ifa_name,
+                           IF_NAMESIZE) == 0 &&
+                           coif->tr_addr.s_addr != 0 &&
+                           coif->tr_addr.s_addr != if_sa->sin_addr.s_addr)
+                               bad_tr_addr = true;
+               if (bad_tr_addr == true)
+                       continue;
                lastifindex = if_nametoindex(ifb->ifa_name);
 
                if (setsockopt(ip4socket, IPPROTO_IP, IP_MULTICAST_IF,



Home | Main Index | Thread Index | Old Index