zebra: Move the master thread handler to the zrouter structure

The master thread handler is really part of the zrouter structure.
So let's move it over to that.  Eventually zserv.h will only be
used for zapi messages.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2019-01-11 13:31:46 -05:00
parent 19b336d343
commit 3801e7646c
20 changed files with 66 additions and 61 deletions

View File

@ -41,7 +41,7 @@
#include "zebra/interface.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/irdp.h"
@ -153,7 +153,7 @@ static int if_zebra_new_hook(struct interface *ifp)
* of seconds and ask again. Hopefully it's all settled
* down upon startup.
*/
thread_add_timer(zebrad.master, if_zebra_speed_update, ifp, 15,
thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 15,
&zebra_if->speed_update);
return 0;
}

View File

@ -45,7 +45,7 @@
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/irdp.h"
#include "zebra/zebra_errors.h"
@ -285,7 +285,7 @@ static void irdp_if_start(struct interface *ifp, int multicast,
timer);
irdp->t_advertise = NULL;
thread_add_timer(zebrad.master, irdp_send_thread, ifp, timer,
thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
&irdp->t_advertise);
}

View File

@ -56,7 +56,7 @@
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/irdp.h"
#include "zebra/zebra_errors.h"
@ -113,7 +113,7 @@ int irdp_sock_init(void)
};
t_irdp_raw = NULL;
thread_add_read(zebrad.master, irdp_read_raw, NULL, sock, &t_irdp_raw);
thread_add_read(zrouter.master, irdp_read_raw, NULL, sock, &t_irdp_raw);
return sock;
}
@ -245,7 +245,7 @@ int irdp_send_thread(struct thread *t_advert)
timer);
irdp->t_advertise = NULL;
thread_add_timer(zebrad.master, irdp_send_thread, ifp, timer,
thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
&irdp->t_advertise);
return 0;
}
@ -306,7 +306,7 @@ void process_solicit(struct interface *ifp)
timer = (random() % MAX_RESPONSE_DELAY) + 1;
irdp->t_advertise = NULL;
thread_add_timer(zebrad.master, irdp_send_thread, ifp, timer,
thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
&irdp->t_advertise);
}

View File

@ -58,7 +58,7 @@
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/irdp.h"
#include "zebra/zebra_errors.h"
@ -230,7 +230,7 @@ int irdp_read_raw(struct thread *r)
int irdp_sock = THREAD_FD(r);
t_irdp_raw = NULL;
thread_add_read(zebrad.master, irdp_read_raw, NULL, irdp_sock,
thread_add_read(zrouter.master, irdp_read_raw, NULL, irdp_sock,
&t_irdp_raw);
ret = irdp_recvmsg(irdp_sock, (uint8_t *)buf, IRDP_RX_BUF, &ifindex);

View File

@ -43,7 +43,8 @@
#include "mpls.h"
#include "lib_errors.h"
#include "zebra/zserv.h"
//#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_ns.h"
#include "zebra/zebra_vrf.h"
#include "zebra/rt.h"
@ -388,7 +389,7 @@ static int kernel_read(struct thread *thread)
netlink_parse_info(netlink_information_fetch, &zns->netlink, &dp_info,
5, 0);
zns->t_netlink = NULL;
thread_add_read(zebrad.master, kernel_read, zns, zns->netlink.sock,
thread_add_read(zrouter.master, kernel_read, zns, zns->netlink.sock,
&zns->t_netlink);
return 0;
@ -1158,7 +1159,7 @@ void kernel_init(struct zebra_ns *zns)
zns->t_netlink = NULL;
thread_add_read(zebrad.master, kernel_read, zns,
thread_add_read(zrouter.master, kernel_read, zns,
zns->netlink.sock, &zns->t_netlink);
rt_netlink_init();

View File

@ -43,7 +43,7 @@
#include "zebra/rt.h"
#include "zebra/interface.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/debug.h"
#include "zebra/kernel_socket.h"
#include "zebra/rib.h"
@ -1372,7 +1372,7 @@ static int kernel_read(struct thread *thread)
return 0;
}
thread_add_read(zebrad.master, kernel_read, NULL, sock, NULL);
thread_add_read(zrouter.master, kernel_read, NULL, sock, NULL);
if (IS_ZEBRA_DEBUG_KERNEL)
rtmsg_debug(&buf.r.rtm);
@ -1445,7 +1445,7 @@ static void routing_socket(struct zebra_ns *zns)
zlog_warn ("Can't set O_NONBLOCK to routing socket");*/
/* kernel_read needs rewrite. */
thread_add_read(zebrad.master, kernel_read, NULL, routing_sock, NULL);
thread_add_read(zrouter.master, kernel_read, NULL, routing_sock, NULL);
}
/* Exported interface function. This function simply calls

View File

@ -34,7 +34,8 @@
#include "lib/zclient.h"
#include "lib/libfrr.h"
#include "zebra/zserv.h"
//#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/label_manager.h"
#include "zebra/zebra_errors.h"
@ -294,7 +295,7 @@ static int lm_zclient_connect(struct thread *t)
if (zclient_socket_connect(zclient) < 0) {
flog_err(EC_ZEBRA_LM_CLIENT_CONNECTION_FAILED,
"Error connecting synchronous zclient!");
thread_add_timer(zebrad.master, lm_zclient_connect, zclient,
thread_add_timer(zrouter.master, lm_zclient_connect, zclient,
CONNECTION_DELAY, &zclient->t_connect);
return -1;
}
@ -318,7 +319,7 @@ static void lm_zclient_init(char *lm_zserv_path)
lm_zserv_path);
/* Set default values. */
zclient = zclient_new(zebrad.master, &zclient_options_default);
zclient = zclient_new(zrouter.master, &zclient_options_default);
zclient->privs = &zserv_privs;
zclient->sock = -1;
zclient->t_connect = NULL;

View File

@ -391,7 +391,7 @@ int main(int argc, char **argv)
}
}
zebrad.master = frr_init();
zrouter.master = frr_init();
/* Initialize pthread library */
frr_pthread_init();
@ -479,7 +479,7 @@ int main(int argc, char **argv)
#endif /* HANDLE_NETLINK_FUZZING */
frr_run(zebrad.master);
frr_run(zrouter.master);
/* Not reached... */
return 0;

