From edb386a0a35dbb25b0697011a1b3df79dc4b5b02 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 15 Jan 2020 02:19:47 -0500 Subject: [PATCH] zebra: try to optimize a bit more try to avoid mutex locks, thread schedules, etc. --- zebra/zserv.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zebra/zserv.c b/zebra/zserv.c index 3cc0f5b2b8..8e23eda8b5 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -464,6 +464,9 @@ zread_fail: static void zserv_client_event(struct zserv *client, enum zserv_client_event event) { +#ifdef FUZZING + return; +#endif switch (event) { case ZSERV_CLIENT_READ: thread_add_read(client->pthread->master, zserv_read, client, @@ -535,6 +538,10 @@ static int zserv_process_messages(struct thread *thread) int zserv_send_message(struct zserv *client, struct stream *msg) { +#ifdef FUZZING + stream_free(msg); + return 0; +#endif frr_with_mutex(&client->obuf_mtx) { stream_fifo_push(client->obuf_fifo, msg); } @@ -592,7 +599,9 @@ static void zserv_client_free(struct zserv *client) unsigned long nroutes; unsigned long nnhgs; +#ifndef FUZZING close(client->sock); +#endif if (DYNAMIC_CLIENT_GR_DISABLED(client)) { zebra_mpls_client_cleanup_vrf_label(client->proto); @@ -626,9 +635,11 @@ static void zserv_client_free(struct zserv *client) if (client->wb) buffer_free(client->wb); +#ifndef FUZZING /* Free buffer mutexes */ pthread_mutex_destroy(&client->obuf_mtx); pthread_mutex_destroy(&client->ibuf_mtx); +#endif /* Free bitmaps. */ for (afi_t afi = AFI_IP; afi < AFI_MAX; afi++) { @@ -668,6 +679,7 @@ void zserv_close_client(struct zserv *client) bool free_p = true; if (client->pthread) { +#ifndef FUZZING /* synchronously stop and join pthread */ frr_pthread_stop(client->pthread, NULL); @@ -682,6 +694,7 @@ void zserv_close_client(struct zserv *client) /* destroy pthread */ frr_pthread_destroy(client->pthread); client->pthread = NULL; +#endif } /* @@ -748,8 +761,10 @@ struct zserv *zserv_client_create(int sock) client->obuf_fifo = stream_fifo_new(); client->ibuf_work = stream_new(stream_size); client->obuf_work = stream_new(stream_size); +#ifndef FUZZING pthread_mutex_init(&client->ibuf_mtx, NULL); pthread_mutex_init(&client->obuf_mtx, NULL); +#endif client->wb = buffer_new(0); TAILQ_INIT(&(client->gr_info_queue)); @@ -770,6 +785,7 @@ struct zserv *zserv_client_create(int sock) listnode_add(zrouter.client_list, client); } +#ifndef FUZZING struct frr_pthread_attr zclient_pthr_attrs = { .start = frr_pthread_attr_default.start, .stop = frr_pthread_attr_default.stop @@ -780,6 +796,7 @@ struct zserv *zserv_client_create(int sock) /* start read loop */ zserv_client_event(client, ZSERV_CLIENT_READ); +#endif /* call callbacks */ hook_call(zserv_client_connect, client); @@ -962,6 +979,9 @@ void zserv_start(char *path) void zserv_event(struct zserv *client, enum zserv_event event) { +#ifdef FUZZING + return; +#endif switch (event) { case ZSERV_ACCEPT: thread_add_read(zrouter.master, zserv_accept, NULL, zsock, -- 2.39.5