]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2229 from qlyoung/fix-readme-typo
authorRenato Westphal <renato@openbsd.org>
Tue, 15 May 2018 14:58:27 +0000 (11:58 -0300)
committerGitHub <noreply@github.com>
Tue, 15 May 2018 14:58:27 +0000 (11:58 -0300)
frr: fix typo in README

bgpd/bgp_zebra.c
lib/zclient.c
zebra/label_manager.c
zebra/label_manager.h
zebra/zapi_msg.c

index 52a246387ee2d945dbf1406c5c797005a06b5db8..4a909d8cdc0247b5c0bb94fcc1b0eb4c248a5f4b 100644 (file)
@@ -2391,12 +2391,25 @@ static void bgp_zebra_process_label_chunk(
        uint8_t response_keep;
        uint32_t first;
        uint32_t last;
+       uint8_t proto;
+       unsigned short instance;
 
        s = zclient->ibuf;
+       STREAM_GETC(s, proto);
+       STREAM_GETW(s, instance);
        STREAM_GETC(s, response_keep);
        STREAM_GETL(s, first);
        STREAM_GETL(s, last);
 
+       if (zclient->redist_default != proto) {
+               zlog_err("Got LM msg with wrong proto %u", proto);
+               return;
+       }
+       if (zclient->instance != instance) {
+               zlog_err("Got LM msg with wrong instance %u", proto);
+               return;
+       }
+
        if (first > last ||
                first < MPLS_LABEL_UNRESERVED_MIN ||
                last > MPLS_LABEL_UNRESERVED_MAX) {
index 05bd907589ce4940273098b9c56c6750a2d7e57b..0f7cf350dbad7e1a5a3c4b3a659a8c6c10825664 100644 (file)
@@ -1237,9 +1237,8 @@ stream_failure:
        return 0;
 }
 
-static void zapi_encode_prefix(struct stream *s,
-                             struct prefix *p,
-                             uint8_t family)
+static void zapi_encode_prefix(struct stream *s, struct prefix *p,
+                              uint8_t family)
 {
        struct prefix any;
 
@@ -1254,8 +1253,7 @@ static void zapi_encode_prefix(struct stream *s,
        stream_put(s, &p->u.prefix, prefix_blen(p));
 }
 
-int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
-                        struct pbr_rule *zrule)
+int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, struct pbr_rule *zrule)
 {
        stream_reset(s);
        zclient_create_header(s, cmd, zrule->vrf_id);
@@ -1271,11 +1269,11 @@ int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
 
        zapi_encode_prefix(s, &(zrule->filter.src_ip),
                           zrule->filter.src_ip.family);
-       stream_putw(s, zrule->filter.src_port);  /* src port */
+       stream_putw(s, zrule->filter.src_port); /* src port */
        zapi_encode_prefix(s, &(zrule->filter.dst_ip),
                           zrule->filter.src_ip.family);
-       stream_putw(s, zrule->filter.dst_port);  /* dst port */
-       stream_putw(s, zrule->filter.fwmark);    /* fwmark */
+       stream_putw(s, zrule->filter.dst_port); /* dst port */
+       stream_putw(s, zrule->filter.fwmark);   /* fwmark */
 
        stream_putl(s, zrule->action.table);
        stream_putl(s, zrule->ifindex);
@@ -1323,8 +1321,8 @@ bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno,
        STREAM_GETL(s, ifi);
 
        if (zclient_debug)
-               zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__,
-                          seq, prio, uni, ifi);
+               zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__, seq, prio,
+                          uni, ifi);
        *seqno = seq;
        *priority = prio;
        *unique = uni;
@@ -1336,9 +1334,8 @@ stream_failure:
        return false;
 }
 
-bool zapi_ipset_notify_decode(struct stream *s,
-                             uint32_t *unique,
-                            enum zapi_ipset_notify_owner *note)
+bool zapi_ipset_notify_decode(struct stream *s, uint32_t *unique,
+                             enum zapi_ipset_notify_owner *note)
 {
        uint32_t uni;
 
@@ -1356,10 +1353,9 @@ stream_failure:
        return false;
 }
 
