]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_dynhn.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IS-IS Rout(e)ing protocol - isis_dynhn.c
4 * Dynamic hostname cache
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
21 #include "isisd/isis_constants.h"
22 #include "isisd/isis_common.h"
23 #include "isisd/isis_flags.h"
24 #include "isisd/isis_circuit.h"
25 #include "isisd/isisd.h"
26 #include "isisd/isis_dynhn.h"
27 #include "isisd/isis_misc.h"
28 #include "isisd/isis_constants.h"
30 DEFINE_MTYPE_STATIC(ISISD
, ISIS_DYNHN
, "ISIS dyn hostname");
32 static void dyn_cache_cleanup(struct thread
*);
34 void dyn_cache_init(struct isis
*isis
)
36 isis
->dyn_cache
= list_new();
37 if (!CHECK_FLAG(im
->options
, F_ISIS_UNIT_TEST
))
38 thread_add_timer(master
, dyn_cache_cleanup
, isis
, 120,
42 void dyn_cache_finish(struct isis
*isis
)
44 struct listnode
*node
, *nnode
;
45 struct isis_dynhn
*dyn
;
47 THREAD_OFF(isis
->t_dync_clean
);
49 for (ALL_LIST_ELEMENTS(isis
->dyn_cache
, node
, nnode
, dyn
)) {
50 list_delete_node(isis
->dyn_cache
, node
);
51 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
54 list_delete(&isis
->dyn_cache
);
57 static void dyn_cache_cleanup(struct thread
*thread
)
59 struct listnode
*node
, *nnode
;
60 struct isis_dynhn
*dyn
;
61 time_t now
= time(NULL
);
62 struct isis
*isis
= NULL
;
64 isis
= THREAD_ARG(thread
);
66 isis
->t_dync_clean
= NULL
;
68 for (ALL_LIST_ELEMENTS(isis
->dyn_cache
, node
, nnode
, dyn
)) {
69 if ((now
- dyn
->refresh
) < MAX_LSP_LIFETIME
)
71 list_delete_node(isis
->dyn_cache
, node
);
72 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
75 thread_add_timer(master
, dyn_cache_cleanup
, isis
, 120,
79 struct isis_dynhn
*dynhn_find_by_id(struct isis
*isis
, const uint8_t *id
)
81 struct listnode
*node
= NULL
;
82 struct isis_dynhn
*dyn
= NULL
;
84 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
))
85 if (memcmp(dyn
->id
, id
, ISIS_SYS_ID_LEN
) == 0)
91 struct isis_dynhn
*dynhn_find_by_name(struct isis
*isis
, const char *hostname
)
93 struct listnode
*node
= NULL
;
94 struct isis_dynhn
*dyn
= NULL
;
96 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
))
97 if (strncmp(dyn
->hostname
, hostname
, 255) == 0)
103 void isis_dynhn_insert(struct isis
*isis
, const uint8_t *id
,
104 const char *hostname
, int level
)
106 struct isis_dynhn
*dyn
;
108 dyn
= dynhn_find_by_id(isis
, id
);
110 dyn
= XCALLOC(MTYPE_ISIS_DYNHN
, sizeof(struct isis_dynhn
));
111 memcpy(dyn
->id
, id
, ISIS_SYS_ID_LEN
);
113 listnode_add(isis
->dyn_cache
, dyn
);
116 snprintf(dyn
->hostname
, sizeof(dyn
->hostname
), "%s", hostname
);
117 dyn
->refresh
= time(NULL
);
120 void isis_dynhn_remove(struct isis
*isis
, const uint8_t *id
)
122 struct isis_dynhn
*dyn
;
124 dyn
= dynhn_find_by_id(isis
, id
);
127 listnode_delete(isis
->dyn_cache
, dyn
);
128 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
132 * Level System ID Dynamic Hostname (notag)
133 * 2 0000.0000.0001 foo-gw
134 * 2 0000.0000.0002 bar-gw
135 * * 0000.0000.0004 this-gw
137 void dynhn_print_all(struct vty
*vty
, struct isis
*isis
)
139 struct listnode
*node
;
140 struct isis_dynhn
*dyn
;
142 vty_out(vty
, "vrf : %s\n", isis
->name
);
143 if (!isis
->sysid_set
)
145 vty_out(vty
, "Level System ID Dynamic Hostname\n");
146 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
)) {
147 vty_out(vty
, "%-7d", dyn
->level
);
148 vty_out(vty
, "%-15s%-15s\n", sysid_print(dyn
->id
),
152 vty_out(vty
, " * %s %s\n", sysid_print(isis
->sysid
),
157 struct isis_dynhn
*dynhn_snmp_next(struct isis
*isis
, const uint8_t *id
,
160 struct listnode
*node
= NULL
;
161 struct isis_dynhn
*dyn
= NULL
;
162 struct isis_dynhn
*found_dyn
= NULL
;
165 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
)) {
166 res
= memcmp(dyn
->id
, id
, ISIS_SYS_ID_LEN
);
171 if (res
== 0 && dyn
->level
<= level
)
176 * This is the best match, we can stop
184 if (found_dyn
== NULL
185 || memcmp(dyn
->id
, found_dyn
->id
, ISIS_SYS_ID_LEN
) < 0) {