+// SPDX-License-Identifier: GPL-2.0-or-later
/*********************************************************************
* Copyright 2017 Cumulus Networks, Inc. All rights reserved.
*
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
* bfd_packet.c: implements the BFD protocol packet handling.
*
* Authors
memcpy(&ttlval, CMSG_DATA(cm), sizeof(ttlval));
if (ttlval > 255) {
if (bglobal.debug_network)
- zlog_debug("ipv4-recv: invalid TTL: %u",
- ttlval);
+ zlog_debug("%s: invalid TTL: %u",
+ __func__, ttlval);
return -1;
}
*ttl = ttlval;
memcpy(&ttlval, CMSG_DATA(cm), sizeof(ttlval));
if (ttlval > 255) {
if (bglobal.debug_network)
- zlog_debug("ipv6-recv: invalid TTL: %u",
- ttlval);
+ zlog_debug("%s: invalid TTL: %u",
+ __func__, ttlval);
return -1;
}
}
}
+PRINTFRR(6, 7)
static void cp_debug(bool mhop, struct sockaddr_any *peer,
struct sockaddr_any *local, ifindex_t ifindex,
vrf_id_t vrfid, const char *fmt, ...)
/* Implement RFC 5880 6.8.6 */
if (mlen < BFD_PKT_LEN) {
cp_debug(is_mhop, &peer, &local, ifindex, vrfid,
- "too small (%ld bytes)", mlen);
+ "too small (%zd bytes)", mlen);
return;
}
"no session found");
return;
}
+ /*
+ * We may have a situation where received packet is on wrong vrf
+ */
+ if (bfd && bfd->vrf && bfd->vrf != bvrf->vrf) {
+ cp_debug(is_mhop, &peer, &local, ifindex, vrfid,
+ "wrong vrfid.");
+ return;
+ }
/* Ensure that existing good sessions are not overridden. */
if (!cp->discrs.remote_discr && bfd->ses_state != PTM_BFD_DOWN &&
if (wlen <= 0) {
if (bglobal.debug_network)
- zlog_debug("udp-send: loopback failure: (%d) %s", errno,
- strerror(errno));
+ zlog_debug("%s: loopback failure: (%d) %s", __func__,
+ errno, strerror(errno));
return -1;
} else if (wlen < (ssize_t)datalen) {
if (bglobal.debug_network)
- zlog_debug("udp-send: partial send: %zd expected %zu",
- wlen, datalen);
+ zlog_debug("%s: partial send: %zd expected %zu",
+ __func__, wlen, datalen);
return -1;
}
wlen = sendmsg(sd, &msg, 0);
if (wlen <= 0) {
if (bglobal.debug_network)
- zlog_debug("udp-send: loopback failure: (%d) %s", errno,
- strerror(errno));
+ zlog_debug("%s: loopback failure: (%d) %s", __func__,
+ errno, strerror(errno));
return -1;
} else if (wlen < (ssize_t)datalen) {
if (bglobal.debug_network)
- zlog_debug("udp-send: partial send: %zd expected %zu",
- wlen, datalen);
+ zlog_debug("%s: partial send: %zd expected %zu",
+ __func__, wlen, datalen);
return -1;
}
int ttl = value;
if (setsockopt(sd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) == -1) {
- zlog_warn("set-ttl: setsockopt(IP_TTL, %d): %s", value,
+ zlog_warn("%s: setsockopt(IP_TTL, %d): %s", __func__, value,
strerror(errno));
return -1;
}
int tos = value;
if (setsockopt(sd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1) {
- zlog_warn("set-tos: setsockopt(IP_TOS, %d): %s", value,
+ zlog_warn("%s: setsockopt(IP_TOS, %d): %s", __func__, value,
strerror(errno));
return -1;
}
return 0;
}
+static bool bp_set_reuse_addr(int sd)
+{
+ int one = 1;
+
+ if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
+ zlog_warn("%s: setsockopt(SO_REUSEADDR, %d): %s", __func__, one,
+ strerror(errno));
+ return false;
+ }
+ return true;
+}
+
+static bool bp_set_reuse_port(int sd)
+{
+ int one = 1;
+
+ if (setsockopt(sd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1) {
+ zlog_warn("%s: setsockopt(SO_REUSEPORT, %d): %s", __func__, one,
+ strerror(errno));
+ return false;
+ }
+ return true;
+}
+
+
static void bp_set_ipopts(int sd)
{
int rcvttl = BFD_RCV_TTL_VAL;
+ if (!bp_set_reuse_addr(sd))
+ zlog_fatal("set-reuse-addr: failed");
+
+ if (!bp_set_reuse_port(sd))
+ zlog_fatal("set-reuse-port: failed");
+
if (bp_set_ttl(sd, BFD_TTL_VAL) != 0)
zlog_fatal("set-ipopts: TTL configuration failed");
sin.sin_len = sizeof(sin);
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
memcpy(&sin.sin_addr, &bs->key.local, sizeof(sin.sin_addr));
- if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) == 0)
- sin.sin_addr.s_addr = INADDR_ANY;
pcount = 0;
do {
int ipv6_pktinfo = BFD_IPV6_PKT_INFO_VAL;
int ipv6_only = BFD_IPV6_ONLY_VAL;
+ if (!bp_set_reuse_addr(sd))
+ zlog_fatal("set-reuse-addr: failed");
+
+ if (!bp_set_reuse_port(sd))
+ zlog_fatal("set-reuse-port: failed");
+
if (bp_set_ttlv6(sd, BFD_TTL_VAL) == -1)
zlog_fatal(
"set-ipv6opts: setsockopt(IPV6_UNICAST_HOPS, %d): %s",
if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET))
return;
+ if (ifp->flags & IFF_NOARP)
+ return;
if (peer->sa_sin.sin_family == AF_INET) {
/* IPV4 */
strlcpy(arpreq_.arp_dev, ifp->name, sizeof(arpreq_.arp_dev));
if (ioctl(sd, SIOCGARP, &arpreq_) < 0) {
- zlog_warn("BFD: getting peer's mac failed error %s",
- strerror(errno));
+ zlog_warn(
+ "BFD: getting peer's mac on %s failed error %s",
+ ifp->name, strerror(errno));
UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET);
memset(bfd->peer_hw_addr, 0, sizeof(bfd->peer_hw_addr));