Skip to content

Commit

Permalink
Merge pull request FRRouting#14867 from opensourcerouting/zclient-opt…
Browse files Browse the repository at this point in the history
…ions-cleanup

*: clean up `zclient` options
  • Loading branch information
donaldsharp committed Nov 25, 2023
2 parents ca8fb16 + 5a40f2b commit 0dc7704
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 55 deletions.
5 changes: 1 addition & 4 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -3422,9 +3422,6 @@ static void bgp_zebra_capabilities(struct zclient_capabilities *cap)

void bgp_zebra_init(struct event_loop *master, unsigned short instance)
{
struct zclient_options options = zclient_options_default;

options.synchronous = true;
zclient_num_connects = 0;

hook_register_prio(if_real, 0, bgp_ifp_create);
Expand All @@ -3442,7 +3439,7 @@ void bgp_zebra_init(struct event_loop *master, unsigned short instance)
zclient->instance = instance;

/* Initialize special zclient for synchronous message exchanges. */
zclient_sync = zclient_new(master, &options, NULL, 0);
zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_BGP;
zclient_sync->instance = instance;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/rfapi/vnc_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ static zclient_handler *const vnc_handlers[] = {
void vnc_zebra_init(struct event_loop *master)
{
/* Set default values. */
zclient_vnc = zclient_new(master, &zclient_options_default,
zclient_vnc = zclient_new(master, &zclient_options_auxiliary,
vnc_handlers, array_size(vnc_handlers));
zclient_init(zclient_vnc, ZEBRA_ROUTE_VNC, 0, &bgpd_privs);
}
Expand Down
4 changes: 1 addition & 3 deletions eigrpd/eigrp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ static zclient_handler *const eigrp_handlers[] = {

void eigrp_zebra_init(void)
{
struct zclient_options opt = {.receive_notify = false};

zclient = zclient_new(master, &opt, eigrp_handlers,
zclient = zclient_new(master, &zclient_options_default, eigrp_handlers,
array_size(eigrp_handlers));

zclient_init(zclient, ZEBRA_ROUTE_EIGRP, 0, &eigrpd_privs);
Expand Down
4 changes: 1 addition & 3 deletions isisd/isis_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,9 +1395,7 @@ void isis_zebra_init(struct event_loop *master, int instance)
zclient->zebra_connected = isis_zebra_connected;

/* Initialize special zclient for synchronous message exchanges. */
struct zclient_options options = zclient_options_default;
options.synchronous = true;
zclient_sync = zclient_new(master, &options, NULL, 0);
zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_ISIS;
zclient_sync->instance = instance;
Expand Down
6 changes: 1 addition & 5 deletions ldpd/lde.c
Original file line number Diff line number Diff line change
Expand Up @@ -2135,12 +2135,8 @@ static void zclient_sync_retry(struct event *thread)
*/
static void zclient_sync_init(void)
{
struct zclient_options options = zclient_options_default;

options.synchronous = true;

/* Initialize special zclient for synchronous message exchanges. */
zclient_sync = zclient_new(master, &options, NULL, 0);
zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_LDP;
zclient_sync->session_id = 1; /* Distinguish from main session */
Expand Down
27 changes: 18 additions & 9 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ static void zclient_event(enum zclient_event, struct zclient *);
static void zebra_interface_if_set_value(struct stream *s,
struct interface *ifp);

struct zclient_options zclient_options_default = {.receive_notify = false,
.synchronous = false};
const struct zclient_options zclient_options_default = {
.synchronous = false,
.auxiliary = false,
};

const struct zclient_options zclient_options_sync = {
.synchronous = true,
.auxiliary = true,
};

const struct zclient_options zclient_options_auxiliary = {
.synchronous = false,
.auxiliary = true,
};

struct sockaddr_storage zclient_addr;
socklen_t zclient_addr_len;
Expand All @@ -52,7 +64,7 @@ static int zclient_debug;

/* Allocate zclient structure. */
struct zclient *zclient_new(struct event_loop *master,
struct zclient_options *opt,
const struct zclient_options *opt,
zclient_handler *const *handlers, size_t n_handlers)
{
struct zclient *zclient;
Expand All @@ -69,8 +81,8 @@ struct zclient *zclient_new(struct event_loop *master,
zclient->handlers = handlers;
zclient->n_handlers = n_handlers;

zclient->receive_notify = opt->receive_notify;
zclient->synchronous = opt->synchronous;
zclient->auxiliary = opt->auxiliary;

return zclient;
}
Expand Down Expand Up @@ -392,10 +404,6 @@ enum zclient_send_status zclient_send_hello(struct zclient *zclient)
stream_putc(s, zclient->redist_default);
stream_putw(s, zclient->instance);
stream_putl(s, zclient->session_id);
if (zclient->receive_notify)
stream_putc(s, 1);
else
stream_putc(s, 0);
if (zclient->synchronous)
stream_putc(s, 1);
else
Expand Down Expand Up @@ -4444,7 +4452,8 @@ static void zclient_read(struct event *thread)
zlog_debug("zclient %p command %s VRF %u", zclient,
zserv_command_string(command), vrf_id);

if (command < array_size(lib_handlers) && lib_handlers[command])
if (!zclient->auxiliary && command < array_size(lib_handlers) &&
lib_handlers[command])
lib_handlers[command](command, zclient, length, vrf_id);
if (command < zclient->n_handlers && zclient->handlers[command])
zclient->handlers[command](command, zclient, length, vrf_id);
Expand Down
21 changes: 15 additions & 6 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,14 @@ struct zclient {
/* Privileges to change socket values */
struct zebra_privs_t *privs;

/* Do we care about failure events for route install? */
bool receive_notify;

/* Is this a synchronous client? */
bool synchronous;

/* Auxiliary clients don't execute standard library handlers
* (which otherwise would duplicate VRF/interface add/delete/etc.
*/
bool auxiliary;

/* BFD enabled with bfd_protocol_integration_init() */
bool bfd_integration;

Expand Down Expand Up @@ -834,11 +836,18 @@ extern char *zclient_evpn_dump_macip_flags(uint8_t flags, char *buf,
enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };

struct zclient_options {
bool receive_notify;
bool synchronous;

/* auxiliary = don't call common lib/ handlers that manage bits.
* Those should only run once, on the "main" zclient, which this is
* not. (This is also set for synchronous clients.)
*/
bool auxiliary;
};

extern struct zclient_options zclient_options_default;
extern const struct zclient_options zclient_options_default;
extern const struct zclient_options zclient_options_sync;
extern const struct zclient_options zclient_options_auxiliary;

/* link layer representation for GRE like interfaces
* ip_in is the underlay IP, ip_out is the tunnel dest
Expand Down Expand Up @@ -885,7 +894,7 @@ int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in,
extern uint32_t zclient_get_nhg_start(uint32_t proto);

extern struct zclient *zclient_new(struct event_loop *m,
struct zclient_options *opt,
const struct zclient_options *opt,
zclient_handler *const *handlers,
size_t n_handlers);

Expand Down
4 changes: 1 addition & 3 deletions ospfd/ospf_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,9 +2189,7 @@ void ospf_zebra_init(struct event_loop *master, unsigned short instance)
zclient->nexthop_update = ospf_zebra_import_check_update;

/* Initialize special zclient for synchronous message exchanges. */
struct zclient_options options = zclient_options_default;
options.synchronous = true;
zclient_sync = zclient_new(master, &options, NULL, 0);
zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_OSPF;
zclient_sync->instance = instance;
Expand Down
5 changes: 1 addition & 4 deletions pathd/path_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,14 @@ static zclient_handler *const path_handlers[] = {
*/
void path_zebra_init(struct event_loop *master)
{
struct zclient_options options = zclient_options_default;
options.synchronous = true;

/* Initialize asynchronous zclient. */
zclient = zclient_new(master, &zclient_options_default, path_handlers,
array_size(path_handlers));
zclient_init(zclient, ZEBRA_ROUTE_SRTE, 0, &pathd_privs);
zclient->zebra_connected = path_zebra_connected;

/* Initialize special zclient for synchronous message exchanges. */
zclient_sync = zclient_new(master, &options, NULL, 0);
zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_SRTE;
zclient_sync->instance = 1;
Expand Down
6 changes: 3 additions & 3 deletions pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS)
static void zebra_connected(struct zclient *zclient)
{
DEBUGD(&pbr_dbg_zebra, "%s: Registering for fun and profit", __func__);

zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true);
zclient_send_reg_requests(zclient, VRF_DEFAULT);
}

Expand Down Expand Up @@ -401,9 +403,7 @@ static zclient_handler *const pbr_handlers[] = {

void pbr_zebra_init(void)
{
struct zclient_options opt = { .receive_notify = true };

zclient = zclient_new(master, &opt, pbr_handlers,
zclient = zclient_new(master, &zclient_options_default, pbr_handlers,
array_size(pbr_handlers));

zclient_init(zclient, ZEBRA_ROUTE_PBR, 0, &pbr_privs);
Expand Down
5 changes: 1 addition & 4 deletions pimd/pim_zlookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ void zclient_lookup_free(void)

void zclient_lookup_new(void)
{
struct zclient_options options = zclient_options_default;
options.synchronous = true;

zlookup = zclient_new(router->master, &options, NULL, 0);
zlookup = zclient_new(router->master, &zclient_options_sync, NULL, 0);
if (!zlookup) {
flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_new() failure",
__func__);
Expand Down
5 changes: 2 additions & 3 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS)

static void zebra_connected(struct zclient *zclient)
{
zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true);
zclient_send_reg_requests(zclient, VRF_DEFAULT);

/*
Expand Down Expand Up @@ -1067,14 +1068,12 @@ static zclient_handler *const sharp_handlers[] = {

void sharp_zebra_init(void)
{
struct zclient_options opt = {.receive_notify = true};

hook_register_prio(if_real, 0, sharp_ifp_create);
hook_register_prio(if_up, 0, sharp_ifp_up);
hook_register_prio(if_down, 0, sharp_ifp_down);
hook_register_prio(if_unreal, 0, sharp_ifp_destroy);

zclient = zclient_new(master, &opt, sharp_handlers,
zclient = zclient_new(master, &zclient_options_default, sharp_handlers,
array_size(sharp_handlers));

zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
Expand Down
5 changes: 2 additions & 3 deletions staticd/static_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS)

static void zebra_connected(struct zclient *zclient)
{
zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true);
zclient_send_reg_requests(zclient, VRF_DEFAULT);

static_fixup_vrf_ids(vrf_info_lookup(VRF_DEFAULT));
Expand Down Expand Up @@ -531,14 +532,12 @@ static zclient_handler *const static_handlers[] = {

void static_zebra_init(void)
{
struct zclient_options opt = { .receive_notify = true };

hook_register_prio(if_real, 0, static_ifp_create);
hook_register_prio(if_up, 0, static_ifp_up);
hook_register_prio(if_down, 0, static_ifp_down);
hook_register_prio(if_unreal, 0, static_ifp_destroy);

zclient = zclient_new(master, &opt, static_handlers,
zclient = zclient_new(master, &zclient_options_default, static_handlers,
array_size(static_handlers));

zclient_init(zclient, ZEBRA_ROUTE_STATIC, 0, &static_privs);
Expand Down
4 changes: 0 additions & 4 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2376,17 +2376,13 @@ static void zread_hello(ZAPI_HANDLER_ARGS)
/* type of protocol (lib/zebra.h) */
uint8_t proto;
unsigned short instance;
uint8_t notify;
uint8_t synchronous;
uint32_t session_id;

STREAM_GETC(msg, proto);
STREAM_GETW(msg, instance);
STREAM_GETL(msg, session_id);
STREAM_GETC(msg, notify);
STREAM_GETC(msg, synchronous);
if (notify)
client->notify_owner = true;

if (synchronous)
client->synchronous = true;
Expand Down

0 comments on commit 0dc7704

Please sign in to comment.