-bool zapi_ipset_entry_notify_decode(struct stream *s,
-               uint32_t *unique,
-               char *ipset_name,
-               enum zapi_ipset_entry_notify_owner *note)
+bool zapi_ipset_entry_notify_decode(struct stream *s, uint32_t *unique,
+                                   char *ipset_name,
+                                   enum zapi_ipset_entry_notify_owner *note)
 {
        uint32_t uni;
 
@@ -1367,8 +1363,7 @@ bool zapi_ipset_entry_notify_decode(struct stream *s,
 
        STREAM_GETL(s, uni);
 
-       STREAM_GET(ipset_name, s,
-                  ZEBRA_IPSET_NAME_SIZE);
+       STREAM_GET(ipset_name, s, ZEBRA_IPSET_NAME_SIZE);
 
        if (zclient_debug)
                zlog_debug("%s: %u", __PRETTY_FUNCTION__, uni);
@@ -1414,7 +1409,7 @@ struct nexthop *nexthop_from_zapi_nexthop(struct zapi_nexthop *znh)
         */
        if (znh->label_num) {
                nexthop_add_labels(n, ZEBRA_LSP_NONE, znh->label_num,
-                       znh->labels);
+                                  znh->labels);
        }
 
        return n;
@@ -1475,7 +1470,7 @@ bool zapi_nexthop_update_decode(struct stream *s, struct zapi_route *nhr)
                if (nhr->nexthops[i].label_num)
                        STREAM_GET(&nhr->nexthops[i].labels[0], s,
                                   nhr->nexthops[i].label_num
-                                  * sizeof(mpls_label_t));
+                                          * sizeof(mpls_label_t));
        }
 
        return true;
@@ -1898,8 +1893,9 @@ struct connected *zebra_interface_address_read(int type, struct stream *s,
                                zlog_warn(
                                        "warning: interface %s address %s "
                                        "with peer flag set, but no peer address!",
-                                       ifp->name, prefix2str(ifc->address, buf,
-                                                             sizeof buf));
+                                       ifp->name,
+                                       prefix2str(ifc->address, buf,
+                                                  sizeof buf));
                                UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
                        }
                }
@@ -2065,7 +2061,7 @@ int lm_label_manager_connect(struct zclient *zclient)
        uint8_t result;
 
        if (zclient_debug)
-               zlog_debug("Connecting to Label Manager");
+               zlog_debug("Connecting to Label Manager (LM)");
 
        if (zclient->sock < 0)
                return -1;
@@ -2085,33 +2081,45 @@ int lm_label_manager_connect(struct zclient *zclient)
 
        ret = writen(zclient->sock, s->data, stream_get_endp(s));
        if (ret < 0) {
-               zlog_err("%s: can't write to zclient->sock", __func__);
+               zlog_err("Can't write to zclient sock");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
        }
        if (ret == 0) {
-               zlog_err("%s: zclient->sock connection closed", __func__);
+               zlog_err("Zclient sock closed");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
        }
        if (zclient_debug)
-               zlog_debug("%s: Label manager connect request (%d bytes) sent",
-                          __func__, ret);
+               zlog_debug("LM connect request sent (%d bytes)", ret);
 
        /* read response */
        if (zclient_read_sync_response(zclient, ZEBRA_LABEL_MANAGER_CONNECT)
            != 0)
                return -1;
 
-       /* result */
        s = zclient->ibuf;
+
+       /* read instance and proto */
+       uint8_t proto = stream_getc(s);
+       uint16_t instance = stream_getw(s);
+
+       /* sanity */
+       if (proto != zclient->redist_default)
+               zlog_err(
+                       "Wrong proto (%u) in LM connect response. Should be %u",
+                       proto, zclient->redist_default);
+       if (instance != zclient->instance)
+               zlog_err(
+                       "Wrong instId (%u) in LM connect response. Should be %u",
+                       instance, zclient->instance);
+
+       /* result code */
        result = stream_getc(s);
        if (zclient_debug)
-               zlog_debug(
-                       "%s: Label Manager connect response received, result %u",
-                       __func__, result);
+               zlog_debug("LM connect-response received, result %u", result);
 
        return (int)result;
 }
@@ -2124,10 +2132,8 @@ int lm_label_manager_connect(struct zclient *zclient)
  * @param chunk_size Amount of labels requested
  * @result 0 on success, -1 otherwise
  */
-int zclient_send_get_label_chunk(
-       struct zclient  *zclient,
-       uint8_t         keep,
-       uint32_t        chunk_size)
+int zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
+                                uint32_t chunk_size)
 {
        struct stream *s;
 
@@ -2141,6 +2147,10 @@ int zclient_send_get_label_chunk(
        stream_reset(s);
 
        zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, VRF_DEFAULT);
+       /* proto */
+       stream_putc(s, zclient->redist_default);
+       /* instance */
+       stream_putw(s, zclient->instance);
        stream_putc(s, keep);
        stream_putl(s, chunk_size);
 
@@ -2180,6 +2190,10 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
        s = zclient->obuf;
        stream_reset(s);
        zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, VRF_DEFAULT);
