]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #3481 from opensourcerouting/6.0-spelchek
authorJafar Al-Gharaibeh <Jafaral@users.noreply.github.com>
Fri, 14 Dec 2018 05:28:42 +0000 (23:28 -0600)
committerGitHub <noreply@github.com>
Fri, 14 Dec 2018 05:28:42 +0000 (23:28 -0600)
[6.0] spelchek

15 files changed:
bgpd/bgp_labelpool.c
bgpd/bgp_main.c
bgpd/bgp_zebra.c
bgpd/bgp_zebra.h
bgpd/bgpd.c
bgpd/bgpd.h
doc/manpages/bgpd.rst
ldpd/lde.c
lib/log.c
lib/zclient.c
lib/zclient.h
tests/bgpd/test_peer_attr.c
tests/test_lblmgr.c
zebra/label_manager.c
zebra/zapi_msg.c

index 8d15649ea55f2bd38ecd6c0b40567c222a2659cc..81cf2c79bb1917915f2439b5244654309542f5cf 100644 (file)
@@ -530,6 +530,7 @@ void bgp_lp_event_zebra_up(void)
        int chunks_needed;
        void *labelid;
        struct lp_lcb *lcb;
+       int lm_init_ok;
 
        /*
         * Get label chunk allocation request dispatched to zebra
@@ -541,6 +542,11 @@ void bgp_lp_event_zebra_up(void)
        chunks_needed = (labels_needed / LP_CHUNK_SIZE) + 1;
        labels_needed = chunks_needed * LP_CHUNK_SIZE;
 
+       lm_init_ok = lm_label_manager_connect(zclient, 1) == 0;
+
+       if (!lm_init_ok)
+               zlog_err("%s: label manager connection error", __func__);
+
        zclient_send_get_label_chunk(zclient, 0, labels_needed);
        lp->pending_count = labels_needed;
 
index 138788194dba7944914e1d222201727ed88d33e5..25c2fd079a8a8cc3b01d5837367f8135ea432dfc 100644 (file)
@@ -77,6 +77,7 @@ static const struct option longopts[] = {
        {"no_kernel", no_argument, NULL, 'n'},
        {"skip_runas", no_argument, NULL, 'S'},
        {"ecmp", required_argument, NULL, 'e'},
+       {"int_num", required_argument, NULL, 'I'},
        {0}};
 
 /* signal definitions */
@@ -364,15 +365,17 @@ int main(int argc, char **argv)
        char *bgp_address = NULL;
        int no_fib_flag = 0;
        int skip_runas = 0;
+       int instance = 0;
 
        frr_preinit(&bgpd_di, argc, argv);
        frr_opt_add(
-               "p:l:Sne:" DEPRECATED_OPTIONS, longopts,
+               "p:l:Sne:I:" DEPRECATED_OPTIONS, longopts,
                "  -p, --bgp_port     Set BGP listen port number (0 means do not listen).\n"
                "  -l, --listenon     Listen on specified address (implies -n)\n"
                "  -n, --no_kernel    Do not install route to kernel.\n"
                "  -S, --skip_runas   Skip capabilities checks, and changing user and group IDs.\n"
-               "  -e, --ecmp         Specify ECMP to use.\n");
+               "  -e, --ecmp         Specify ECMP to use.\n"
+               "  -I, --int_num      Set instance number (label-manager)\n");
 
        /* Command line argument treatment. */
        while (1) {
@@ -419,6 +422,12 @@ int main(int argc, char **argv)
                case 'S':
                        skip_runas = 1;
                        break;
+               case 'I':
+                       instance = atoi(optarg);
+                       if (instance > (unsigned short)-1)
+                               zlog_err("Instance %i out of range (0..%u)",
+                                        instance, (unsigned short)-1);
+                       break;
                default:
                        frr_help_exit(1);
                        break;
@@ -441,7 +450,7 @@ int main(int argc, char **argv)
        bgp_vrf_init();
 
        /* BGP related initialization.  */
-       bgp_init();
+       bgp_init((unsigned short)instance);
 
        snprintf(bgpd_di.startinfo, sizeof(bgpd_di.startinfo), ", bgp@%s:%d",
                 (bm->address ? bm->address : "<all>"), bm->port);
index 4c5057563e6ce943578893adc5b882258c95df82..f59c288a73aaa2046f450d6548a760f0c2b8121d 100644 (file)
@@ -2530,7 +2530,7 @@ stream_failure:           /* for STREAM_GETX */
 
 extern struct zebra_privs_t bgpd_privs;
 
-void bgp_zebra_init(struct thread_master *master)
+void bgp_zebra_init(struct thread_master *master, unsigned short instance)
 {
        zclient_num_connects = 0;
 
@@ -2569,6 +2569,7 @@ void bgp_zebra_init(struct thread_master *master)
        zclient->ipset_notify_owner = ipset_notify_owner;
        zclient->ipset_entry_notify_owner = ipset_entry_notify_owner;
        zclient->iptable_notify_owner = iptable_notify_owner;
+       zclient->instance = instance;
 }
 
 void bgp_zebra_destroy(void)
index c00d9925eeff24c3db05bc490a731a9ca7d385f3..0223c423df770153a85ae31c33104230eac525b9 100644 (file)
@@ -23,7 +23,8 @@
 
 #include "vxlan.h"
 
-extern void bgp_zebra_init(struct thread_master *master);
+extern void bgp_zebra_init(struct thread_master *master,
+                          unsigned short instance);
 extern void bgp_zebra_init_tm_connect(struct bgp *bgp);
 extern uint32_t bgp_zebra_tm_get_id(void);
 extern bool bgp_zebra_tm_chunk_obtained(void);
index 7ff5053ce37a8907e65c299acdb1aea15847b981..dfff778fcb35355a6f00ea264d0c61b81b87724d 100644 (file)
@@ -7790,7 +7790,7 @@ void bgp_pthreads_finish()
        frr_pthread_finish();
 }
 
