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 a new keyword for config file - passive-...



details:   https://anonhg.NetBSD.org/src/rev/9769f59d5dcf
branches:  trunk
changeset: 784366:9769f59d5dcf
user:      kefren <kefren%NetBSD.org@localhost>
date:      Sat Jan 26 21:07:49 2013 +0000

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

diffstat:

 usr.sbin/ldpd/conffile.c  |  18 +++++++++++++++++-
 usr.sbin/ldpd/conffile.h  |   8 +++++++-
 usr.sbin/ldpd/socketops.c |  33 ++++++++++++++++++++++++++++-----
 3 files changed, 52 insertions(+), 7 deletions(-)

diffs (171 lines):

diff -r 25a19cc7ccb0 -r 9769f59d5dcf usr.sbin/ldpd/conffile.c
--- a/usr.sbin/ldpd/conffile.c  Sat Jan 26 20:15:50 2013 +0000
+++ b/usr.sbin/ldpd/conffile.c  Sat Jan 26 21:07:49 2013 +0000
@@ -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 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 @@
        { "neighbour", Fneighbour },
        { "no-default-route", Fnodefault },
        { "loop-detection", Floopdetection },
+       { "passive-if", Fpassiveif },
        { "", NULL },
 };
 
@@ -94,6 +96,7 @@
        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 @@
        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;
+}
diff -r 25a19cc7ccb0 -r 9769f59d5dcf usr.sbin/ldpd/conffile.h
--- a/usr.sbin/ldpd/conffile.h  Sat Jan 26 20:15:50 2013 +0000
+++ b/usr.sbin/ldpd/conffile.h  Sat Jan 26 21:07:49 2013 +0000
@@ -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 @@
 };
 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);
 
diff -r 25a19cc7ccb0 -r 9769f59d5dcf usr.sbin/ldpd/socketops.c
--- a/usr.sbin/ldpd/socketops.c Sat Jan 26 20:15:50 2013 +0000
+++ b/usr.sbin/ldpd/socketops.c Sat Jan 26 21:07:49 2013 +0000
@@ -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 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 @@
                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 @@
                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 @@
        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 @@
        /* 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 @@
                    (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;
                /*



Home | Main Index | Thread Index | Old Index