+       /* proto */
+       stream_putc(s, zclient->redist_default);
+       /* instance */
+       stream_putw(s, zclient->instance);
        /* keep */
        stream_putc(s, keep);
        /* chunk size */
@@ -2189,26 +2203,39 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
 
        ret = writen(zclient->sock, s->data, stream_get_endp(s));
        if (ret < 0) {
-               zlog_err("%s: can't write to zclient->sock", __func__);
+               zlog_err("Can't write to zclient sock");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
        }
        if (ret == 0) {
-               zlog_err("%s: zclient->sock connection closed", __func__);
+               zlog_err("Zclient sock closed");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
        }
        if (zclient_debug)
-               zlog_debug("%s: Label chunk request (%d bytes) sent", __func__,
-                          ret);
+               zlog_debug("Label chunk request (%d bytes) sent", ret);
 
        /* read response */
        if (zclient_read_sync_response(zclient, ZEBRA_GET_LABEL_CHUNK) != 0)
                return -1;
 
+       /* parse response */
        s = zclient->ibuf;
+
+       /* read proto and instance */
+       uint8_t proto = stream_getc(s);
+       uint16_t instance = stream_getw(s);
+
+       /* sanities */
+       if (proto != zclient->redist_default)
+               zlog_err("Wrong proto (%u) in get chunk response. Should be %u",
+                        proto, zclient->redist_default);
+       if (instance != zclient->instance)
+               zlog_err("Wrong instId (%u) in get chunk response Should be %u",
+                        instance, zclient->instance);
+
        /* keep */
        response_keep = stream_getc(s);
        /* start and end labels */
@@ -2218,19 +2245,18 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
        /* not owning this response */
        if (keep != response_keep) {
                zlog_err(
-                       "%s: Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
-                       __func__, *start, *end, keep, response_keep);
+                       "Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
+                       *start, *end, keep, response_keep);
        }
        /* sanity */
        if (*start > *end || *start < MPLS_LABEL_UNRESERVED_MIN
            || *end > MPLS_LABEL_UNRESERVED_MAX) {
-               zlog_err("%s: Invalid Label chunk: %u - %u", __func__, *start,
-                        *end);
+               zlog_err("Invalid Label chunk: %u - %u", *start, *end);
                return -1;
        }
 
        if (zclient_debug)
