diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2019-03-25 17:50:21 +0100 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2019-05-07 15:49:39 +0200 |
commit | 1f4b73e54cd3961750a8747ad11afbd237df33b0 (patch) | |
tree | e9de2712d7c82297db57e11b85df8cd3ccf03bb7 /bfdd/bfd_packet.c | |
parent | lib: perform a bind inside vrf_socket() call (diff) | |
download | frr-1f4b73e54cd3961750a8747ad11afbd237df33b0.tar.xz frr-1f4b73e54cd3961750a8747ad11afbd237df33b0.zip |
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>
Diffstat (limited to 'bfdd/bfd_packet.c')
-rw-r--r-- | bfdd/bfd_packet.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index 5b7db4f70..7526ff633 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)) { |