summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2019-03-25 17:50:21 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2019-05-07 15:49:39 +0200
commit1f4b73e54cd3961750a8747ad11afbd237df33b0 (patch)
treee9de2712d7c82297db57e11b85df8cd3ccf03bb7
parent91f854f62a204c6440b5e13f8e959450869f494b (diff)
bfdd: use vrf api for creation socket with binding with vrf lite
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>
-rw-r--r--bfdd/bfd.c4
-rw-r--r--bfdd/bfd_packet.c44
-rw-r--r--bfdd/bsd.c48
-rw-r--r--bfdd/linux.c52
-rw-r--r--bfdd/subdir.am2
5 files changed, 16 insertions, 134 deletions
diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index 517fed1a41..4a1cad5266 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -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;
diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c
index 5b7db4f709..7526ff633a 100644
--- a/bfdd/bfd_packet.c
+++ b/bfdd/bfd_packet.c
@@ -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
index 923fbd909e..0000000000
--- a/bfdd/bsd.c
+++ /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
index 3a76b459d7..0000000000
--- a/bfdd/linux.c
+++ /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 */
diff --git a/bfdd/subdir.am b/bfdd/subdir.am
index 334e974b04..e88b982ec3 100644
--- a/bfdd/subdir.am
+++ b/bfdd/subdir.am
@@ -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