mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 06:50:17 +00:00
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 <chris@opensourcerouting.org>
This commit is contained in:
parent
dc0dacfc89
commit
eb2bcb2800
127
isisd/isisd.c
127
isisd/isisd.c
@ -1293,6 +1293,66 @@ DEFUN (show_isis_summary,
|
|||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct isis_lsp *lsp_for_arg(const char *argv, dict_t *lspdb)
|
||||||
|
{
|
||||||
|
char sysid[255] = {0};
|
||||||
|
uint8_t number[3];
|
||||||
|
const char *pos;
|
||||||
|
uint8_t lspid[ISIS_SYS_ID_LEN + 2] = {0};
|
||||||
|
struct isis_dynhn *dynhn;
|
||||||
|
struct isis_lsp *lsp = NULL;
|
||||||
|
|
||||||
|
if (!argv)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extract fragment and pseudo id from the string argv
|
||||||
|
* in the forms:
|
||||||
|
* (a) <systemid/hostname>.<pseudo-id>-<framenent> or
|
||||||
|
* (b) <systemid/hostname>.<pseudo-id> or
|
||||||
|
* (c) <systemid/hostname> or
|
||||||
|
* Where systemid is in the form:
|
||||||
|
* xxxx.xxxx.xxxx
|
||||||
|
*/
|
||||||
|
if (argv)
|
||||||
|
strncpy(sysid, argv, 254);
|
||||||
|
if (argv && strlen(argv) > 3) {
|
||||||
|
pos = argv + strlen(argv) - 3;
|
||||||
|
if (strncmp(pos, "-", 1) == 0) {
|
||||||
|
memcpy(number, ++pos, 2);
|
||||||
|
lspid[ISIS_SYS_ID_LEN + 1] =
|
||||||
|
(uint8_t)strtol((char *)number, NULL, 16);
|
||||||
|
pos -= 4;
|
||||||
|
if (strncmp(pos, ".", 1) != 0)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (strncmp(pos, ".", 1) == 0) {
|
||||||
|
memcpy(number, ++pos, 2);
|
||||||
|
lspid[ISIS_SYS_ID_LEN] =
|
||||||
|
(uint8_t)strtol((char *)number, NULL, 16);
|
||||||
|
sysid[pos - argv - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to find the lsp-id if the argv
|
||||||
|
* string is in
|
||||||
|
* the form
|
||||||
|
* hostname.<pseudo-id>-<fragment>
|
||||||
|
*/
|
||||||
|
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:
|
* This function supports following display options:
|
||||||
* [ show isis database [detail] ]
|
* [ show isis database [detail] ]
|
||||||
@ -1314,48 +1374,11 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level)
|
|||||||
struct listnode *node;
|
struct listnode *node;
|
||||||
struct isis_area *area;
|
struct isis_area *area;
|
||||||
struct isis_lsp *lsp;
|
struct isis_lsp *lsp;
|
||||||
struct isis_dynhn *dynhn;
|
|
||||||
const char *pos;
|
|
||||||
uint8_t lspid[ISIS_SYS_ID_LEN + 2];
|
|
||||||
char sysid[255];
|
|
||||||
uint8_t number[3];
|
|
||||||
int level, lsp_count;
|
int level, lsp_count;
|
||||||
|
|
||||||
if (isis->area_list->count == 0)
|
if (isis->area_list->count == 0)
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
|
|
||||||
memset(&lspid, 0, ISIS_SYS_ID_LEN);
|
|
||||||
memset(&sysid, 0, 255);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* extract fragment and pseudo id from the string argv
|
|
||||||
* in the forms:
|
|
||||||
* (a) <systemid/hostname>.<pseudo-id>-<framenent> or
|
|
||||||
* (b) <systemid/hostname>.<pseudo-id> or
|
|
||||||
* (c) <systemid/hostname> or
|
|
||||||
* Where systemid is in the form:
|
|
||||||
* xxxx.xxxx.xxxx
|
|
||||||
*/
|
|
||||||
if (argv)
|
|
||||||
strncpy(sysid, argv, 254);
|
|
||||||
if (argv && strlen(argv) > 3) {
|
|
||||||
pos = argv + strlen(argv) - 3;
|
|
||||||
if (strncmp(pos, "-", 1) == 0) {
|
|
||||||
memcpy(number, ++pos, 2);
|
|
||||||
lspid[ISIS_SYS_ID_LEN + 1] =
|
|
||||||
(uint8_t)strtol((char *)number, NULL, 16);
|
|
||||||
pos -= 4;
|
|
||||||
if (strncmp(pos, ".", 1) != 0)
|
|
||||||
return CMD_WARNING;
|
|
||||||
}
|
|
||||||
if (strncmp(pos, ".", 1) == 0) {
|
|
||||||
memcpy(number, ++pos, 2);
|
|
||||||
lspid[ISIS_SYS_ID_LEN] =
|
|
||||||
(uint8_t)strtol((char *)number, NULL, 16);
|
|
||||||
sysid[pos - argv - 1] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
|
for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
|
||||||
vty_out(vty, "Area %s:\n",
|
vty_out(vty, "Area %s:\n",
|
||||||
area->area_tag ? area->area_tag : "null");
|
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++) {
|
for (level = 0; level < ISIS_LEVELS; level++) {
|
||||||
if (area->lspdb[level]
|
if (area->lspdb[level]
|
||||||
&& dict_count(area->lspdb[level]) > 0) {
|
&& dict_count(area->lspdb[level]) > 0) {
|
||||||
lsp = NULL;
|
lsp = lsp_for_arg(argv, area->lspdb[level]);
|
||||||
if (argv != NULL) {
|
|
||||||
/*
|
|
||||||
* Try to find the lsp-id if the argv
|
|
||||||
* string is in
|
|
||||||
* the form
|
|
||||||
* hostname.<pseudo-id>-<fragment>
|
|
||||||
*/
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lsp != NULL || argv == NULL) {
|
if (lsp != NULL || argv == NULL) {
|
||||||
vty_out(vty,
|
vty_out(vty,
|
||||||
|
@ -178,6 +178,7 @@ struct isis_area *isis_area_create(const char *);
|
|||||||
struct isis_area *isis_area_lookup(const char *);
|
struct isis_area *isis_area_lookup(const char *);
|
||||||
int isis_area_get(struct vty *vty, const char *area_tag);
|
int isis_area_get(struct vty *vty, const char *area_tag);
|
||||||
void print_debug(struct vty *, int, int);
|
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_invalidate_routes(struct isis_area *area, int levels);
|
||||||
void isis_area_verify_routes(struct isis_area *area);
|
void isis_area_verify_routes(struct isis_area *area);
|
||||||
|
Loading…
Reference in New Issue
Block a user