]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/label_manager.c
eigrpd: eigrp usage of uint32_t to struct in_addr for router_id data
[mirror_frr.git] / zebra / label_manager.c
index 9bfc4001b66aa7a557ec458750194971a7858384..bfad8ea643f7aac5cec4e4e43211aa0639644387 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <zebra.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
-#include "zebra.h"
-#include "zserv.h"
 #include "lib/log.h"
 #include "lib/memory.h"
 #include "lib/mpls.h"
@@ -35,7 +34,9 @@
 #include "lib/zclient.h"
 #include "lib/libfrr.h"
 
-#include "label_manager.h"
+#include "zebra/zserv.h"
+#include "zebra/label_manager.h"
+#include "zebra/zebra_errors.h"
 
 #define CONNECTION_DELAY 5
 
@@ -82,11 +83,28 @@ static int relay_response_back(void)
        ret = zclient_read_header(src, zclient->sock, &size, &marker, &version,
                                  &vrf_id, &resp_cmd);
        if (ret < 0 && errno != EAGAIN) {
-               zlog_err("Error reading Label Manager response: %s",
+               flog_err(EC_ZEBRA_LM_RESPONSE,
+                        "Error reading Label Manager response: %s",
                         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;
 
@@ -99,9 +117,10 @@ static int relay_response_back(void)
        proto_str = zebra_route_string(proto);
 
        /* lookup the client to relay the msg to */
-       zserv = zebra_find_client(proto, instance);
+       zserv = zserv_find_client(proto, instance);
        if (!zserv) {
-               zlog_err(
+               flog_err(
+                       EC_ZEBRA_LM_NO_SUCH_CLIENT,
                        "Error relaying LM response: can't find client %s, instance %u",
                        proto_str, instance);
                return -1;
@@ -116,7 +135,8 @@ static int relay_response_back(void)
        /* send response back */
        ret = writen(zserv->sock, dst->data, stream_get_endp(dst));
        if (ret <= 0) {
-               zlog_err("Error relaying LM response to %s instance %u: %s",
+               flog_err(EC_ZEBRA_LM_RELAY_FAILED,
+                        "Error relaying LM response to %s instance %u: %s",
                         proto_str, instance, strerror(errno));
                return -1;
        }
@@ -135,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;
 }
 
@@ -183,7 +208,8 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
        unsigned short instance;
 
        if (zclient->sock < 0) {
-               zlog_err("Unable to relay LM request: no socket");
+               flog_err(EC_ZEBRA_LM_NO_SOCKET,
+                        "Unable to relay LM request: no socket");
                reply_error(cmd, zserv, vrf_id);
                return -1;
        }
@@ -204,14 +230,16 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
 
        /* check & set client proto if unset */
        if (zserv->proto && zserv->proto != proto) {
-               zlog_warn("Client proto(%u) != msg proto(%u)", zserv->proto,
+               flog_warn(EC_ZEBRAING_LM_PROTO_MISMATCH,
+                         "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)",
+               flog_err(EC_ZEBRA_LM_BAD_INSTANCE,
+                        "Client instance(%u) != msg instance(%u)",
                         zserv->instance, instance);
                return -1;
        }
@@ -221,8 +249,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;
@@ -233,7 +262,8 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
        /* Send request to external label manager */
        ret = writen(zclient->sock, dst->data, stream_get_endp(dst));
        if (ret <= 0) {
-               zlog_err("Error relaying LM request from %s instance %u: %s",
+               flog_err(EC_ZEBRA_LM_RELAY_FAILED,
+                        "Error relaying LM request from %s instance %u: %s",
                         proto_str, instance, strerror(errno));
                reply_error(cmd, zserv, vrf_id);
                return -1;
@@ -262,16 +292,15 @@ static int lm_zclient_connect(struct thread *t)
                return 0;
 
        if (zclient_socket_connect(zclient) < 0) {
-               zlog_err("Error connecting synchronous zclient!");
+               flog_err(EC_ZEBRA_LM_CLIENT_CONNECTION_FAILED,
+                        "Error connecting synchronous zclient!");
                thread_add_timer(zebrad.master, lm_zclient_connect, zclient,
                                 CONNECTION_DELAY, &zclient->t_connect);
                return -1;
        }
 
        /* make socket non-blocking */
-       if (set_nonblocking(zclient->sock) < 0)
-               zlog_warn("%s: set_nonblocking(%d) failed", __func__,
-                         zclient->sock);
+       (void)set_nonblocking(zclient->sock);
 
        return 0;
 }
@@ -289,7 +318,7 @@ static void lm_zclient_init(char *lm_zserv_path)
                                 lm_zserv_path);
 
        /* Set default values. */
-       zclient = zclient_new_notify(zebrad.master, &zclient_options_default);
+       zclient = zclient_new(zebrad.master, &zclient_options_default);
        zclient->privs = &zserv_privs;
        zclient->sock = -1;
        zclient->t_connect = NULL;
@@ -384,8 +413,6 @@ struct label_manager_chunk *assign_label_chunk(uint8_t proto,
        }
        /* otherwise create a new one */
        lmc = XCALLOC(MTYPE_LM_CHUNK, sizeof(struct label_manager_chunk));
-       if (!lmc)
-               return NULL;
 
        if (list_isempty(lbl_mgr.lc_list))
                lmc->start = MPLS_LABEL_UNRESERVED_MIN;
@@ -395,7 +422,8 @@ struct label_manager_chunk *assign_label_chunk(uint8_t proto,
                                     ->end
                             + 1;
        if (lmc->start > MPLS_LABEL_UNRESERVED_MAX - size + 1) {
-               zlog_err("Reached max labels. Start: %u, size: %u", lmc->start,
+               flog_err(EC_ZEBRA_LM_EXHAUSTED_LABELS,
+                        "Reached max labels. Start: %u, size: %u", lmc->start,
                         size);
                XFREE(MTYPE_LM_CHUNK, lmc);
                return NULL;
@@ -434,7 +462,8 @@ int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
                if (lmc->end != end)
                        continue;
                if (lmc->proto != proto || lmc->instance != instance) {
-                       zlog_err("%s: Daemon mismatch!!", __func__);
+                       flog_err(EC_ZEBRA_LM_DAEMON_MISMATCH,
+                                "%s: Daemon mismatch!!", __func__);
                        continue;
                }
                lmc->proto = NO_PROTO;
@@ -444,7 +473,8 @@ int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
                break;
        }
        if (ret != 0)
-               zlog_err("%s: Label chunk not released!!", __func__);
+               flog_err(EC_ZEBRA_LM_UNRELEASED_CHUNK,
+                        "%s: Label chunk not released!!", __func__);
 
        return ret;
 }
@@ -452,6 +482,6 @@ 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);
+       list_delete(&lbl_mgr.lc_list);
        stream_free(obuf);
 }