diff options
| author | kefren <kefren@NetBSD.org> | 2013-10-17 18:10:23 +0000 |
|---|---|---|
| committer | kefren <kefren@NetBSD.org> | 2013-10-17 18:10:23 +0000 |
| commit | efed389d5be73525d06660b141d724afcfbeeeb1 (patch) | |
| tree | ca82a938ca8cf512c5824087690829daa4cfe26d /usr.sbin/ldpd | |
| parent | ebbd33874bed683de9dc95e74f1c1c0303e407f3 (diff) | |
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 (limited to 'usr.sbin/ldpd')
| -rw-r--r-- | usr.sbin/ldpd/conffile.c | 92 | ||||
| -rw-r--r-- | usr.sbin/ldpd/conffile.h | 10 | ||||
| -rw-r--r-- | usr.sbin/ldpd/socketops.c | 21 |
3 files changed, 99 insertions, 24 deletions
diff --git a/usr.sbin/ldpd/conffile.c b/usr.sbin/ldpd/conffile.c index 3b28e2903be..ebc39413591 100644 --- a/usr.sbin/ldpd/conffile.c +++ b/usr.sbin/ldpd/conffile.c @@ -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 Fneighbour(char*); 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 @@ struct conf_func main_commands[] = { { "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 @@ conf_parsefile(const char *fname) 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 @@ conf_dispatch(char *line) 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 @@ Fneighbour(char *line) 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 @@ Floopdetection(char *line) 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]; - 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); + 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); + + 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 --git a/usr.sbin/ldpd/conffile.h b/usr.sbin/ldpd/conffile.h index a30d3967001..06b6a479b01 100644 --- a/usr.sbin/ldpd/conffile.h +++ b/usr.sbin/ldpd/conffile.h @@ -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 @@ struct conf_neighbour { }; 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 --git a/usr.sbin/ldpd/socketops.c b/usr.sbin/ldpd/socketops.c index 216595c048c..81344847665 100644 --- a/usr.sbin/ldpd/socketops.c +++ b/usr.sbin/ldpd/socketops.c @@ -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 @@ is_hello_socket(int s) 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 @@ send_hello(void) 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_hello(void) /* 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, |