-void bgp_init(void)
+void bgp_init(unsigned short instance)
 {
 
        /* allocates some vital data structures used by peer commands in
@@ -7800,7 +7800,7 @@ void bgp_init(void)
        bgp_pthreads_init();
 
        /* Init zebra. */
-       bgp_zebra_init(bm->master);
+       bgp_zebra_init(bm->master, instance);
 
 #if ENABLE_BGP_VNC
        vnc_zebra_init(bm->master);
index fa2ece0ad7d517c4db02ac6c7abdfd3e68acb38b..1baa88914ae9c97da1b01cfa2a837b621a6a5352 100644 (file)
@@ -1517,7 +1517,7 @@ extern int bgp_config_write(struct vty *);
 
 extern void bgp_master_init(struct thread_master *master);
 
-extern void bgp_init(void);
+extern void bgp_init(unsigned short instance);
 extern void bgp_pthreads_run(void);
 extern void bgp_pthreads_finish(void);
 extern void bgp_route_map_init(void);
index 94213db4d75379800f66b256db329593bfc90467..f1736ffd0bd200782d381ac87a83dcf8620d4759 100644 (file)
@@ -21,6 +21,13 @@ OPTIONS available for the |DAEMON| command:
 
 .. include:: common-options.rst
 
+LABEL MANAGER
+-------------
+
+.. option:: -I, --int_num
+
+   Set zclient id. This is required when using Zebra label manager in proxy mode.
+
 FILES
 =====
 
index 03b62b482b26076fd10c0162d217dec626c2a6f7..eb78f2bcc0b2e9fd17d0bc386ad2394ada572c72 100644 (file)
@@ -1643,7 +1643,7 @@ static void zclient_sync_init(unsigned short instance)
        sock_set_nonblock(zclient_sync->sock);
 
        /* Connect to label manager */
-       while (lm_label_manager_connect(zclient_sync) != 0) {
+       while (lm_label_manager_connect(zclient_sync, 0) != 0) {
                log_warnx("Error connecting to label manager!");
                sleep(1);
        }
index 5f0bbff2a204b737d0103ecbc67787e5a9044a04..1619ad36ec4b883e843f7bff1d76f92596571cf2 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -963,6 +963,7 @@ static const struct zebra_desc_table command_types[] = {
        DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE),
        DESC_ENTRY(ZEBRA_IPMR_ROUTE_STATS),
        DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT),
+       DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT_ASYNC),
        DESC_ENTRY(ZEBRA_GET_LABEL_CHUNK),
        DESC_ENTRY(ZEBRA_RELEASE_LABEL_CHUNK),
        DESC_ENTRY(ZEBRA_ADVERTISE_ALL_VNI),
