]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zapi_msg.c
Merge pull request #4635 from AnuradhaKaruppiah/evpn-pim-replay
[mirror_frr.git] / zebra / zapi_msg.c
index 2f41f7133d8383280c8f863ca29d2207a7fe0f33..98bb2eda6046ca29c5d49a7070c78c47f7ec3c24 100644 (file)
@@ -57,7 +57,6 @@
 #include "zebra/rtadv.h"
 #include "zebra/zebra_mpls.h"
 #include "zebra/zebra_mroute.h"
-#include "zebra/label_manager.h"
 #include "zebra/zebra_vxlan.h"
 #include "zebra/rt.h"
 #include "zebra/zebra_pbr.h"
@@ -165,7 +164,7 @@ int zsend_interface_add(struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_ADD, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_ADD, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        client->ifadd_cnt++;
@@ -177,7 +176,7 @@ int zsend_interface_delete(struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_DELETE, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        client->ifdel_cnt++;
@@ -217,8 +216,7 @@ int zsend_interface_link_params(struct zserv *client, struct interface *ifp)
                return 0;
        }
 
-       zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS,
-                             vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id);
 
        /* Add Interface Index */
        stream_putl(s, ifp->ifindex);
@@ -280,7 +278,7 @@ int zsend_interface_address(int cmd, struct zserv *client,
        struct prefix *p;
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        stream_putl(s, ifp->ifindex);
 
        /* Interface address flag. */
@@ -322,7 +320,7 @@ static int zsend_interface_nbr_address(int cmd, struct zserv *client,
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
        struct prefix *p;
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        stream_putl(s, ifp->ifindex);
 
        /* Prefix information. */
@@ -430,8 +428,7 @@ int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp,
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE,
-                             vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id);
 
        /* Fill in the name of the interface and its new VRF (id) */
        stream_put(s, ifp->name, INTERFACE_NAMSIZ);
@@ -506,7 +503,7 @@ int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        if (cmd == ZEBRA_INTERFACE_UP)
@@ -930,20 +927,20 @@ int zsend_pw_update(struct zserv *client, struct zebra_pw *pw)
 }
 
 /* Send response to a get label chunk request to client */
-static int zsend_assign_label_chunk_response(struct zserv *client,
-                                            vrf_id_t vrf_id,
-                                            struct label_manager_chunk *lmc)
+int zsend_assign_label_chunk_response(struct zserv *client, vrf_id_t vrf_id,
+                                     uint8_t proto, uint16_t instance,
+                                     struct label_manager_chunk *lmc)
 {
        int ret;
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
        zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, vrf_id);