View File

@ -1698,9 +1698,9 @@ static void rtadv_event(struct zebra_ns *zns, enum rtadv_event event, int val)
switch (event) {
case RTADV_START:
thread_add_read(zebrad.master, rtadv_read, zns, val,
thread_add_read(zrouter.master, rtadv_read, zns, val,
&rtadv->ra_read);
thread_add_event(zebrad.master, rtadv_timer, zns, 0,
thread_add_event(zrouter.master, rtadv_timer, zns, 0,
&rtadv->ra_timer);
break;
case RTADV_STOP:
@ -1714,15 +1714,15 @@ static void rtadv_event(struct zebra_ns *zns, enum rtadv_event event, int val)
}
break;
case RTADV_TIMER:
thread_add_timer(zebrad.master, rtadv_timer, zns, val,
thread_add_timer(zrouter.master, rtadv_timer, zns, val,
&rtadv->ra_timer);
break;
case RTADV_TIMER_MSEC:
thread_add_timer_msec(zebrad.master, rtadv_timer, zns, val,
thread_add_timer_msec(zrouter.master, rtadv_timer, zns, val,
&rtadv->ra_timer);
break;
case RTADV_READ:
thread_add_read(zebrad.master, rtadv_read, zns, val,
thread_add_read(zrouter.master, rtadv_read, zns, val,
&rtadv->ra_read);
break;
default:

View File

@ -26,7 +26,7 @@
#include "lib/zebra.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_memory.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_dplane.h"
#include "zebra/rt.h"
#include "zebra/debug.h"
@ -1802,7 +1802,7 @@ static int dplane_check_shutdown_status(struct thread *event)
/* We appear to be done - schedule a final callback event
* for the zebra main pthread.
*/
thread_add_event(zebrad.master, zebra_finalize, NULL, 0, NULL);
thread_add_event(zrouter.master, zebra_finalize, NULL, 0, NULL);
}
return 0;

View File

@ -40,6 +40,7 @@
#include "zebra/rt.h"
#include "zebra/interface.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/zebra_memory.h"
@ -1716,7 +1717,7 @@ static char *snhlfe2str(zebra_snhlfe_t *snhlfe, char *buf, int size)
*/
static int mpls_processq_init(struct zebra_t *zebra)
{
zebra->lsp_process_q = work_queue_new(zebra->master, "LSP processing");
zebra->lsp_process_q = work_queue_new(zrouter.master, "LSP processing");
if (!zebra->lsp_process_q) {
flog_err(EC_ZEBRA_WQ_NONEXISTENT,
"%s: could not initialise work queue!", __func__);

View File

@ -36,7 +36,7 @@
#include "memory.h"
#include "lib_errors.h"
#include "zserv.h"
#include "zebra_router.h"
#include "zebra_memory.h"
#endif /* defined(HAVE_NETLINK) */
@ -121,7 +121,7 @@ static int zebra_ns_continue_read(struct zebra_netns_info *zns_info,
XFREE(MTYPE_NETNS_MISC, zns_info);
return 0;
}
thread_add_timer_msec(zebrad.master, zebra_ns_ready_read,
thread_add_timer_msec(zrouter.master, zebra_ns_ready_read,
(void *)zns_info, ZEBRA_NS_POLLING_INTERVAL_MSEC,
NULL);
return 0;
@ -242,7 +242,7 @@ static int zebra_ns_notify_read(struct thread *t)
ssize_t len;
zebra_netns_notify_current = thread_add_read(
zebrad.master, zebra_ns_notify_read, NULL, fd_monitor, NULL);
zrouter.master, zebra_ns_notify_read, NULL, fd_monitor, NULL);
len = read(fd_monitor, buf, sizeof(buf));
if (len < 0) {
flog_err_sys(EC_ZEBRA_NS_NOTIFY_READ,
@ -284,7 +284,7 @@ static int zebra_ns_notify_read(struct thread *t)
sizeof(struct zebra_netns_info));
netnsinfo->retries = ZEBRA_NS_POLLING_MAX_RETRIES;
netnsinfo->netnspath = netnspath;
thread_add_timer_msec(zebrad.master, zebra_ns_ready_read,
thread_add_timer_msec(zrouter.master, zebra_ns_ready_read,
(void *)netnsinfo, 0, NULL);
}
return 0;
@ -355,7 +355,7 @@ void zebra_ns_notify_init(void)
safe_strerror(errno));
}
zebra_netns_notify_current = thread_add_read(
zebrad.master, zebra_ns_notify_read, NULL, fd_monitor, NULL);
zrouter.master, zebra_ns_notify_read, NULL, fd_monitor, NULL);
}
void zebra_ns_notify_close(void)

View File

@ -187,12 +187,12 @@ static int zebra_ptm_flush_messages(struct thread *thread)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return (-1);
case BUFFER_PENDING:
ptm_cb.t_write = NULL;
thread_add_write(zebrad.master, zebra_ptm_flush_messages, NULL,
thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
ptm_cb.ptm_sock, &ptm_cb.t_write);
break;
case BUFFER_EMPTY:
@ -213,14 +213,14 @@ static int zebra_ptm_send_message(char *data, int size)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return -1;
case BUFFER_EMPTY:
THREAD_OFF(ptm_cb.t_write);
break;
case BUFFER_PENDING:
thread_add_write(zebrad.master, zebra_ptm_flush_messages, NULL,
thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
ptm_cb.ptm_sock, &ptm_cb.t_write);
break;
}
@ -240,7 +240,7 @@ int zebra_ptm_connect(struct thread *t)
if (ptm_cb.ptm_sock != -1) {
if (init) {
ptm_cb.t_read = NULL;
thread_add_read(zebrad.master, zebra_ptm_sock_read,
thread_add_read(zrouter.master, zebra_ptm_sock_read,
NULL, ptm_cb.ptm_sock, &ptm_cb.t_read);
zebra_bfd_peer_replay_req();
}
@ -252,7 +252,7 @@ int zebra_ptm_connect(struct thread *t)
ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_MAX;
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
} else if (ptm_cb.reconnect_time >= ZEBRA_PTM_RECONNECT_TIME_MAX) {
ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL;
@ -657,14 +657,14 @@ int zebra_ptm_sock_read(struct thread *thread)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time,
&ptm_cb.t_timer);
return (-1);
}
ptm_cb.t_read = NULL;
thread_add_read(zebrad.master, zebra_ptm_sock_read, NULL,
thread_add_read(zrouter.master, zebra_ptm_sock_read, NULL,
ptm_cb.ptm_sock, &ptm_cb.t_read);
return 0;
@ -700,7 +700,7 @@ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@ -854,7 +854,7 @@ void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@ -981,7 +981,7 @@ void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@ -1039,7 +1039,7 @@ int zebra_ptm_bfd_client_deregister(struct zserv *client)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return 0;
}

View File

@ -27,7 +27,7 @@
#include "zebra/debug.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/zapi_msg.h"
#include "zebra/zebra_rnh.h"
#include "zebra/zebra_vrf.h"
@ -213,7 +213,7 @@ void zebra_pw_install_failure(struct zebra_pw *pw)
/* schedule to retry later */
THREAD_TIMER_OFF(pw->install_retry_timer);
thread_add_timer(zebrad.master, zebra_pw_install_retry, pw,
thread_add_timer(zrouter.master, zebra_pw_install_retry, pw,
PW_INSTALL_RETRY_INTERVAL, &pw->install_retry_timer);
zebra_pw_update_status(pw, PW_STATUS_DOWN);

View File

@ -2326,7 +2326,8 @@ static void rib_queue_init(struct zebra_t *zebra)
assert(zebra);
if (!(zebra->ribq =
work_queue_new(zebra->master, "route_node processing"))) {
work_queue_new(zrouter.master,
"route_node processing"))) {
flog_err(EC_ZEBRA_WQ_NONEXISTENT,
"%s: could not initialise work queue!", __func__);
return;
@ -3313,7 +3314,7 @@ static int rib_dplane_results(struct dplane_ctx_q *ctxlist)
pthread_mutex_unlock(&dplane_mutex);
/* Ensure event is signalled to zebra main pthread */
thread_add_event(zebrad.master, rib_process_dplane_results, NULL, 0,
thread_add_event(zrouter.master, rib_process_dplane_results, NULL, 0,
&t_dplane);
return 0;

View File

@ -33,7 +33,7 @@
#include "vrf.h"
#include "frrstr.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/zebra_rnh.h"
@ -1745,7 +1745,7 @@ static void zebra_route_map_mark_update(const char *rmap_name)
/* rmap_update_timer of 0 means don't do route updates */
if (zebra_rmap_update_timer && !zebra_t_rmap_update) {
zebra_t_rmap_update = NULL;
thread_add_timer(zebrad.master, zebra_route_map_update_timer,
thread_add_timer(zrouter.master, zebra_route_map_update_timer,
NULL, zebra_rmap_update_timer,
&zebra_t_rmap_update);
}

View File

@ -45,6 +45,8 @@ RB_PROTOTYPE(zebra_router_table_head, zebra_router_table,
zebra_router_table_entry, zebra_router_table_entry_compare)
struct zebra_router {
/* Thread master */
struct thread_master *master;
struct zebra_router_table_head tables;

View File

@ -50,7 +50,7 @@
#include "zebra/zebra_vrf.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_vxlan_private.h"
#include "zebra/zserv.h"
#include "zebra/zebra_router.h"
DEFINE_MTYPE_STATIC(ZEBRA, HOST_PREFIX, "host prefix");
DEFINE_MTYPE_STATIC(ZEBRA, ZVNI, "VNI hash");
@ -510,7 +510,7 @@ static void zebra_vxlan_dup_addr_detect_for_mac(struct zebra_vrf *zvrf,
sizeof(buf)),
mac->flags, zvrf->dad_freeze_time);
thread_add_timer(zebrad.master,
thread_add_timer(zrouter.master,
zebra_vxlan_dad_mac_auto_recovery_exp,
mac, zvrf->dad_freeze_time,
&mac->dad_mac_auto_recovery_timer);
@ -643,7 +643,7 @@ static void zebra_vxlan_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf,
ipaddr2str(&nbr->ip, buf1, sizeof(buf1)),
nbr->flags, zvrf->dad_freeze_time);
thread_add_timer(zebrad.master,
thread_add_timer(zrouter.master,
zebra_vxlan_dad_ip_auto_recovery_exp,
nbr, zvrf->dad_freeze_time,
&nbr->dad_ip_auto_recovery_timer);

View File

@ -61,6 +61,7 @@
#include "zebra/zapi_msg.h" /* for zserv_handle_commands */
#include "zebra/zebra_vrf.h" /* for zebra_vrf_lookup_by_id, zvrf */
#include "zebra/zserv.h" /* for zserv */
#include "zebra/zebra_router.h"
#include "zebra/zebra_errors.h" /* for error messages */
/* clang-format on */
@ -637,7 +638,7 @@ void zserv_close_client(struct zserv *client)
zlog_debug("Closing client '%s'",
zebra_route_string(client->proto));
thread_cancel_event(zebrad.master, client);
thread_cancel_event(zrouter.master, client);
THREAD_OFF(client->t_cleanup);
THREAD_OFF(client->t_process);
@ -834,15 +835,15 @@ void zserv_event(struct zserv *client, enum zserv_event event)
{
switch (event) {
case ZSERV_ACCEPT:
thread_add_read(zebrad.master, zserv_accept, NULL, zebrad.sock,
thread_add_read(zrouter.master, zserv_accept, NULL, zebrad.sock,
NULL);
break;
case ZSERV_PROCESS_MESSAGES:
thread_add_event(zebrad.master, zserv_process_messages, client,
thread_add_event(zrouter.master, zserv_process_messages, client,
0, &client->t_process);
break;
case ZSERV_HANDLE_CLIENT_FAIL:
thread_add_event(zebrad.master, zserv_handle_client_fail,
thread_add_event(zrouter.master, zserv_handle_client_fail,
client, 0, &client->t_cleanup);
}
}

View File

@ -175,8 +175,6 @@ DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client));
/* Zebra instance */
struct zebra_t {
/* Thread master */
struct thread_master *master;
struct list *client_list;
/* Socket */