]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/zclient.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / zclient.c
index 1cdf4ff22e81a5bc69c109bc2cb60f98768d900a..d2a6c75548f41698834c1ec3efacc1f6eff85e9a 100644 (file)
@@ -58,8 +58,8 @@ int zclient_debug = 0;
 struct zclient_options zclient_options_default = {.receive_notify = false};
 
 /* Allocate zclient structure. */
-struct zclient *zclient_new_notify(struct thread_master *master,
-                                  struct zclient_options *opt)
+struct zclient *zclient_new(struct thread_master *master,
+                           struct zclient_options *opt)
 {
        struct zclient *zclient;
        zclient = XCALLOC(MTYPE_ZCLIENT, sizeof(struct zclient));
@@ -133,7 +133,7 @@ void redist_del_instance(struct redist_proto *red, unsigned short instance)
        XFREE(MTYPE_REDIST_INST, id);
        if (!red->instances->count) {
                red->enabled = 0;
-               list_delete_and_null(&red->instances);
+               list_delete(&red->instances);
        }
 }
 
@@ -199,7 +199,7 @@ void zclient_reset(struct zclient *zclient)
  * @param zclient a pointer to zclient structure
  * @return socket fd just to make sure that connection established
  * @see zclient_init
- * @see zclient_new_notify
+ * @see zclient_new
  */
 int zclient_socket_connect(struct zclient *zclient)
 {
@@ -1217,6 +1217,7 @@ bool zapi_nexthop_update_decode(struct stream *s, struct zapi_route *nhr)
        STREAM_GETC(s, nhr->nexthop_num);
 
        for (i = 0; i < nhr->nexthop_num; i++) {
+               STREAM_GETL(s, nhr->nexthops[i].vrf_id);
                STREAM_GETC(s, nhr->nexthops[i].type);
                switch (nhr->nexthops[i].type) {
                case NEXTHOP_TYPE_IPV4:
@@ -1369,7 +1370,7 @@ static void zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id)
        memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ);
        /* overwrite default vrf */
        if (vrf_id == VRF_DEFAULT)
-               vrf_set_default_name(vrfname_tmp);
+               vrf_set_default_name(vrfname_tmp, false);
        vrf_enable(vrf);
 }
 
@@ -1400,7 +1401,7 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id)
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* Lookup/create interface by name. */
-       ifp = if_get_by_name(ifname_tmp, vrf_id, 0);
+       ifp = if_get_by_name(ifname_tmp, vrf_id);
 
        zebra_interface_if_set_value(s, ifp);
 
@@ -1769,19 +1770,19 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s,
                                                  vrf_id_t vrf_id,
                                                  vrf_id_t *new_vrf_id)
 {
-       unsigned int ifindex;
+       char ifname[INTERFACE_NAMSIZ];
        struct interface *ifp;
        vrf_id_t new_id;
 
-       /* Get interface index. */
-       ifindex = stream_getl(s);
+       /* Read interface name. */
+       stream_get(ifname, s, INTERFACE_NAMSIZ);
 
        /* Lookup interface. */
-       ifp = if_lookup_by_index(ifindex, vrf_id);
+       ifp = if_lookup_by_name(ifname, vrf_id);
        if (ifp == NULL) {
                flog_err(EC_LIB_ZAPI_ENCODE,
-                        "INTERFACE_VRF_UPDATE: Cannot find IF %u in VRF %d",
-                        ifindex, vrf_id);
+                        "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d",
+                        ifname, vrf_id);
                return NULL;
        }
 
@@ -1839,24 +1840,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);
@@ -1882,8 +1888,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;