* 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"
#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
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;
/* lookup the client to relay the msg to */
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;
/* 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;
}
/* 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;
}
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;
}
/* 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;
}
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;
/* 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;
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;
}
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;
->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;
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;
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;
}
void label_manager_close()
{
- list_delete_and_null(&lbl_mgr.lc_list);
+ list_delete(&lbl_mgr.lc_list);
stream_free(obuf);
}