Module Name:    src
Committed By:   kefren
Date:           Thu Oct 17 18:10:23 UTC 2013

Modified Files:
        src/usr.sbin/ldpd: conffile.c conffile.h socketops.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/conffile.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/conffile.h
cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/ldpd/socketops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/conffile.c
diff -u src/usr.sbin/ldpd/conffile.c:1.6 src/usr.sbin/ldpd/conffile.c:1.7
--- src/usr.sbin/ldpd/conffile.c:1.6	Thu Jul 11 10:46:19 2013
+++ src/usr.sbin/ldpd/conffile.c	Thu Oct 17 18:10:23 2013
@@ -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;
 }

Index: src/usr.sbin/ldpd/conffile.h
diff -u src/usr.sbin/ldpd/conffile.h:1.3 src/usr.sbin/ldpd/conffile.h:1.4
--- src/usr.sbin/ldpd/conffile.h:1.3	Thu Jul 11 10:46:19 2013
+++ src/usr.sbin/ldpd/conffile.h	Thu Oct 17 18:10:23 2013
@@ -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);
 

Index: src/usr.sbin/ldpd/socketops.c
diff -u src/usr.sbin/ldpd/socketops.c:1.31 src/usr.sbin/ldpd/socketops.c:1.32
--- src/usr.sbin/ldpd/socketops.c:1.31	Sat Jul 27 14:35:41 2013
+++ src/usr.sbin/ldpd/socketops.c	Thu Oct 17 18:10:23 2013
@@ -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,

Reply via email to