From 9196731f9d13999e8358da953fa181cb021b4472 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Wed, 24 Oct 2018 06:27:17 +0200 Subject: [PATCH] isisd: Combine lsp_l1/l2_refresh lsp_l1_refresh and lsp_l2_refresh are identical apart from the hardcoded IS-IS level they are referring to. So merge them and pass the level as part of the argument. Signed-off-by: Christian Franke --- isisd/isis_lsp.c | 72 ++++++++++++++++-------------------------------- isisd/isisd.c | 7 +++++ isisd/isisd.h | 7 +++++ 3 files changed, 37 insertions(+), 49 deletions(-) diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 8320ad9d75..e01364dfec 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -59,8 +59,7 @@ #include "isisd/fabricd.h" #include "isisd/isis_tx_queue.h" -static int lsp_l1_refresh(struct thread *thread); -static int lsp_l2_refresh(struct thread *thread); +static int lsp_refresh(struct thread *thread); static int lsp_l1_refresh_pseudo(struct thread *thread); static int lsp_l2_refresh_pseudo(struct thread *thread); @@ -1251,12 +1250,9 @@ int lsp_generate(struct isis_area *area, int level) THREAD_TIMER_OFF(area->t_lsp_refresh[level - 1]); area->lsp_regenerate_pending[level - 1] = 0; - if (level == IS_LEVEL_1) - thread_add_timer(master, lsp_l1_refresh, area, refresh_time, - &area->t_lsp_refresh[level - 1]); - else if (level == IS_LEVEL_2) - thread_add_timer(master, lsp_l2_refresh, area, refresh_time, - &area->t_lsp_refresh[level - 1]); + thread_add_timer(master, lsp_refresh, + &area->lsp_refresh_arg[level - 1], refresh_time, + &area->t_lsp_refresh[level - 1]); if (isis->debugs & DEBUG_UPDATE_PACKETS) { zlog_debug("ISIS-Upd (%s): Building L%d LSP %s, len %" PRIu16 @@ -1323,12 +1319,9 @@ static int lsp_regenerate(struct isis_area *area, int level) lsp_seqno_update(lsp); refresh_time = lsp_refresh_time(lsp, rem_lifetime); - if (level == IS_LEVEL_1) - thread_add_timer(master, lsp_l1_refresh, area, refresh_time, - &area->t_lsp_refresh[level - 1]); - else if (level == IS_LEVEL_2) - thread_add_timer(master, lsp_l2_refresh, area, refresh_time, - &area->t_lsp_refresh[level - 1]); + thread_add_timer(master, lsp_refresh, + &area->lsp_refresh_arg[level - 1], refresh_time, + &area->t_lsp_refresh[level - 1]); area->lsp_regenerate_pending[level - 1] = 0; if (isis->debugs & DEBUG_UPDATE_PACKETS) { @@ -1350,42 +1343,28 @@ static int lsp_regenerate(struct isis_area *area, int level) /* * Something has changed or periodic refresh -> regenerate LSP */ -static int lsp_l1_refresh(struct thread *thread) +static int lsp_refresh(struct thread *thread) { - struct isis_area *area; - - area = THREAD_ARG(thread); - assert(area); - - area->t_lsp_refresh[0] = NULL; - area->lsp_regenerate_pending[0] = 0; - - if ((area->is_type & IS_LEVEL_1) == 0) - return ISIS_ERROR; + struct lsp_refresh_arg *arg = THREAD_ARG(thread); - sched_debug( - "ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", - area->area_tag); - return lsp_regenerate(area, IS_LEVEL_1); -} + assert(arg); -static int lsp_l2_refresh(struct thread *thread) -{ - struct isis_area *area; + struct isis_area *area = arg->area; - area = THREAD_ARG(thread); assert(area); - area->t_lsp_refresh[1] = NULL; - area->lsp_regenerate_pending[1] = 0; + int level = arg->level; - if ((area->is_type & IS_LEVEL_2) == 0) + area->t_lsp_refresh[level - 1] = NULL; + area->lsp_regenerate_pending[level - 1] = 0; + + if ((area->is_type & level) == 0) return ISIS_ERROR; sched_debug( - "ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", - area->area_tag); - return lsp_regenerate(area, IS_LEVEL_2); + "ISIS (%s): LSP L%d refresh timer expired. Refreshing LSP...", + area->area_tag, level); + return lsp_regenerate(area, level); } int _lsp_regenerate_schedule(struct isis_area *area, int level, @@ -1472,15 +1451,10 @@ int _lsp_regenerate_schedule(struct isis_area *area, int level, } area->lsp_regenerate_pending[lvl - 1] = 1; - if (lvl == IS_LEVEL_1) { - thread_add_timer_msec(master, lsp_l1_refresh, area, - timeout, - &area->t_lsp_refresh[lvl - 1]); - } else if (lvl == IS_LEVEL_2) { - thread_add_timer_msec(master, lsp_l2_refresh, area, - timeout, - &area->t_lsp_refresh[lvl - 1]); - } + thread_add_timer_msec(master, lsp_refresh, + &area->lsp_refresh_arg[lvl - 1], + timeout, + &area->t_lsp_refresh[lvl - 1]); } if (all_pseudo) { diff --git a/isisd/isisd.c b/isisd/isisd.c index 94e6a63855..54bdbf3eb3 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -160,6 +160,13 @@ struct isis_area *isis_area_create(const char *area_tag) if (fabricd) area->fabricd = fabricd_new(area); + + area->lsp_refresh_arg[0].area = area; + area->lsp_refresh_arg[0].level = IS_LEVEL_1; + area->lsp_refresh_arg[1].area = area; + area->lsp_refresh_arg[1].level = IS_LEVEL_2; + + QOBJ_REG(area, isis_area); return area; diff --git a/isisd/isisd.h b/isisd/isisd.h index 7572f55174..5c4cf3e0da 100644 --- a/isisd/isisd.h +++ b/isisd/isisd.h @@ -90,6 +90,11 @@ enum spf_tree_id { SPFTREE_COUNT }; +struct lsp_refresh_arg { + struct isis_area *area; + int level; +}; + struct isis_area { struct isis *isis; /* back pointer */ dict_t *lspdb[ISIS_LEVELS]; /* link-state dbs */ @@ -160,6 +165,8 @@ struct isis_area { parameters*/ struct thread *spf_timer[ISIS_LEVELS]; + struct lsp_refresh_arg lsp_refresh_arg[ISIS_LEVELS]; + QOBJ_FIELDS }; DECLARE_QOBJ_TYPE(isis_area) -- 2.39.5