]> git.proxmox.com Git - mirror_frr.git/blobdiff - bfdd/ptm_adapter.c
zebra: include lib/queue.h in zebra dataplane
[mirror_frr.git] / bfdd / ptm_adapter.c
index 9a2b70d36a64c7fa3b320c0d44f85b0f9b0dfa89..f9c7c16fb1349e860c981ba223ae8e4336ed6bc7 100644 (file)
@@ -155,6 +155,8 @@ int ptm_bfd_notify(struct bfd_session *bs)
        struct stream *msg;
        struct sockaddr_any sac;
 
+       bs->stats.znotification++;
+
        /*
         * Message format:
         * - header: command, vrf
@@ -274,7 +276,7 @@ static void _ptm_msg_read_address(struct stream *msg, struct sockaddr_any *sa)
                return;
 
        default:
-               log_warning("%s: invalid family: %d", __func__, family);
+               log_warning("ptm-read-address: invalid family: %d", family);
                break;
        }
 
@@ -287,7 +289,7 @@ static int _ptm_msg_read(struct stream *msg, int command,
 {
        uint32_t pid;
        uint8_t ttl __attribute__((unused));
-       uint8_t ifnamelen;
+       size_t ifnamelen;
 
        /*
         * Register/Deregister/Update Message format:
@@ -329,7 +331,7 @@ static int _ptm_msg_read(struct stream *msg, int command,
 
        *pc = pc_new(pid);
        if (*pc == NULL) {
-               log_debug("%s: failed to allocate memory", __func__);
+               log_debug("ptm-read: failed to allocate memory");
                return -1;
        }
 
@@ -370,8 +372,8 @@ static int _ptm_msg_read(struct stream *msg, int command,
                 * structure, otherwise fail.
                 */
                STREAM_GETC(msg, ifnamelen);
-               if (ifnamelen > sizeof(bpc->bpc_localif)) {
-                       log_error("%s: interface name is too big", __func__);
+               if (ifnamelen >= sizeof(bpc->bpc_localif)) {
+                       log_error("ptm-read: interface name is too big");
                        return -1;
                }
 
@@ -379,6 +381,21 @@ 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);
                }
        }
 
@@ -386,8 +403,7 @@ static int _ptm_msg_read(struct stream *msg, int command,
        if (bpc->bpc_local.sa_sin.sin_family != 0
            && (bpc->bpc_local.sa_sin.sin_family
                != bpc->bpc_peer.sa_sin.sin_family)) {
-               log_warning("%s: peer family doesn't match local type",
-                           __func__);
+               log_warning("ptm-read: peer family doesn't match local type");
                return -1;
        }
 
@@ -415,7 +431,7 @@ static void bfdd_dest_register(struct stream *msg)
        if (bs == NULL) {
                bs = ptm_bfd_sess_new(&bpc);
                if (bs == NULL) {
-                       log_debug("%s: failed to create BFD session", __func__);
+                       log_debug("ptm-add-dest: failed to create BFD session");
                        return;
                }
        } else {
@@ -428,7 +444,7 @@ static void bfdd_dest_register(struct stream *msg)
        /* Create client peer notification register. */
        pcn = pcn_new(pc, bs);
        if (pcn == NULL) {
-               log_error("%s: failed to registrate notifications", __func__);
+               log_error("ptm-add-dest: failed to registrate notifications");
                return;
        }
 
@@ -451,7 +467,7 @@ static void bfdd_dest_deregister(struct stream *msg)
        /* Find or start new BFD session. */
        bs = bs_peer_find(&bpc);
        if (bs == NULL) {
-               log_debug("%s: failed to create BFD session", __func__);
+               log_debug("ptm-del-dest: failed to find BFD session");
                return;
        }
 
@@ -474,14 +490,14 @@ static void bfdd_client_register(struct stream *msg)
 
        pc = pc_new(pid);
        if (pc == NULL) {
-               log_error("%s: failed to register client: %u", __func__, pid);
+               log_error("ptm-add-client: failed to register client: %u", pid);
                return;
        }
 
        return;
 
 stream_failure:
-       log_error("%s: failed to register client", __func__);
+       log_error("ptm-add-client: failed to register client");
 }
 
 /*
@@ -498,7 +514,7 @@ static void bfdd_client_deregister(struct stream *msg)
 
        pc = pc_lookup(pid);
        if (pc == NULL) {
-               log_debug("%s: failed to find client: %u", __func__, pid);
+               log_debug("ptm-del-client: failed to find client: %u", pid);
                return;
        }
 
@@ -507,7 +523,7 @@ static void bfdd_client_deregister(struct stream *msg)
        return;
 
 stream_failure:
-       log_error("%s: failed to deregister client", __func__);
+       log_error("ptm-del-client: failed to deregister client");
 }
 
 static int bfdd_replay(int cmd, struct zclient *zc, uint16_t len, vrf_id_t vid)
@@ -533,14 +549,14 @@ static int bfdd_replay(int cmd, struct zclient *zc, uint16_t len, vrf_id_t vid)
                break;
 
        default:
-               log_debug("%s: invalid message type %u", __func__, rcmd);
+               log_debug("ptm-replay: invalid message type %u", rcmd);
                return -1;
        }
 
        return 0;
 
 stream_failure:
-       log_error("%s: failed to find command", __func__);
+       log_error("ptm-replay: failed to find command");
        return -1;
 }
 
@@ -565,7 +581,7 @@ static void bfdd_zebra_connected(struct zclient *zc)
 
 void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv)
 {
-       zclient = zclient_new_notify(master, &zclient_options_default);
+       zclient = zclient_new(master, &zclient_options_default);
        assert(zclient != NULL);
        zclient_init(zclient, ZEBRA_ROUTE_BFD, 0, bfdd_priv);