]> git.proxmox.com Git - mirror_frr.git/commitdiff
bfdd: use vrf api for creation socket with binding with vrf lite
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 25 Mar 2019 16:50:21 +0000 (17:50 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 7 May 2019 13:49:39 +0000 (15:49 +0200)
in the case vrf-lite is used, it is possible to call SO_BINDTODVICE, by
using vrf_socket() call.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bfdd/bfd.c
bfdd/bfd_packet.c
bfdd/bsd.c [deleted file]
bfdd/linux.c [deleted file]
bfdd/subdir.am

index 517fed1a418e5e1ac10dce13b449a016addca89c..4a1cad5266575f722af7ea54c25618e96338e28b 100644 (file)
@@ -1201,10 +1201,6 @@ int bs_observer_add(struct bfd_session *bs)
        if (bso->bso_isinterface)
                strlcpy(bso->bso_entryname, bs->key.ifname,
                        sizeof(bso->bso_entryname));
-       else
-               strlcpy(bso->bso_entryname, bs->key.vrfname,
-                       sizeof(bso->bso_entryname));
-
        /* Handle socket binding failures caused by missing local addresses. */
        if (bs->sock == -1) {
                bso->bso_isaddress = true;
index 5b7db4f70963b4c662376ba0d88149fd80d0b65b..7526ff633a10379e8da26c5ab06e1561d1416e09 100644 (file)
@@ -904,10 +904,17 @@ int bp_peer_socket(const struct bfd_session *bs)
        int sd, pcount;
        struct sockaddr_in sin;
        static int srcPort = BFD_SRCPORTINIT;
+       const char *device_to_bind = NULL;
+
+       if (bs->key.ifname[0])
+               device_to_bind = (const char *)bs->key.ifname;
+       else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
+           && bs->key.vrfname[0])
+               device_to_bind = (const char *)bs->key.vrfname;
 
        frr_elevate_privs(&bfdd_privs) {
                sd = vrf_socket(AF_INET, SOCK_DGRAM, PF_UNSPEC,
-                               bs->vrf->vrf_id, NULL);
+                               bs->vrf->vrf_id, device_to_bind);
        }
        if (sd == -1) {
                log_error("ipv4-new: failed to create socket: %s",
@@ -927,19 +934,6 @@ int bp_peer_socket(const struct bfd_session *bs)
                return -1;
        }
 
-       if (bs->key.ifname[0]) {
-               if (bp_bind_dev(sd, bs->key.ifname) != 0) {
-                       close(sd);
-                       return -1;
-               }
-       } else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
-                  && bs->key.vrfname[0]) {
-               if (bp_bind_dev(sd, bs->key.vrfname) != 0) {
-                       close(sd);
-                       return -1;
-               }
-       }
-
        /* Find an available source port in the proper range */
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
@@ -977,10 +971,17 @@ int bp_peer_socketv6(const struct bfd_session *bs)
        int sd, pcount;
        struct sockaddr_in6 sin6;
        static int srcPort = BFD_SRCPORTINIT;
+       const char *device_to_bind = NULL;
+
+       if (bs->key.ifname[0])
+               device_to_bind = (const char *)bs->key.ifname;
+       else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
+           && bs->key.vrfname[0])
+               device_to_bind = (const char *)bs->key.vrfname;
 
        frr_elevate_privs(&bfdd_privs) {
                sd = vrf_socket(AF_INET6, SOCK_DGRAM, PF_UNSPEC,
-                               bs->vrf->vrf_id, NULL);
+                               bs->vrf->vrf_id, device_to_bind);
        }
        if (sd == -1) {
                log_error("ipv6-new: failed to create socket: %s",
@@ -1010,19 +1011,6 @@ int bp_peer_socketv6(const struct bfd_session *bs)
        if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
                sin6.sin6_scope_id = bs->ifp->ifindex;
 
-       if (bs->key.ifname[0]) {
-               if (bp_bind_dev(sd, bs->key.ifname) != 0) {
-                       close(sd);
-                       return -1;
-               }
-       } else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
-                  && bs->key.vrfname[0]) {
-               if (bp_bind_dev(sd, bs->key.vrfname) != 0) {
-                       close(sd);
-                       return -1;
-               }
-       }
-
        pcount = 0;
        do {
                if ((++pcount) > (BFD_SRCPORTMAX - BFD_SRCPORTINIT)) {
diff --git a/bfdd/bsd.c b/bfdd/bsd.c
deleted file mode 100644 (file)
index 923fbd9..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * *BSD specific code
- *
- * Copyright (C) 2018 Network Device Education Foundation, Inc. ("NetDEF")
- *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with FRR; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <zebra.h>
-
-#ifdef BFD_BSD
-
-#include <net/if.h>
-#include <net/if_types.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <ifaddrs.h>
-
-#include "bfd.h"
-
-/*
- * Definitions.
- */
-int bp_bind_dev(int sd, const char *dev)
-{
-       /*
-        * *BSDs don't support `SO_BINDTODEVICE`, instead you must
-        * manually specify the main address of the interface or use
-        * BPF on the socket descriptor.
-        */
-       return 0;
-}
-
-#endif /* BFD_BSD */
diff --git a/bfdd/linux.c b/bfdd/linux.c
deleted file mode 100644 (file)
index 3a76b45..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Linux specific code
- *
- * Copyright (C) 2018 Network Device Education Foundation, Inc. ("NetDEF")
- *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with FRR; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <zebra.h>
-
-#ifdef BFD_LINUX
-
-#include "bfd.h"
-
-
-/*
- * Definitions.
- */
-int bp_bind_dev(int sd __attribute__((__unused__)),
-               const char *dev __attribute__((__unused__)))
-{
-       /*
-        * TODO: implement this differently. It is not possible to
-        * SO_BINDTODEVICE after the daemon has dropped its privileges.
-        */
-#if 0
-       size_t devlen = strlen(dev) + 1;
-
-       if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, dev, devlen) == -1) {
-               log_warning("%s: setsockopt(SO_BINDTODEVICE, \"%s\"): %s",
-                           __func__, dev, strerror(errno));
-               return -1;
-       }
-#endif
-
-       return 0;
-}
-
-#endif /* BFD_LINUX */
index 334e974b048a9eb1676666b4e63c8eaa65e3d97c..e88b982ec3bfcc5d9260d936f7536a613040cb95 100644 (file)
@@ -14,11 +14,9 @@ bfdd_libbfd_a_SOURCES = \
        bfdd/bfd.c \
        bfdd/bfdd_vty.c \
        bfdd/bfd_packet.c \
-       bfdd/bsd.c \
        bfdd/config.c \
        bfdd/control.c \
        bfdd/event.c \
-       bfdd/linux.c \
        bfdd/log.c \
        bfdd/ptm_adapter.c \
        # end