]> git.puffer.fish Git - mirror/frr.git/commitdiff
bfdd: remove scope-id from the session key 3948/head
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Thu, 14 Mar 2019 15:28:07 +0000 (12:28 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Thu, 14 Mar 2019 16:11:02 +0000 (13:11 -0300)
Unbreaks CLI ability to remove IPv6 sessions using link-local
addresses. This moves the scope-id logic to the packet sending
functions.

bfdd/bfd.c
bfdd/bfd_packet.c
bfdd/ptm_adapter.c

index 7ab71511a6880da0e6bd5eb6957a59aca26f9381..fc2d0bea9ce9f53b1ae83fd9652ce18fdc8b0c02 100644 (file)
@@ -261,6 +261,7 @@ static struct bfd_session *bfd_find_disc(struct sockaddr_any *sa,
                break;
        case AF_INET6:
                sa->sa_sin6.sin6_port = 0;
+               sa->sa_sin6.sin6_scope_id = 0;
                if (memcmp(sa, &bs->shop.peer, sizeof(sa->sa_sin6)) == 0)
                        return bs;
                break;
@@ -579,16 +580,9 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc)
                ptm_bfd_fetch_local_mac(bpc->bpc_localif, bfd->local_mac);
        }
 
-       if (bpc->bpc_ipv4 == false) {
+       if (bpc->bpc_ipv4 == false)
                BFD_SET_FLAG(bfd->flags, BFD_SESS_FLAG_IPV6);
 
-               /* Set the IPv6 scope id for link-local addresses. */
-               if (IN6_IS_ADDR_LINKLOCAL(&bpc->bpc_local.sa_sin6.sin6_addr))
-                       bpc->bpc_local.sa_sin6.sin6_scope_id = bfd->ifindex;
-               if (IN6_IS_ADDR_LINKLOCAL(&bpc->bpc_peer.sa_sin6.sin6_addr))
-                       bpc->bpc_peer.sa_sin6.sin6_scope_id = bfd->ifindex;
-       }
-
        /* Initialize the session */
        bfd->ses_state = PTM_BFD_DOWN;
        bfd->discrs.my_discr = ptm_bfd_gen_ID();
@@ -963,6 +957,7 @@ static void _shop_key(struct bfd_session *bs, const struct bfd_shop_key *shop)
                break;
        case AF_INET6:
                bs->shop.peer.sa_sin6.sin6_port = 0;
+               bs->shop.peer.sa_sin6.sin6_scope_id = 0;
                break;
        }
 }
@@ -985,7 +980,9 @@ static void _mhop_key(struct bfd_session *bs, const struct bfd_mhop_key *mhop)
                break;
        case AF_INET6:
                bs->mhop.peer.sa_sin6.sin6_port = 0;
+               bs->mhop.peer.sa_sin6.sin6_scope_id = 0;
                bs->mhop.local.sa_sin6.sin6_port = 0;
+               bs->mhop.local.sa_sin6.sin6_scope_id = 0;
                break;
        }
 }
index 606f739b4606a884c5e791883b7c0c1e4ad798c7..e602eb9bc24eeca16303a73fe9e6c8e06d0b42cf 100644 (file)
@@ -88,6 +88,9 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
                                         ? htons(BFD_DEF_MHOP_DEST_PORT)
                                         : htons(BFD_DEFDESTPORT);
 
+               if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
+                       sin6.sin6_scope_id = bs->ifindex;
+
                sd = bs->sock;
                sa = (struct sockaddr *)&sin6;
                slen = sizeof(sin6);
@@ -146,6 +149,8 @@ void ptm_bfd_echo_snd(struct bfd_session *bfd)
 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
                sin6.sin6_len = sizeof(sin6);
 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
+               if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
+                       sin6.sin6_scope_id = bfd->ifindex;
 
                sa = (struct sockaddr_any *)&sin6;
                salen = sizeof(sin6);
@@ -359,7 +364,6 @@ ssize_t bfd_recv_ipv6(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
 {
        struct cmsghdr *cm;
        struct in6_pktinfo *pi6 = NULL;
-       int ifindex = 0;
        ssize_t mlen;
        uint32_t ttlval;
        struct sockaddr_in6 msgaddr6;
@@ -415,17 +419,10 @@ ssize_t bfd_recv_ipv6(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
                                fetch_portname_from_ifindex(pi6->ipi6_ifindex,
                                                            port, portlen);
-                               ifindex = pi6->ipi6_ifindex;
                        }
                }
        }
 
-       /* Set scope ID for link local addresses. */
-       if (IN6_IS_ADDR_LINKLOCAL(&peer->sa_sin6.sin6_addr))
-               peer->sa_sin6.sin6_scope_id = ifindex;
-       if (IN6_IS_ADDR_LINKLOCAL(&local->sa_sin6.sin6_addr))
-               local->sa_sin6.sin6_scope_id = ifindex;
-
        return mlen;
 }
 
@@ -1046,7 +1043,7 @@ int bp_peer_socket(struct bfd_peer_cfg *bpc)
 
 int bp_peer_socketv6(struct bfd_peer_cfg *bpc)
 {
-       int sd, pcount, ifindex;
+       int sd, pcount;
        struct sockaddr_in6 sin6;
        static int srcPort = BFD_SRCPORTINIT;
 
@@ -1075,10 +1072,10 @@ int bp_peer_socketv6(struct bfd_peer_cfg *bpc)
 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
        sin6.sin6_len = sizeof(sin6);
 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
-       sin6 = bpc->bpc_local.sa_sin6;
-       ifindex = ptm_bfd_fetch_ifindex(bpc->bpc_localif);
+       memcpy(&sin6.sin6_addr, &bpc->bpc_local.sa_sin6.sin6_addr,
+              sizeof(sin6.sin6_addr));
        if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
-               sin6.sin6_scope_id = ifindex;
+               sin6.sin6_scope_id = ptm_bfd_fetch_ifindex(bpc->bpc_localif);
 
        if (bpc->bpc_has_localif) {
                if (bp_bind_dev(sd, bpc->bpc_localif) != 0) {
index f9c7c16fb1349e860c981ba223ae8e4336ed6bc7..a6be28dbd910c43983bfc4c8c356f7dea5dd1ff4 100644 (file)
@@ -381,21 +381,6 @@ static int _ptm_msg_read(struct stream *msg, int command,
                if (bpc->bpc_has_localif) {
                        STREAM_GET(bpc->bpc_localif, msg, ifnamelen);
                        bpc->bpc_localif[ifnamelen] = 0;
-
-                       /*
-                        * IPv6 link-local addresses must use scope id,
-                        * otherwise the session lookup will always fail
-                        * and we'll have multiple sessions showing up.
-                        *
-                        * This problem only happens with single hop
-                        * since it is not possible to have link-local
-                        * address for multi hop sessions.
-                        */
-                       if (bpc->bpc_ipv4 == false
-                           && IN6_IS_ADDR_LINKLOCAL(
-                                      &bpc->bpc_peer.sa_sin6.sin6_addr))
-                               bpc->bpc_peer.sa_sin6.sin6_scope_id =
-                                       ptm_bfd_fetch_ifindex(bpc->bpc_localif);
                }
        }