+       /* proto */
+       stream_putc(s, proto);
+       /* instance */
+       stream_putw(s, instance);
 
        if (lmc) {
-               /* proto */
-               stream_putc(s, lmc->proto);
-               /* instance */
-               stream_putw(s, lmc->instance);
                /* keep */
                stream_putc(s, lmc->keep);
                /* start and end labels */
@@ -960,9 +957,8 @@ static int zsend_assign_label_chunk_response(struct zserv *client,
 }
 
 /* Send response to a label manager connect request to client */
-static int zsend_label_manager_connect_response(struct zserv *client,
-                                               vrf_id_t vrf_id,
-                                               unsigned short result)
+int zsend_label_manager_connect_response(struct zserv *client, vrf_id_t vrf_id,
+                                        unsigned short result)
 {
        int ret;
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
@@ -1898,27 +1894,16 @@ static void zread_label_manager_connect(struct zserv *client,
                flog_err(EC_ZEBRA_TM_WRONG_PROTO,
                         "client %d has wrong protocol %s", client->sock,
                         zebra_route_string(proto));
-               if (client->is_synchronous)
-                       zsend_label_manager_connect_response(client, vrf_id, 1);
+               zsend_label_manager_connect_response(client, vrf_id, 1);
                return;
        }
-       zlog_notice("client %d with vrf %u instance %u connected as %s",
-                   client->sock, vrf_id, instance, zebra_route_string(proto));
+
+       /* recall proto and instance in this socket */
        client->proto = proto;
        client->instance = instance;
 
-       /*
-        * Release previous labels of same protocol and instance.
-        * This is done in case it restarted from an unexpected shutdown.
-        */
-       release_daemon_label_chunks(client);
-
-       zlog_debug(
-               " Label Manager client connected: sock %d, proto %s, vrf %u instance %u",
-               client->sock, zebra_route_string(proto), vrf_id, instance);
-       /* send response back */
-       if (client->is_synchronous)
-               zsend_label_manager_connect_response(client, vrf_id, 0);
+       /* call hook for connection using wrapper */
+       lm_client_connect_call(proto, instance, vrf_id);
 
 stream_failure:
        return;
@@ -1929,8 +1914,8 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
 {
        struct stream *s;
        uint8_t keep;
-       uint32_t size;
-       struct label_manager_chunk *lmc;
+       uint32_t size, base;
+       struct label_manager_chunk *lmc = NULL;
        uint8_t proto;
        unsigned short instance;
 
@@ -1942,8 +1927,11 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
        STREAM_GETW(s, instance);
        STREAM_GETC(s, keep);
        STREAM_GETL(s, size);
+       STREAM_GETL(s, base);
+
+       /* call hook to get a chunk using wrapper */
+       lm_get_chunk_call(&lmc, proto, instance, keep, size, base, vrf_id);
 
-       lmc = assign_label_chunk(proto, instance, keep, size);
        if (!lmc)
                flog_err(
                        EC_ZEBRA_LM_CANNOT_ASSIGN_CHUNK,
@@ -1953,8 +1941,6 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
                zlog_debug("Assigned Label Chunk %u - %u to %s instance %u",
                           lmc->start, lmc->end,
                           zebra_route_string(proto), instance);
-       /* send response back */
-       zsend_assign_label_chunk_response(client, vrf_id, lmc);
 
 stream_failure:
        return;
@@ -1976,33 +1962,23 @@ static void zread_release_label_chunk(struct zserv *client, struct stream *msg)
        STREAM_GETL(s, start);
        STREAM_GETL(s, end);
 
-       release_label_chunk(proto, instance, start, end);
+       /* call hook to release a chunk using wrapper */
+       lm_release_chunk_call(proto, instance, start, end);
 
 stream_failure:
        return;
 }
+
 static void zread_label_manager_request(ZAPI_HANDLER_ARGS)
 {
-       /* to avoid sending other messages like ZERBA_INTERFACE_UP */
-       client->is_synchronous = hdr->command ==
-                                ZEBRA_LABEL_MANAGER_CONNECT;
-
-       /* external label manager */
-       if (lm_is_external)
-               zread_relay_label_manager_request(hdr->command, client, msg,
-                                                 zvrf_id(zvrf));
-       /* this is a label manager */
+       if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT
+           || hdr->command == ZEBRA_LABEL_MANAGER_CONNECT_ASYNC)
+               zread_label_manager_connect(client, msg, zvrf_id(zvrf));
        else {
-               if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT ||
-                   hdr->command == ZEBRA_LABEL_MANAGER_CONNECT_ASYNC)
-                       zread_label_manager_connect(client, msg, zvrf_id(zvrf));
-               else {
-                       if (hdr->command == ZEBRA_GET_LABEL_CHUNK)
-                               zread_get_label_chunk(client, msg,
-                                                     zvrf_id(zvrf));
-                       else if (hdr->command == ZEBRA_RELEASE_LABEL_CHUNK)
-                               zread_release_label_chunk(client, msg);
-               }
+               if (hdr->command == ZEBRA_GET_LABEL_CHUNK)
+                       zread_get_label_chunk(client, msg, zvrf_id(zvrf));
+               else if (hdr->command == ZEBRA_RELEASE_LABEL_CHUNK)
+                       zread_release_label_chunk(client, msg);
        }
 }
 
@@ -2209,9 +2185,9 @@ static void zread_vrf_label(ZAPI_HANDLER_ARGS)
        STREAM_GETC(s, ltype);
 
        if (zvrf->vrf->vrf_id != VRF_DEFAULT)
-               ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf);
+               ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf->vrf_id);
        else
-               ifp = if_lookup_by_name("lo", vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name("lo", VRF_DEFAULT);
 
        if (!ifp) {
                zlog_debug("Unable to find specified Interface for %s",
@@ -2434,6 +2410,7 @@ static inline void zread_iptable(ZAPI_HANDLER_ARGS)
        STREAM_GETW(s, zpi.tcp_mask_flags);
        STREAM_GETC(s, zpi.dscp_value);
        STREAM_GETC(s, zpi.fragment);
+       STREAM_GETC(s, zpi.protocol);
        STREAM_GETL(s, zpi.nb_interface);
        zebra_pbr_iptable_update_interfacelist(s, &zpi);
 
@@ -2514,6 +2491,7 @@ void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
        [ZEBRA_IPTABLE_ADD] = zread_iptable,
        [ZEBRA_IPTABLE_DELETE] = zread_iptable,
        [ZEBRA_VXLAN_FLOOD_CONTROL] = zebra_vxlan_flood_control,
+       [ZEBRA_VXLAN_SG_REPLAY] = zebra_vxlan_sg_replay,
 };
 
 #if defined(HANDLE_ZAPI_FUZZING)