index b2bafcb7d8f831e2c5f8a69037b331cde2ae2a51..1019ed7ecfcc9e026fb08ddf94b368355315a36f 100644 (file)
@@ -1830,24 +1830,29 @@ static int zclient_read_sync_response(struct zclient *zclient,
  * immediately reads the answer from the input buffer.
  *
  * @param zclient Zclient used to connect to label manager (zebra)
+ * @param async Synchronous (0) or asynchronous (1) operation
  * @result Result of response
  */
-int lm_label_manager_connect(struct zclient *zclient)
+int lm_label_manager_connect(struct zclient *zclient, int async)
 {
        int ret;
        struct stream *s;
        uint8_t result;
+       uint16_t cmd = async ? ZEBRA_LABEL_MANAGER_CONNECT_ASYNC :
+                              ZEBRA_LABEL_MANAGER_CONNECT;
 
        if (zclient_debug)
                zlog_debug("Connecting to Label Manager (LM)");
 
-       if (zclient->sock < 0)
+       if (zclient->sock < 0) {
+               zlog_debug("%s: invalid zclient socket", __func__);
                return -1;
+       }
 
        /* send request */
        s = zclient->obuf;
        stream_reset(s);
-       zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, VRF_DEFAULT);
+       zclient_create_header(s, cmd, VRF_DEFAULT);
 
        /* proto */
        stream_putc(s, zclient->redist_default);
@@ -1873,8 +1878,11 @@ int lm_label_manager_connect(struct zclient *zclient)
        if (zclient_debug)
                zlog_debug("LM connect request sent (%d bytes)", ret);
 
+       if (async)
+               return 0;
+
        /* read response */
-       if (zclient_read_sync_response(zclient, ZEBRA_LABEL_MANAGER_CONNECT)
+       if (zclient_read_sync_response(zclient, cmd)
            != 0)
                return -1;
 
index b8ff85e80ff584f954f990abcc695d0d15d45c70..e434228eb786e0eb6cafe829756d6ba87b3c4943 100644 (file)
@@ -113,6 +113,7 @@ typedef enum {
        ZEBRA_MPLS_LABELS_DELETE,
        ZEBRA_IPMR_ROUTE_STATS,
        ZEBRA_LABEL_MANAGER_CONNECT,
+       ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
        ZEBRA_GET_LABEL_CHUNK,
        ZEBRA_RELEASE_LABEL_CHUNK,
        ZEBRA_FEC_REGISTER,
@@ -573,7 +574,7 @@ extern int zclient_send_get_label_chunk(
        uint8_t         keep,
        uint32_t        chunk_size);
 
-extern int lm_label_manager_connect(struct zclient *zclient);
+extern int lm_label_manager_connect(struct zclient *zclient, int async);
 extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
                              uint32_t chunk_size, uint32_t *start,
                              uint32_t *end);
index 16bd5d96dab51e53d8cdbaffb12c6467d431cf3b..336582e38d6ca06354a072f53f2ff55e943d51f7 100644 (file)
@@ -1388,7 +1388,7 @@ static void bgp_startup(void)
        bgp_master_init(master);
        bgp_option_set(BGP_OPT_NO_LISTEN);
        vrf_init(NULL, NULL, NULL, NULL);
-       bgp_init();
+       bgp_init(0);
        bgp_pthreads_run();
 }
 
index c751c0b12d03bf04d4260c77352279dc084c0338..255e9a537bd404129f5043c2cc4177a34435cb61 100644 (file)
@@ -55,7 +55,7 @@ static int zebra_send_label_manager_connect()
 
        printf("Connect to Label Manager\n");
 
-       ret = lm_label_manager_connect(zclient);
+       ret = lm_label_manager_connect(zclient, 0);
        printf("Label Manager connection result: %u \n", ret);
        if (ret != 0) {
                fprintf(stderr, "Error %d connecting to Label Manager %s\n",
index e53764c77010775cd26732192c510b8b9b215baf..65c85f7deed847f9fe46766536feb6433467cfc3 100644 (file)
@@ -88,7 +88,23 @@ static int relay_response_back(void)
                          strerror(errno));
                return -1;
        }
-       zlog_debug("Label Manager response received, %d bytes", size);
+
+       /* do not relay a msg that has nothing to do with LM */
+       switch (resp_cmd) {
+       case ZEBRA_LABEL_MANAGER_CONNECT:
+       case ZEBRA_LABEL_MANAGER_CONNECT_ASYNC: /* should not be seen */
+       case ZEBRA_GET_LABEL_CHUNK:
+       case ZEBRA_RELEASE_LABEL_CHUNK:
+               break;
+       default:
+               zlog_debug("Not relaying '%s' response (size %d) from LM",
+                          zserv_command_string(resp_cmd), size);
+               return -1;
+       }
+
+       zlog_debug("Received '%s' response (size %d) from LM",
+                  zserv_command_string(resp_cmd), size);
+
        if (size == 0)
                return -1;
 
@@ -139,6 +155,11 @@ static int lm_zclient_read(struct thread *t)
        /* read response and send it back */
        ret = relay_response_back();
 
+       /* on error, schedule another read */
+       if (ret == -1)
+               if (!zclient->t_read)
+                       thread_add_read(zclient->master, lm_zclient_read, NULL,
+                                       zclient->sock, &zclient->t_read);
        return ret;
 }
 
