mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 06:26:37 +00:00
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>
This commit is contained in:
parent
91f854f62a
commit
1f4b73e54c
@ -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;
|
||||
|
@ -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)) {
|
||||
|
48
bfdd/bsd.c
48
bfdd/bsd.c
@ -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 */
|
52
bfdd/linux.c
52
bfdd/linux.c
@ -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 */
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user