-               zlog_debug("Label Chunk assign: %u - %u (%u) ", *start, *end,
+               zlog_debug("Label Chunk assign: %u - %u (%u)", *start, *end,
                           response_keep);
 
        return 0;
@@ -2251,7 +2277,7 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
        struct stream *s;
 
        if (zclient_debug)
-               zlog_debug("Releasing Label Chunk");
+               zlog_debug("Releasing Label Chunk %u - %u", start, end);
 
        if (zclient->sock < 0)
                return -1;
@@ -2261,6 +2287,10 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
        stream_reset(s);
        zclient_create_header(s, ZEBRA_RELEASE_LABEL_CHUNK, VRF_DEFAULT);
 
+       /* proto */
+       stream_putc(s, zclient->redist_default);
+       /* instance */
+       stream_putw(s, zclient->instance);
        /* start */
        stream_putl(s, start);
        /* end */
@@ -2271,13 +2301,13 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
 
        ret = writen(zclient->sock, s->data, stream_get_endp(s));
        if (ret < 0) {
-               zlog_err("%s: can't write to zclient->sock", __func__);
+               zlog_err("Can't write to zclient sock");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
        }
        if (ret == 0) {
-               zlog_err("%s: zclient->sock connection closed", __func__);
+               zlog_err("Zclient sock connection closed");
                close(zclient->sock);
                zclient->sock = -1;
                return -1;
@@ -2325,8 +2355,7 @@ int tm_table_manager_connect(struct zclient *zclient)
                return -1;
 
        if (zclient_debug)
-               zlog_debug("%s: Table manager connect request sent",
-                          __func__);
+               zlog_debug("%s: Table manager connect request sent", __func__);
 
        /* read response */
        if (zclient_read_sync_response(zclient, ZEBRA_TABLE_MANAGER_CONNECT)
@@ -2789,7 +2818,7 @@ static int zclient_read(struct thread *thread)
        case ZEBRA_GET_LABEL_CHUNK:
                if (zclient->label_chunk)
                        (*zclient->label_chunk)(command, zclient, length,
-                                                     vrf_id);
+                                               vrf_id);
                break;
        case ZEBRA_IPSET_NOTIFY_OWNER:
                if (zclient->ipset_notify_owner)
index 190ac1e57f7ec7571f4306a7fb1fe3642bd30e16..f3fa3ba94efd618e9730c46527f8c2f64f14390f 100644 (file)
@@ -50,7 +50,6 @@ DEFINE_MTYPE_STATIC(LBL_MGR, LM_CHUNK, "Label Manager Chunk");
  * it will be a proxy to relay messages to external label manager
  * This zclient thus is to connect to it
  */
-static struct stream *ibuf;
 static struct stream *obuf;
 static struct zclient *zclient;
 bool lm_is_external;
@@ -60,7 +59,7 @@ static void delete_label_chunk(void *val)
        XFREE(MTYPE_LM_CHUNK, val);
 }
 
-static int relay_response_back(struct zserv *zserv)
+static int relay_response_back(void)
 {
        int ret = 0;
        struct stream *src, *dst;
@@ -69,49 +68,72 @@ static int relay_response_back(struct zserv *zserv)
        uint8_t version;
        vrf_id_t vrf_id;
        uint16_t resp_cmd;
+       uint8_t proto;
+       const char *proto_str;
+       unsigned short instance;
+       struct zserv *zserv;
 
+       /* input buffer with msg from label manager */
        src = zclient->ibuf;
-       dst = obuf;
 
        stream_reset(src);
 
+       /* parse header */
        ret = zclient_read_header(src, zclient->sock, &size, &marker, &version,
                                  &vrf_id, &resp_cmd);
        if (ret < 0 && errno != EAGAIN) {
-               zlog_err("%s: Error reading Label Manager response: %s",
-                        __func__, strerror(errno));
+               zlog_err("Error reading Label Manager response: %s",
+                        strerror(errno));
                return -1;
        }
-       zlog_debug("%s: Label Manager response received, %d bytes", __func__,
-                  size);
+       zlog_debug("Label Manager response received, %d bytes", size);
        if (size == 0)
                return -1;
 
-       /* send response back */
+       /* Get the 'proto' field of the message */
+       proto = stream_getc(src);
+
+       /* Get the 'instance' field of the message */
+       instance = stream_getw(src);
+
+       proto_str = zebra_route_string(proto);
+
+       /* lookup the client to relay the msg to */
+       zserv = zebra_find_client(proto, instance);
+       if (!zserv) {
+               zlog_err(
+                       "Error relaying LM response: can't find client %s, instance %u",
+                       proto_str, instance);
+               return -1;
+       }
+       zlog_debug("Found client to relay LM response to client %s instance %u",
+                  proto_str, instance);
+
+       /* copy msg into output buffer */
+       dst = obuf;
        stream_copy(dst, src);
-       ret = writen(zserv->sock, src->data, stream_get_endp(src));
+
+       /* send response back */
+       ret = writen(zserv->sock, dst->data, stream_get_endp(dst));
        if (ret <= 0) {
-               zlog_err("%s: Error sending Label Manager response back: %s",
-                        __func__, strerror(errno));
+               zlog_err("Error relaying LM response to %s instance %u: %s",
+                        proto_str, instance, strerror(errno));
                return -1;
        }
-       zlog_debug("%s: Label Manager response (%d bytes) sent back", __func__,
-                  ret);
+       zlog_debug("Relayed LM response (%d bytes) to %s instance %u", ret,
+                  proto_str, instance);
 
        return 0;
 }
 
 static int lm_zclient_read(struct thread *t)
 {
-       struct zserv *zserv;
        int ret;
 
-       /* Get socket to zebra. */
-       zserv = THREAD_ARG(t);
        zclient->t_read = NULL;
 
        /* read response and send it back */
-       ret = relay_response_back(zserv);
+       ret = relay_response_back();
 
        return ret;
 }
@@ -125,6 +147,10 @@ static int reply_error(int cmd, struct zserv *zserv, vrf_id_t vrf_id)
 
        zclient_create_header(s, cmd, vrf_id);
 
+       /* proto */
+       stream_putc(s, zserv->proto);
+       /* instance */
+       stream_putw(s, zserv->instance);
        /* result */
        stream_putc(s, 1);
 
@@ -148,38 +174,73 @@ static int reply_error(int cmd, struct zserv *zserv, vrf_id_t vrf_id)
  * @return 0 on success, -1 otherwise
  */
 int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
-                                     vrf_id_t vrf_id)
+                                     struct stream *msg, vrf_id_t vrf_id)
 {
-       struct stream *src, *dst;
+       struct stream *dst;
        int ret = 0;
+       uint8_t proto;
+       const char *proto_str;
+       unsigned short instance;
 
        if (zclient->sock < 0) {
-               zlog_err(
-                       "%s: Error relaying label chunk request: no zclient socket",
-                       __func__);
+               zlog_err("Unable to relay LM request: no socket");
                reply_error(cmd, zserv, vrf_id);
                return -1;
        }
 
+       /* peek msg to get proto and instance id. This zebra, which acts as
+        * a proxy needs to have such values for each client in order to
+        * relay responses back to it.
+        */
+
+       /* Get the 'proto' field of incoming msg */
+       proto = stream_getc(msg);
+
+       /* Get the 'instance' field of incoming msg */
+       instance = stream_getw(msg);
+
+       /* stringify proto */
+       proto_str = zebra_route_string(proto);
+
+       /* check & set client proto if unset */
+       if (zserv->proto && zserv->proto != proto) {
+               zlog_warn("Client proto(%u) != msg proto(%u)", zserv->proto,
+                         proto);
+               return -1;
+       }
+
+       /* check & set client instance if unset */
+       if (zserv->instance && zserv->instance != instance) {
+               zlog_err("Client instance(%u) != msg instance(%u)",
+                        zserv->instance, instance);
+               return -1;
+       }
+
+       /* recall proto and instance */
+       zserv->instance = instance;
+       zserv->proto = proto;
+
        /* in case there's any incoming message enqueued, read and forward it */
        while (ret == 0)
-               ret = relay_response_back(zserv);
+               ret = relay_response_back();
 
-       /* Send request to external label manager */
-       src = ibuf;
+       /* get the msg buffer used toward the 'master' Label Manager */
        dst = zclient->obuf;
 
-       stream_copy(dst, src);
+       /* copy the message */
+       stream_copy(dst, msg);
 
+       /* Send request to external label manager */
        ret = writen(zclient->sock, dst->data, stream_get_endp(dst));
        if (ret <= 0) {
-               zlog_err("%s: Error relaying label chunk request: %s", __func__,
-                        strerror(errno));
+               zlog_err("Error relaying LM request from %s instance %u: %s",
+                        proto_str, instance, strerror(errno));
                reply_error(cmd, zserv, vrf_id);
                return -1;
        }
-       zlog_debug("%s: Label chunk request relayed. %d bytes sent", __func__,
-                  ret);
+       zlog_debug("Relayed LM request (%d bytes) from %s instance %u", ret,
+                  proto_str, instance);
+
 
        /* Release label chunk has no response */
        if (cmd == ZEBRA_RELEASE_LABEL_CHUNK)
@@ -187,7 +248,7 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
 
        /* make sure we listen to the response */
        if (!zclient->t_read)
-               thread_add_read(zclient->master, lm_zclient_read, zserv,
+               thread_add_read(zclient->master, lm_zclient_read, NULL,
                                zclient->sock, &zclient->t_read);
 
        return 0;
@@ -276,7 +337,7 @@ void label_manager_init(char *lm_zserv_path)
 {
        /* this is an actual label manager */
        if (!lm_zserv_path) {
-               zlog_debug("Initializing own label manager");
+               zlog_debug("Initializing internal label manager");
                lm_is_external = false;
                lbl_mgr.lc_list = list_new();
                lbl_mgr.lc_list->del = delete_label_chunk;
@@ -287,7 +348,6 @@ void label_manager_init(char *lm_zserv_path)
                lm_zclient_init(lm_zserv_path);
        }
 
-       ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
        obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
        hook_register(zapi_client_close, release_daemon_label_chunks);
@@ -393,6 +453,5 @@ int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
 void label_manager_close()
 {
        list_delete_and_null(&lbl_mgr.lc_list);
-       stream_free(ibuf);
        stream_free(obuf);
 }
index b998372224ad02cc679cfd19c6e7aeb8e51dafab..3e3def5f98bbf47eaf7a18e11cc6da2a4786c65d 100644 (file)
@@ -64,7 +64,7 @@ struct label_manager {
 bool lm_is_external;
 
 int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
-                                     vrf_id_t vrf_id);
+                                     struct stream *msg, vrf_id_t vrf_id);
 void label_manager_init(char *lm_zserv_path);
 struct label_manager_chunk *assign_label_chunk(uint8_t proto,
                                               unsigned short instance,
index 6bd12391dbf223148baedb5735db572bfdf1cc60..9a18cc22f0c5500c090b7ef1c2cb56515129a187 100644 (file)
@@ -887,6 +887,10 @@ static int zsend_assign_label_chunk_response(struct zserv *client,
        zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, vrf_id);
 
        if (lmc) {
+               /* proto */
+               stream_putc(s, lmc->proto);
+               /* instance */
+               stream_putw(s, lmc->instance);
                /* keep */
                stream_putc(s, lmc->keep);
                /* start and end labels */
@@ -912,6 +916,12 @@ static int zsend_label_manager_connect_response(struct zserv *client,
 
        zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, vrf_id);
 
+       /* proto */
+       stream_putc(s, client->proto);
+
+       /* instance */
+       stream_putw(s, client->instance);
+
        /* result */
        stream_putc(s, result);
 
@@ -2397,6 +2407,26 @@ static void zread_label_manager_connect(struct zserv *client,
 stream_failure:
        return;
 }
+static int msg_client_id_mismatch(const char *op, struct zserv *client,
+                                 uint8_t proto, unsigned int instance)
+{
+       if (proto != client->proto) {
+               zlog_err("%s: msg vs client proto mismatch, client=%u msg=%u",
+                        op, client->proto, proto);
+               /* TODO: fail when BGP sets proto and instance */
+               /* return 1; */
+       }
+
+       if (instance != client->instance) {
+               zlog_err(
+                       "%s: msg vs client instance mismatch, client=%u msg=%u",
+                       op, client->instance, instance);
+               /* TODO: fail when BGP sets proto and instance */
+               /* return 1; */
+       }
+
+       return 0;
+}
 
 static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
                                  vrf_id_t vrf_id)
@@ -2405,21 +2435,32 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
        uint8_t keep;
        uint32_t size;
        struct label_manager_chunk *lmc;
+       uint8_t proto;
+       unsigned short instance;
 
        /* Get input stream.  */
        s = msg;
 
        /* Get data. */
+       STREAM_GETC(s, proto);
+       STREAM_GETW(s, instance);
        STREAM_GETC(s, keep);
        STREAM_GETL(s, size);
 
+       /* detect client vs message (proto,instance) mismatch */
+       if (msg_client_id_mismatch("Get-label-chunk", client, proto, instance))
+               return;
+
        lmc = assign_label_chunk(client->proto, client->instance, keep, size);
        if (!lmc)
-               zlog_err("%s: Unable to assign Label Chunk of size %u",
-                        __func__, size);
+               zlog_err(
+                       "Unable to assign Label Chunk of size %u to %s instance %u",
+                       size, zebra_route_string(client->proto),
+                       client->instance);
        else
-               zlog_debug("Assigned Label Chunk %u - %u to %u", lmc->start,
-                          lmc->end, keep);
+               zlog_debug("Assigned Label Chunk %u - %u to %s instance %u",
+                          lmc->start, lmc->end,
+                          zebra_route_string(client->proto), client->instance);
        /* send response back */
        zsend_assign_label_chunk_response(client, vrf_id, lmc);
 
@@ -2431,14 +2472,23 @@ static void zread_release_label_chunk(struct zserv *client, struct stream *msg)
 {
        struct stream *s;
        uint32_t start, end;
+       uint8_t proto;
+       unsigned short instance;
 
        /* Get input stream.  */
        s = msg;
 
        /* Get data. */
+       STREAM_GETC(s, proto);
+       STREAM_GETW(s, instance);
        STREAM_GETL(s, start);
        STREAM_GETL(s, end);
 
+       /* detect client vs message (proto,instance) mismatch */
+       if (msg_client_id_mismatch("Release-label-chunk", client, proto,
+                                  instance))
+               return;
+
        release_label_chunk(client->proto, client->instance, start, end);
 
 stream_failure:
@@ -2452,7 +2502,7 @@ static void zread_label_manager_request(ZAPI_HANDLER_ARGS)
 
        /* external label manager */
        if (lm_is_external)
-               zread_relay_label_manager_request(hdr->command, client,
+               zread_relay_label_manager_request(hdr->command, client, msg,
                                                  zvrf_id(zvrf));
        /* this is a label manager */
        else {