@@ -227,8 +248,9 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
        zserv->proto = proto;
 
        /* in case there's any incoming message enqueued, read and forward it */
-       while (ret == 0)
-               ret = relay_response_back();
+       if (zserv->is_synchronous)
+               while (ret == 0)
+                       ret = relay_response_back();
 
        /* get the msg buffer used toward the 'master' Label Manager */
        dst = zclient->obuf;
index d95f78109cbea829aa8c86813f4637246354d855..1b5c927ea2e9bc6b88116b22b12a1462d3a9b3ff 100644 (file)
@@ -1822,9 +1822,10 @@ static void zread_label_manager_connect(struct zserv *client,
        /* accept only dynamic routing protocols */
        if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) {
                flog_err(ZEBRA_ERR_TM_WRONG_PROTO,
-                         "client %d has wrong protocol %s", client->sock,
-                         zebra_route_string(proto));
-               zsend_label_manager_connect_response(client, vrf_id, 1);
+                        "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);
                return;
        }
        zlog_notice("client %d with vrf %u instance %u connected as %s",
@@ -1842,33 +1843,12 @@ static void zread_label_manager_connect(struct zserv *client,
                " Label Manager client connected: sock %d, proto %s, vrf %u instance %u",
                client->sock, zebra_route_string(proto), vrf_id, instance);
        /* send response back */
-       zsend_label_manager_connect_response(client, vrf_id, 0);
+       if (client->is_synchronous)
+               zsend_label_manager_connect_response(client, vrf_id, 0);
 
 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) {
-               flog_err(ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
-                         "%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) {
-               flog_err(
-                       ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
-                       "%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)
@@ -1889,21 +1869,16 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
        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);
+       lmc = assign_label_chunk(proto, instance, keep, size);
        if (!lmc)
                flog_err(
                        ZEBRA_ERR_LM_CANNOT_ASSIGN_CHUNK,
                        "Unable to assign Label Chunk of size %u to %s instance %u",
-                       size, zebra_route_string(client->proto),
-                       client->instance);
+                       size, zebra_route_string(proto), instance);
        else
                zlog_debug("Assigned Label Chunk %u - %u to %s instance %u",
                           lmc->start, lmc->end,
-                          zebra_route_string(client->proto), client->instance);
+                          zebra_route_string(proto), instance);
        /* send response back */
        zsend_assign_label_chunk_response(client, vrf_id, lmc);
 
@@ -1927,12 +1902,7 @@ static void zread_release_label_chunk(struct zserv *client, struct stream *msg)
        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);
+       release_label_chunk(proto, instance, start, end);
 
 stream_failure:
        return;
@@ -1940,8 +1910,8 @@ stream_failure:
 static void zread_label_manager_request(ZAPI_HANDLER_ARGS)
 {
        /* to avoid sending other messages like ZERBA_INTERFACE_UP */
-       if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT)
-               client->is_synchronous = 1;
+       client->is_synchronous = hdr->command ==
+                                ZEBRA_LABEL_MANAGER_CONNECT;
 
        /* external label manager */
        if (lm_is_external)
@@ -1949,16 +1919,10 @@ static void zread_label_manager_request(ZAPI_HANDLER_ARGS)
                                                  zvrf_id(zvrf));
        /* this is a label manager */
        else {
-               if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT)
+               if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT ||
+                   hdr->command == ZEBRA_LABEL_MANAGER_CONNECT_ASYNC)
                        zread_label_manager_connect(client, msg, zvrf_id(zvrf));
                else {
-                       /* Sanity: don't allow 'unidentified' requests */
-                       if (!client->proto) {
-                               flog_err(
-                                       ZEBRA_ERR_LM_ALIENS,
-                                       "Got label request from an unidentified client");
-                               return;
-                       }
                        if (hdr->command == ZEBRA_GET_LABEL_CHUNK)
                                zread_get_label_chunk(client, msg,
                                                      zvrf_id(zvrf));
@@ -2440,6 +2404,7 @@ void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
        [ZEBRA_MPLS_LABELS_DELETE] = zread_mpls_labels,
        [ZEBRA_IPMR_ROUTE_STATS] = zebra_ipmr_route_stats,
        [ZEBRA_LABEL_MANAGER_CONNECT] = zread_label_manager_request,
+       [ZEBRA_LABEL_MANAGER_CONNECT_ASYNC] = zread_label_manager_request,
        [ZEBRA_GET_LABEL_CHUNK] = zread_label_manager_request,
        [ZEBRA_RELEASE_LABEL_CHUNK] = zread_label_manager_request,
        [ZEBRA_FEC_REGISTER] = zread_fec_register,