From eb2bcb2800bb37a5984542e6135d5727875c0e84 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 23 Nov 2018 01:38:24 +0100 Subject: [PATCH] isisd: Move code to find LSP out of show database Finding an LSP by its id is useful not only for the `show isis database` command. So move it out into its own function to make it reusable. Signed-off-by: Christian Franke --- isisd/isisd.c | 115 ++++++++++++++++++++++++-------------------------- isisd/isisd.h | 1 + 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/isisd/isisd.c b/isisd/isisd.c index 0138f4345d..9d8f832eb3 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -1293,39 +1293,17 @@ DEFUN (show_isis_summary, return CMD_SUCCESS; } -/* - * This function supports following display options: - * [ show isis database [detail] ] - * [ show isis database [detail] ] - * [ show isis database [detail] ] - * [ show isis database . [detail] ] - * [ show isis database . [detail] ] - * [ show isis database .- [detail] ] - * [ show isis database .- [detail] ] - * [ show isis database detail ] - * [ show isis database detail ] - * [ show isis database detail . ] - * [ show isis database detail . ] - * [ show isis database detail .- ] - * [ show isis database detail .- ] - */ -static int show_isis_database(struct vty *vty, const char *argv, int ui_level) +struct isis_lsp *lsp_for_arg(const char *argv, dict_t *lspdb) { - struct listnode *node; - struct isis_area *area; - struct isis_lsp *lsp; - struct isis_dynhn *dynhn; - const char *pos; - uint8_t lspid[ISIS_SYS_ID_LEN + 2]; - char sysid[255]; + char sysid[255] = {0}; uint8_t number[3]; - int level, lsp_count; - - if (isis->area_list->count == 0) - return CMD_SUCCESS; + const char *pos; + uint8_t lspid[ISIS_SYS_ID_LEN + 2] = {0}; + struct isis_dynhn *dynhn; + struct isis_lsp *lsp = NULL; - memset(&lspid, 0, ISIS_SYS_ID_LEN); - memset(&sysid, 0, 255); + if (!argv) + return NULL; /* * extract fragment and pseudo id from the string argv @@ -1346,7 +1324,7 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) (uint8_t)strtol((char *)number, NULL, 16); pos -= 4; if (strncmp(pos, ".", 1) != 0) - return CMD_WARNING; + return NULL; } if (strncmp(pos, ".", 1) == 0) { memcpy(number, ++pos, 2); @@ -1356,6 +1334,51 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) } } + /* + * Try to find the lsp-id if the argv + * string is in + * the form + * hostname.- + */ + if (sysid2buff(lspid, sysid)) { + lsp = lsp_search(lspid, lspdb); + } else if ((dynhn = dynhn_find_by_name(sysid))) { + memcpy(lspid, dynhn->id, ISIS_SYS_ID_LEN); + lsp = lsp_search(lspid, lspdb); + } else if (strncmp(cmd_hostname_get(), sysid, 15) == 0) { + memcpy(lspid, isis->sysid, ISIS_SYS_ID_LEN); + lsp = lsp_search(lspid, lspdb); + } + + return lsp; +} + +/* + * This function supports following display options: + * [ show isis database [detail] ] + * [ show isis database [detail] ] + * [ show isis database [detail] ] + * [ show isis database . [detail] ] + * [ show isis database . [detail] ] + * [ show isis database .- [detail] ] + * [ show isis database .- [detail] ] + * [ show isis database detail ] + * [ show isis database detail ] + * [ show isis database detail . ] + * [ show isis database detail . ] + * [ show isis database detail .- ] + * [ show isis database detail .- ] + */ +static int show_isis_database(struct vty *vty, const char *argv, int ui_level) +{ + struct listnode *node; + struct isis_area *area; + struct isis_lsp *lsp; + int level, lsp_count; + + if (isis->area_list->count == 0) + return CMD_SUCCESS; + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { vty_out(vty, "Area %s:\n", area->area_tag ? area->area_tag : "null"); @@ -1363,35 +1386,7 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) for (level = 0; level < ISIS_LEVELS; level++) { if (area->lspdb[level] && dict_count(area->lspdb[level]) > 0) { - lsp = NULL; - if (argv != NULL) { - /* - * Try to find the lsp-id if the argv - * string is in - * the form - * hostname.- - */ - if (sysid2buff(lspid, sysid)) { - lsp = lsp_search( - lspid, - area->lspdb[level]); - } else if ((dynhn = dynhn_find_by_name( - sysid))) { - memcpy(lspid, dynhn->id, - ISIS_SYS_ID_LEN); - lsp = lsp_search( - lspid, - area->lspdb[level]); - } else if (strncmp(cmd_hostname_get(), - sysid, 15) - == 0) { - memcpy(lspid, isis->sysid, - ISIS_SYS_ID_LEN); - lsp = lsp_search( - lspid, - area->lspdb[level]); - } - } + lsp = lsp_for_arg(argv, area->lspdb[level]); if (lsp != NULL || argv == NULL) { vty_out(vty, diff --git a/isisd/isisd.h b/isisd/isisd.h index 7899d3ecd8..d857ae4438 100644 --- a/isisd/isisd.h +++ b/isisd/isisd.h @@ -178,6 +178,7 @@ struct isis_area *isis_area_create(const char *); struct isis_area *isis_area_lookup(const char *); int isis_area_get(struct vty *vty, const char *area_tag); void print_debug(struct vty *, int, int); +struct isis_lsp *lsp_for_arg(const char *argv, dict_t *lspdb); void isis_area_invalidate_routes(struct isis_area *area, int levels); void isis_area_verify_routes(struct isis_area *area); -- 2.39.5