2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2003-12-23 09:09:43 +01:00
|
|
|
/*
|
|
|
|
* IS-IS Rout(e)ing protocol - isis_dynhn.c
|
|
|
|
* Dynamic hostname cache
|
|
|
|
* Copyright (C) 2001,2002 Sampo Saaristo
|
|
|
|
* Tampere University of Technology
|
|
|
|
* Institute of Communications Engineering
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "vty.h"
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "if.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2003-12-23 09:09:43 +01:00
|
|
|
|
|
|
|
#include "isisd/isis_constants.h"
|
|
|
|
#include "isisd/isis_common.h"
|
|
|
|
#include "isisd/isis_flags.h"
|
|
|
|
#include "isisd/isis_circuit.h"
|
|
|
|
#include "isisd/isisd.h"
|
|
|
|
#include "isisd/isis_dynhn.h"
|
|
|
|
#include "isisd/isis_misc.h"
|
|
|
|
#include "isisd/isis_constants.h"
|
|
|
|
|
2021-03-22 18:27:58 +01:00
|
|
|
DEFINE_MTYPE_STATIC(ISISD, ISIS_DYNHN, "ISIS dyn hostname");
|
|
|
|
|
2022-03-01 22:18:12 +01:00
|
|
|
static void dyn_cache_cleanup(struct event *);
|
2003-12-23 09:09:43 +01:00
|
|
|
|
2020-07-13 14:37:59 +02:00
|
|
|
void dyn_cache_init(struct isis *isis)
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
2021-06-11 17:27:46 +02:00
|
|
|
isis->dyn_cache = list_new();
|
2020-08-24 19:46:36 +02:00
|
|
|
if (!CHECK_FLAG(im->options, F_ISIS_UNIT_TEST))
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, dyn_cache_cleanup, isis, 120,
|
|
|
|
&isis->t_dync_clean);
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
void dyn_cache_finish(struct isis *isis)
|
2020-08-24 19:46:36 +02:00
|
|
|
{
|
|
|
|
struct listnode *node, *nnode;
|
|
|
|
struct isis_dynhn *dyn;
|
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(isis->t_dync_clean);
|
2021-06-11 17:27:46 +02:00
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS(isis->dyn_cache, node, nnode, dyn)) {
|
|
|
|
list_delete_node(isis->dyn_cache, node);
|
2020-08-24 19:46:36 +02:00
|
|
|
XFREE(MTYPE_ISIS_DYNHN, dyn);
|
|
|
|
}
|
2021-06-11 17:27:46 +02:00
|
|
|
|
|
|
|
list_delete(&isis->dyn_cache);
|
2020-08-24 19:46:36 +02:00
|
|
|
}
|
|
|
|
|
2022-03-01 22:18:12 +01:00
|
|
|
static void dyn_cache_cleanup(struct event *thread)
|
2005-09-28 20:30:51 +02:00
|
|
|
{
|
|
|
|
struct listnode *node, *nnode;
|
|
|
|
struct isis_dynhn *dyn;
|
|
|
|
time_t now = time(NULL);
|
2020-07-13 14:37:59 +02:00
|
|
|
struct isis *isis = NULL;
|
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
isis = EVENT_ARG(thread);
|
2005-09-28 20:30:51 +02:00
|
|
|
|
|
|
|
isis->t_dync_clean = NULL;
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
for (ALL_LIST_ELEMENTS(isis->dyn_cache, node, nnode, dyn)) {
|
2012-03-24 16:35:20 +01:00
|
|
|
if ((now - dyn->refresh) < MAX_LSP_LIFETIME)
|
|
|
|
continue;
|
2021-06-11 17:27:46 +02:00
|
|
|
list_delete_node(isis->dyn_cache, node);
|
2005-09-28 20:30:51 +02:00
|
|
|
XFREE(MTYPE_ISIS_DYNHN, dyn);
|
|
|
|
}
|
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, dyn_cache_cleanup, isis, 120,
|
2020-07-13 14:37:59 +02:00
|
|
|
&isis->t_dync_clean);
|
2005-09-28 20:30:51 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
struct isis_dynhn *dynhn_find_by_id(struct isis *isis, const uint8_t *id)
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
|
|
|
struct listnode *node = NULL;
|
|
|
|
struct isis_dynhn *dyn = NULL;
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(isis->dyn_cache, node, dyn))
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
if (memcmp(dyn->id, id, ISIS_SYS_ID_LEN) == 0)
|
|
|
|
return dyn;
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
struct isis_dynhn *dynhn_find_by_name(struct isis *isis, const char *hostname)
|
2012-03-24 16:35:20 +01:00
|
|
|
{
|
|
|
|
struct listnode *node = NULL;
|
|
|
|
struct isis_dynhn *dyn = NULL;
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(isis->dyn_cache, node, dyn))
|
2017-07-05 18:37:36 +02:00
|
|
|
if (strncmp(dyn->hostname, hostname, 255) == 0)
|
2012-03-24 16:35:20 +01:00
|
|
|
return dyn;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
void isis_dynhn_insert(struct isis *isis, const uint8_t *id,
|
|
|
|
const char *hostname, int level)
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
|
|
|
struct isis_dynhn *dyn;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
dyn = dynhn_find_by_id(isis, id);
|
2004-09-10 22:48:21 +02:00
|
|
|
if (!dyn) {
|
2017-07-05 18:37:36 +02:00
|
|
|
dyn = XCALLOC(MTYPE_ISIS_DYNHN, sizeof(struct isis_dynhn));
|
|
|
|
memcpy(dyn->id, id, ISIS_SYS_ID_LEN);
|
|
|
|
dyn->level = level;
|
2021-06-11 17:27:46 +02:00
|
|
|
listnode_add(isis->dyn_cache, dyn);
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-07-05 18:37:36 +02:00
|
|
|
snprintf(dyn->hostname, sizeof(dyn->hostname), "%s", hostname);
|
2003-12-23 09:09:43 +01:00
|
|
|
dyn->refresh = time(NULL);
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
void isis_dynhn_remove(struct isis *isis, const uint8_t *id)
|
2012-03-24 16:35:20 +01:00
|
|
|
{
|
|
|
|
struct isis_dynhn *dyn;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
dyn = dynhn_find_by_id(isis, id);
|
2012-03-24 16:35:20 +01:00
|
|
|
if (!dyn)
|
|
|
|
return;
|
2021-06-11 17:27:46 +02:00
|
|
|
listnode_delete(isis->dyn_cache, dyn);
|
2012-03-24 16:35:20 +01:00
|
|
|
XFREE(MTYPE_ISIS_DYNHN, dyn);
|
|
|
|
}
|
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
/*
|
|
|
|
* Level System ID Dynamic Hostname (notag)
|
|
|
|
* 2 0000.0000.0001 foo-gw
|
|
|
|
* 2 0000.0000.0002 bar-gw
|
|
|
|
* * 0000.0000.0004 this-gw
|
|
|
|
*/
|
2020-07-13 14:37:59 +02:00
|
|
|
void dynhn_print_all(struct vty *vty, struct isis *isis)
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
|
|
|
struct listnode *node;
|
|
|
|
struct isis_dynhn *dyn;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-07-13 14:37:59 +02:00
|
|
|
vty_out(vty, "vrf : %s\n", isis->name);
|
|
|
|
if (!isis->sysid_set)
|
|
|
|
return;
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, "Level System ID Dynamic Hostname\n");
|
2021-06-11 17:27:46 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(isis->dyn_cache, node, dyn)) {
|
2004-09-10 22:48:21 +02:00
|
|
|
vty_out(vty, "%-7d", dyn->level);
|
2023-01-26 17:47:04 +01:00
|
|
|
vty_out(vty, "%pSY %-15s\n", dyn->id, dyn->hostname);
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-01-26 17:47:04 +01:00
|
|
|
vty_out(vty, " * %pSY %s\n", isis->sysid, cmd_hostname_get());
|
2003-12-23 09:09:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-09-15 22:46:15 +02:00
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
struct isis_dynhn *dynhn_snmp_next(struct isis *isis, const uint8_t *id,
|
|
|
|
int level)
|
2020-09-15 22:46:15 +02:00
|
|
|
{
|
|
|
|
struct listnode *node = NULL;
|
|
|
|
struct isis_dynhn *dyn = NULL;
|
|
|
|
struct isis_dynhn *found_dyn = NULL;
|
|
|
|
int res;
|
|
|
|
|
2021-06-11 17:27:46 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(isis->dyn_cache, node, dyn)) {
|
2020-09-15 22:46:15 +02:00
|
|
|
res = memcmp(dyn->id, id, ISIS_SYS_ID_LEN);
|
|
|
|
|
|
|
|
if (res < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (res == 0 && dyn->level <= level)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (res == 0) {
|
|
|
|
/*
|
|
|
|
* This is the best match, we can stop
|
|
|
|
* searching
|
|
|
|
*/
|
|
|
|
|
|
|
|
found_dyn = dyn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_dyn == NULL
|
|
|
|
|| memcmp(dyn->id, found_dyn->id, ISIS_SYS_ID_LEN) < 0) {
|
|
|
|
found_dyn = dyn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found_dyn;
|
|
|
|
}
|