Module Name:    src
Committed By:   kefren
Date:           Sat Jan 26 21:07:49 UTC 2013

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

Log Message:
 * add a new keyword for config file - passive-if and check if it's
   allowed to use the interface before join/send mcast
 * check if interface supports multicast before join/send mcast


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/conffile.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/conffile.h
cvs rdiff -u -r1.19 -r1.20 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.4 src/usr.sbin/ldpd/conffile.c:1.5
--- src/usr.sbin/ldpd/conffile.c:1.4	Mon Nov 12 18:39:00 2012
+++ src/usr.sbin/ldpd/conffile.c	Sat Jan 26 21:07:49 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.c,v 1.4 2012/11/12 18:39:00 kefren Exp $ */
+/* $NetBSD: conffile.c,v 1.5 2013/01/26 21:07:49 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -63,6 +63,7 @@ static int Fneighbour(char*);
 static int Gneighbour(struct conf_neighbour *, char *);
 static int Fnodefault(char*);
 static int Floopdetection(char*);
+static int Fpassiveif(char*);
 
 struct conf_func {
 	char com[64];
@@ -81,6 +82,7 @@ struct conf_func main_commands[] = {
 	{ "neighbour", Fneighbour },
 	{ "no-default-route", Fnodefault },
 	{ "loop-detection", Floopdetection },
+	{ "passive-if", Fpassiveif },
 	{ "", NULL },
 };
 
@@ -94,6 +96,7 @@ conf_parsefile(char *fname)
 	char buf[LINEMAXSIZE + 1];
 
 	SLIST_INIT(&conei_head);
+	SLIST_INIT(&passifs_head);
 	conf_ldp_id.s_addr = 0;
 
 	confh = open(fname, O_RDONLY, 0);
@@ -324,3 +327,16 @@ Floopdetection(char *line)
 	loop_detection = loopd;
 	return 0;
 }
+
+int
+Fpassiveif(char *line)
+{
+	struct passive_if *pif;
+
+	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);
+	return 0;
+}

Index: src/usr.sbin/ldpd/conffile.h
diff -u src/usr.sbin/ldpd/conffile.h:1.1 src/usr.sbin/ldpd/conffile.h:1.2
--- src/usr.sbin/ldpd/conffile.h:1.1	Thu Dec 30 11:29:21 2010
+++ src/usr.sbin/ldpd/conffile.h	Sat Jan 26 21:07:49 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.h,v 1.1 2010/12/30 11:29:21 kefren Exp $ */
+/* $NetBSD: conffile.h,v 1.2 2013/01/26 21:07:49 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
 #ifndef __CONFFILE_H
 #define __CONFFILE_H
 
+#include <net/if.h>
 #include <netinet/in.h>
 #include <sys/queue.h>
 
@@ -50,6 +51,11 @@ struct conf_neighbour {
 };
 SLIST_HEAD(,conf_neighbour) conei_head;
 
+struct passive_if {
+	char if_name[IF_NAMESIZE];
+	SLIST_ENTRY(passive_if) listentry;
+};
+SLIST_HEAD(,passive_if) passifs_head;
 
 int conf_parsefile(char *fname);
 

Index: src/usr.sbin/ldpd/socketops.c
diff -u src/usr.sbin/ldpd/socketops.c:1.19 src/usr.sbin/ldpd/socketops.c:1.20
--- src/usr.sbin/ldpd/socketops.c:1.19	Sat Jan 26 19:44:52 2013
+++ src/usr.sbin/ldpd/socketops.c	Sat Jan 26 21:07:49 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.19 2013/01/26 19:44:52 kefren Exp $ */
+/* $NetBSD: socketops.c,v 1.20 2013/01/26 21:07:49 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -47,6 +47,7 @@
 #include <strings.h>
 #include <unistd.h>
 
+#include "conffile.h"
 #include "fsm.h"
 #include "ldp.h"
 #include "ldp_command.h"
@@ -83,6 +84,7 @@ static int set_tos(int); 
 static int socket_reuse_port(int);
 static int get_local_addr(struct sockaddr_dl *, struct in_addr *);
 static int is_hello_socket(int);
+static int is_passive_if(char *if_name);
 
 int 
 create_hello_sockets()
@@ -134,7 +136,9 @@ create_hello_sockets()
 		struct sockaddr_in *if_sa = (struct sockaddr_in *) ifb->ifa_addr;
 		if (if_sa->sin_family != AF_INET || (!(ifb->ifa_flags & IFF_UP)) ||
 		    (ifb->ifa_flags & IFF_LOOPBACK) ||
+		    (!(ifb->ifa_flags & IFF_MULTICAST)) ||
 		    (ntohl(if_sa->sin_addr.s_addr) >> 24 == IN_LOOPBACKNET) ||
+		    is_passive_if(ifb->ifa_name) ||
 		    lastifindex == if_nametoindex(ifb->ifa_name))
 			continue;
 		lastifindex = if_nametoindex(ifb->ifa_name);
@@ -211,7 +215,9 @@ create_hello_sockets()
 		if_sa6 = (struct sockaddr_in6 *) ifb->ifa_addr;
 		if (if_sa6->sin6_family != AF_INET6 ||
 		    (!(ifb->ifa_flags & IFF_UP)) ||
+		    (!(ifb->ifa_flags & IFF_MULTICAST)) ||
 		    (ifb->ifa_flags & IFF_LOOPBACK) ||
+		    is_passive_if(ifb->ifa_name) ||
 		    IN6_IS_ADDR_LOOPBACK(&if_sa6->sin6_addr))
 			continue;
 		/*
@@ -275,6 +281,18 @@ is_hello_socket(int s)
 	return 0;
 }
 
+/* Check if interface is passive */
+static int
+is_passive_if(char *if_name)
+{
+	struct passive_if *pif;
+
+	SLIST_FOREACH(pif, &passifs_head, listentry)
+		if (strncasecmp(if_name, pif->if_name, IF_NAMESIZE) == 0)
+			return 1;
+	return 0;
+}
+
 /* Sets the TTL to 1 as we don't want to transmit outside this subnet */
 int
 set_ttl(int s)
