summaryrefslogtreecommitdiffstats
path: root/bfdd
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2018-07-25 03:32:36 +0200
committerRafael Zalamena <rzalamena@opensourcerouting.org>2018-08-08 23:25:08 +0200
commit9d63adda98cfe267d357b005b0d41f0ea62f807a (patch)
treeee2df6add162e17e5b81470f9777db26802a93b7 /bfdd
parentbfdd: free zebra clients data on unregistration (diff)
downloadfrr-9d63adda98cfe267d357b005b0d41f0ea62f807a.tar.xz
frr-9d63adda98cfe267d357b005b0d41f0ea62f807a.zip
bfdd: code refactory for simplification
Simplify code and remove unnecessary log messages. The old log messages are going to be shown by the caller anyway. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'bfdd')
-rw-r--r--bfdd/bfd.c129
1 files changed, 26 insertions, 103 deletions
diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index d2aba178a..8592f6e3c 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -285,114 +285,37 @@ struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp, char *port_name,
struct bfd_session *l_bfd = NULL;
struct bfd_mhop_key mhop;
struct bfd_shop_key shop;
- char peer_addr[64];
- char local_addr[64];
- char vrf_name_buf[MAXNAMELEN + 1];
-
- /* peer, local are in network-byte order */
- strlcpy(peer_addr, satostr(peer), sizeof(peer_addr));
- strlcpy(local_addr, satostr(local), sizeof(local_addr));
-
- if (cp) {
- if (cp->discrs.remote_discr) {
- uint32_t ldisc = ntohl(cp->discrs.remote_discr);
- /* Your discriminator not zero - use it to find session
- */
- l_bfd = bfd_find_disc(peer, ldisc);
-
- if (l_bfd)
- return l_bfd;
-
- DLOG("Can't find session for yourDisc 0x%x from %s",
- ldisc, peer_addr);
- } else if (BFD_GETSTATE(cp->flags) == PTM_BFD_DOWN
- || BFD_GETSTATE(cp->flags) == PTM_BFD_ADM_DOWN) {
-
- if (is_mhop) {
- memset(&mhop, 0, sizeof(mhop));
- mhop.peer = *peer;
- mhop.local = *local;
- if (vrf_name && strlen(vrf_name)) {
- strlcpy(mhop.vrf_name, vrf_name,
- sizeof(mhop.vrf_name));
- } else if (port_name) {
- memset(vrf_name_buf, 0,
- sizeof(vrf_name_buf));
- if (ptm_bfd_get_vrf_name(port_name,
- vrf_name_buf)
- != -1) {
- strlcpy(mhop.vrf_name,
- vrf_name_buf,
- sizeof(mhop.vrf_name));
- }
- }
-
- /* Your discriminator zero -
- * use peer address and local address to
- * find session
- */
- l_bfd = bfd_mhop_lookup(mhop);
- } else {
- memset(&shop, 0, sizeof(shop));
- shop.peer = *peer;
- if (strlen(port_name))
- strlcpy(shop.port_name, port_name,
- sizeof(shop.port_name));
- /* Your discriminator zero -
- * use peer address and port to find
- * session
- */
- l_bfd = bfd_shop_lookup(shop);
- }
- if (l_bfd) {
- /* XXX maybe remoteDiscr should be checked for
- * remoteHeard cases
- */
- return l_bfd;
- }
- }
- if (is_mhop)
- DLOG("Can't find multi hop session peer/local %s/%s in vrf %s port %s",
- peer_addr, local_addr,
- strlen(mhop.vrf_name) ? mhop.vrf_name : "N/A",
- port_name ? port_name : "N/A");
- else
- DLOG("Can't find single hop session for peer/port %s/%s",
- peer_addr, port_name);
- } else if (peer->sa_sin.sin_addr.s_addr
- || !IN6_IS_ADDR_UNSPECIFIED(&peer->sa_sin6.sin6_addr)) {
-
- if (is_mhop) {
- memset(&mhop, 0, sizeof(mhop));
- mhop.peer = *peer;
- mhop.local = *local;
- if (vrf_name && strlen(vrf_name))
- strlcpy(mhop.vrf_name, vrf_name,
- sizeof(mhop.vrf_name));
-
- l_bfd = bfd_mhop_lookup(mhop);
- } else {
- memset(&shop, 0, sizeof(shop));
- shop.peer = *peer;
- if (strlen(port_name)) {
- strlcpy(shop.port_name, port_name,
- sizeof(shop.port_name));
- }
-
- l_bfd = bfd_shop_lookup(shop);
- }
+ char vrf_buf[MAXNAMELEN];
- if (l_bfd) {
- /* XXX maybe remoteDiscr should be checked for
- * remoteHeard cases
- */
- return l_bfd;
+ /* Find our session using the ID signaled by the remote end. */
+ if (cp->discrs.remote_discr)
+ return bfd_find_disc(peer, ntohl(cp->discrs.remote_discr));
+
+ /* Search for session without using discriminator. */
+ if (is_mhop) {
+ memset(&mhop, 0, sizeof(mhop));
+ mhop.peer = *peer;
+ mhop.local = *local;
+ if (vrf_name && vrf_name[0]) {
+ strlcpy(mhop.vrf_name, vrf_name, sizeof(mhop.vrf_name));
+ } else if (port_name && port_name[0]) {
+ memset(vrf_buf, 0, sizeof(vrf_buf));
+ if (ptm_bfd_get_vrf_name(port_name, vrf_buf) != -1)
+ strlcpy(mhop.vrf_name, vrf_buf, sizeof(mhop.vrf_name));
}
- DLOG("Can't find session for peer %s", peer_addr);
+ l_bfd = bfd_mhop_lookup(mhop);
+ } else {
+ memset(&shop, 0, sizeof(shop));
+ shop.peer = *peer;
+ if (port_name && port_name[0])
+ strlcpy(shop.port_name, port_name, sizeof(shop.port_name));
+
+ l_bfd = bfd_shop_lookup(shop);
}
- return (NULL);
+ /* XXX maybe remoteDiscr should be checked for remoteHeard cases. */
+ return l_bfd;
}
#if 0 /* TODO VxLAN Support */