#include "sharp_zebra.h"
/* Zebra structure to hold current status. */
-struct zclient *zclient = NULL;
+struct zclient *g_zclient = NULL;
/* For registering threads. */
extern struct event_loop *master;
DEFINE_MTYPE_STATIC(SHARPD, ZC, "Test zclients");
/* Struct to hold list of test zclients */
-struct sharp_zclient {
- struct sharp_zclient *prev;
- struct sharp_zclient *next;
+struct sharp_zclient_entry {
+ struct sharp_zclient_entry *prev;
+ struct sharp_zclient_entry *next;
struct zclient *client;
};
/* Head of test zclient list */
-static struct sharp_zclient *sharp_clients_head;
+static struct sharp_zclient_entry *sharp_clients_head;
static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS);
/* Utility to add a test zclient struct to the list */
static void add_zclient(struct zclient *client)
{
- struct sharp_zclient *node;
+ struct sharp_zclient_entry *node;
- node = XCALLOC(MTYPE_ZC, sizeof(struct sharp_zclient));
+ node = XCALLOC(MTYPE_ZC, sizeof(struct sharp_zclient_entry));
node->client = client;
cmd = ZEBRA_MPLS_LABELS_DELETE;
}
- if (zebra_send_mpls_labels(zclient, cmd, &zl) == ZCLIENT_SEND_FAILURE)
+ if (zebra_send_mpls_labels(g_zclient, cmd, &zl) == ZCLIENT_SEND_FAILURE)
return -1;
return 0;
memcpy(api.opaque.data, opaque, api.opaque.length);
}
- if (zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api) ==
+ if (zclient_route_send(ZEBRA_ROUTE_ADD, g_zclient, &api) ==
ZCLIENT_SEND_BUFFERED)
return true;
else
api.instance = instance;
memcpy(&api.prefix, p, sizeof(*p));
- if (zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api) ==
+ if (zclient_route_send(ZEBRA_ROUTE_DELETE, g_zclient, &api) ==
ZCLIENT_SEND_BUFFERED)
return true;
else
enum zapi_route_notify_owner note;
uint32_t table;
- if (!zapi_route_notify_decode(zclient->ibuf, &p, &table, ¬e, NULL,
+ if (!zapi_route_notify_decode(g_zclient->ibuf, &p, &table, ¬e, NULL,
NULL))
return -1;
void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label)
{
- zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
+ zclient_send_vrf_label(g_zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
}
void nhg_add(uint32_t id, const struct nexthop_group *nhg,
if (sharp_nhgroup_id_is_installed(id)) {
zlog_debug("%s: nhg %u: no nexthops, deleting nexthop group", __func__,
id);
- zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg);
+ zclient_nhg_send(g_zclient, ZEBRA_NHG_DEL, &api_nhg);
return;
}
zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__,
done:
if (is_valid)
- zclient_nhg_send(zclient, ZEBRA_NHG_ADD, &api_nhg);
+ zclient_nhg_send(g_zclient, ZEBRA_NHG_ADD, &api_nhg);
}
void nhg_del(uint32_t id)
api_nhg.id = id;
- zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg);
+ zclient_nhg_send(g_zclient, ZEBRA_NHG_DEL, &api_nhg);
}
void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import, bool watch,
if (!watch)
command = ZEBRA_NEXTHOP_UNREGISTER;
- if (zclient_send_rnh(zclient, command, p, safi, connected, false, vrf_id) ==
+ if (zclient_send_rnh(g_zclient, command, p, safi, connected, false, vrf_id) ==
ZCLIENT_SEND_FAILURE)
zlog_warn("%s: Failure to send nexthop to zebra", __func__);
}
{
zebra_redistribute_send(turn_on ? ZEBRA_REDISTRIBUTE_ADD
: ZEBRA_REDISTRIBUTE_DELETE,
- zclient, AFI_IP, type, 0, vrf->vrf_id);
+ g_zclient, AFI_IP, type, 0, vrf->vrf_id);
}
static zclient_handler *const sharp_opaque_handlers[] = {
int sharp_zclient_create(uint32_t session_id)
{
struct zclient *client;
- struct sharp_zclient *node;
+ struct sharp_zclient_entry *node;
/* Check for duplicates */
for (node = sharp_clients_head; node != NULL; node = node->next) {
/* Delete one of the extra test zclients */
int sharp_zclient_delete(uint32_t session_id)
{
- struct sharp_zclient *node;
+ struct sharp_zclient_entry *node;
/* Search for session */
for (node = sharp_clients_head; node != NULL; node = node->next) {
/* Send some messages - broadcast and unicast are supported */
for (i = 0; i < count; i++) {
if (proto == 0)
- ret = zclient_send_opaque(zclient, type, buf,
+ ret = zclient_send_opaque(g_zclient, type, buf,
sizeof(buf));
else
- ret = zclient_send_opaque_unicast(zclient, type, proto,
+ ret = zclient_send_opaque_unicast(g_zclient, type, proto,
instance, session_id,
buf, sizeof(buf));
if (ret == ZCLIENT_SEND_FAILURE) {
void sharp_zebra_opaque_notif_reg(bool is_reg, uint32_t type)
{
if (is_reg)
- zclient_opaque_request_notify(zclient, type);
+ zclient_opaque_request_notify(g_zclient, type);
else
- zclient_opaque_drop_notify(zclient, type);
+ zclient_opaque_drop_notify(g_zclient, type);
}
/*
{
struct stream *s;
- s = zclient->obuf;
+ s = g_zclient->obuf;
stream_reset(s);
if (is_reg)
/* Put length at the first point of the stream. */
stream_putw_at(s, 0, stream_get_endp(s));
- (void)zclient_send_message(zclient);
+ (void)zclient_send_message(g_zclient);
}
/* Link State registration */
void sharp_zebra_register_te(void)
{
/* First register to received Link State Update messages */
- zclient_register_opaque(zclient, LINK_STATE_UPDATE);
+ zclient_register_opaque(g_zclient, LINK_STATE_UPDATE);
/* Then, request initial TED with SYNC message */
- ls_request_sync(zclient);
+ ls_request_sync(g_zclient);
}
void sharp_zebra_send_arp(const struct interface *ifp, const struct prefix *p)
{
- zclient_send_neigh_discovery_req(zclient, ifp, p);
+ zclient_send_neigh_discovery_req(g_zclient, ifp, p);
}
static int nhg_notify_owner(ZAPI_CALLBACK_ARGS)
int sharp_zebra_srv6_manager_get_locator_chunk(const char *locator_name)
{
- return srv6_manager_get_locator_chunk(zclient, locator_name);
+ return srv6_manager_get_locator_chunk(g_zclient, locator_name);
}
int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name)
{
- return srv6_manager_release_locator_chunk(zclient, locator_name);
+ return srv6_manager_release_locator_chunk(g_zclient, locator_name);
}
static int sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
zlog_debug("Sending zebra to set %s protodown %s", ifp->name,
down ? "on" : "off");
- if (zclient_send_interface_protodown(zclient, ifp->vrf->vrf_id, ifp,
+ if (zclient_send_interface_protodown(g_zclient, ifp->vrf->vrf_id, ifp,
down) == ZCLIENT_SEND_FAILURE)
return -1;
#define SHARPD_TC_HANDLE 0x0001
struct stream *s;
- s = zclient->obuf;
+ s = g_zclient->obuf;
struct tc_qdisc q = {.ifindex = ifp->ifindex, .kind = TC_QDISC_HTB};
zapi_tc_qdisc_encode(ZEBRA_TC_QDISC_INSTALL, s, &q);
- if (zclient_send_message(zclient) == ZCLIENT_SEND_FAILURE)
+ if (zclient_send_message(g_zclient) == ZCLIENT_SEND_FAILURE)
return -1;
struct tc_class c = {.ifindex = ifp->ifindex,
.u.htb.rate = rate};
zapi_tc_class_encode(ZEBRA_TC_CLASS_ADD, s, &c);
- if (zclient_send_message(zclient) == ZCLIENT_SEND_FAILURE)
+ if (zclient_send_message(g_zclient) == ZCLIENT_SEND_FAILURE)
return -1;
struct tc_filter f = {.ifindex = ifp->ifindex,
f.u.flower.classid = SHARPD_TC_HANDLE & 0xffff;
zapi_tc_filter_encode(ZEBRA_TC_FILTER_ADD, s, &f);
- if (zclient_send_message(zclient) == ZCLIENT_SEND_FAILURE)
+ if (zclient_send_message(g_zclient) == ZCLIENT_SEND_FAILURE)
return -1;
return 0;
void sharp_zebra_register_neigh(vrf_id_t vrf_id, afi_t afi, bool reg)
{
- zclient_register_neigh(zclient, vrf_id, afi, reg);
+ zclient_register_neigh(g_zclient, vrf_id, afi, reg);
}
hook_register_prio(if_down, 0, sharp_ifp_down);
hook_register_prio(if_unreal, 0, sharp_ifp_destroy);
- zclient = zclient_new(master, &zclient_options_default, sharp_handlers,
- array_size(sharp_handlers));
+ g_zclient = zclient_new(master, &zclient_options_default, sharp_handlers,
+ array_size(sharp_handlers));
- zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
- zclient->zebra_connected = zebra_connected;
- zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready;
- zclient->nexthop_update = sharp_nexthop_update;
+ zclient_init(g_zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
+ g_zclient->zebra_connected = zebra_connected;
+ g_zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready;
+ g_zclient->nexthop_update = sharp_nexthop_update;
}
void sharp_zebra_terminate(void)
{
- struct sharp_zclient *node = sharp_clients_head;
+ struct sharp_zclient_entry *node = sharp_clients_head;
while (node) {
sharp_zclient_delete(node->client->session_id);
node = sharp_clients_head;
}
- zclient_stop(zclient);
- zclient_free(zclient);
+ zclient_stop(g_zclient);
+ zclient_free(g_zclient);
}