@@ -471,10 +489,13 @@ send_hello(void)
 	/* Loop all interfaces in order to send IPv4 hellos */
 	for (ifb = ifa; ifb; ifb = ifb->ifa_next) {
 		if_sa = (struct sockaddr_in *) ifb->ifa_addr;
-		if (if_sa->sin_family != AF_INET)
-			continue;
-		if (ntohl(if_sa->sin_addr.s_addr) >> 24 == IN_LOOPBACKNET ||
-		    ntohl(if_sa->sin_addr.s_addr) >> 24 == 0)
+		if (if_sa->sin_family != AF_INET ||
+		    (!(ifb->ifa_flags & IFF_UP)) ||
+		    (ifb->ifa_flags & IFF_LOOPBACK) ||
+		    (!(ifb->ifa_flags & IFF_MULTICAST)) ||
+		    is_passive_if(ifb->ifa_name) ||
+		    (ntohl(if_sa->sin_addr.s_addr) >> 24 == IN_LOOPBACKNET) ||
+		    lastifindex == if_nametoindex(ifb->ifa_name))
 			continue;
 
 		/* Send only once per interface, using primary address */
@@ -529,7 +550,9 @@ send_hello(void)
 		    (struct sockaddr_in6 *) ifb->ifa_addr;
 		if (if_sa6->sin6_family != AF_INET6 ||
 		    (!(ifb->ifa_flags & IFF_UP)) ||
+		    (!(ifb->ifa_flags & IFF_MULTICAST)) ||
 		    (ifb->ifa_flags & IFF_LOOPBACK) ||
+		    is_passive_if(ifb->ifa_name) ||
 		    IN6_IS_ADDR_LOOPBACK(&if_sa6->sin6_addr))
 			continue;
 		/*

Reply via email to