]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_dynhn.c
2 * IS-IS Rout(e)ing protocol - isis_dynhn.c
3 * Dynamic hostname cache
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "isisd/isis_constants.h"
35 #include "isisd/isis_common.h"
36 #include "isisd/isis_flags.h"
37 #include "isisd/isis_circuit.h"
38 #include "isisd/isisd.h"
39 #include "isisd/isis_dynhn.h"
40 #include "isisd/isis_misc.h"
41 #include "isisd/isis_constants.h"
43 DEFINE_MTYPE_STATIC(ISISD
, ISIS_DYNHN
, "ISIS dyn hostname");
45 static int dyn_cache_cleanup(struct thread
*);
47 void dyn_cache_init(struct isis
*isis
)
49 isis
->dyn_cache
= list_new();
50 if (!CHECK_FLAG(im
->options
, F_ISIS_UNIT_TEST
))
51 thread_add_timer(master
, dyn_cache_cleanup
, isis
, 120,
55 void dyn_cache_finish(struct isis
*isis
)
57 struct listnode
*node
, *nnode
;
58 struct isis_dynhn
*dyn
;
60 thread_cancel(&isis
->t_dync_clean
);
62 for (ALL_LIST_ELEMENTS(isis
->dyn_cache
, node
, nnode
, dyn
)) {
63 list_delete_node(isis
->dyn_cache
, node
);
64 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
67 list_delete(&isis
->dyn_cache
);
70 static int dyn_cache_cleanup(struct thread
*thread
)
72 struct listnode
*node
, *nnode
;
73 struct isis_dynhn
*dyn
;
74 time_t now
= time(NULL
);
75 struct isis
*isis
= NULL
;
77 isis
= THREAD_ARG(thread
);
79 isis
->t_dync_clean
= NULL
;
81 for (ALL_LIST_ELEMENTS(isis
->dyn_cache
, node
, nnode
, dyn
)) {
82 if ((now
- dyn
->refresh
) < MAX_LSP_LIFETIME
)
84 list_delete_node(isis
->dyn_cache
, node
);
85 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
88 thread_add_timer(master
, dyn_cache_cleanup
, isis
, 120,
94 struct isis_dynhn
*dynhn_find_by_id(struct isis
*isis
, const uint8_t *id
)
96 struct listnode
*node
= NULL
;
97 struct isis_dynhn
*dyn
= NULL
;
99 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
))
100 if (memcmp(dyn
->id
, id
, ISIS_SYS_ID_LEN
) == 0)
106 struct isis_dynhn
*dynhn_find_by_name(struct isis
*isis
, const char *hostname
)
108 struct listnode
*node
= NULL
;
109 struct isis_dynhn
*dyn
= NULL
;
111 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
))
112 if (strncmp(dyn
->hostname
, hostname
, 255) == 0)
118 void isis_dynhn_insert(struct isis
*isis
, const uint8_t *id
,
119 const char *hostname
, int level
)
121 struct isis_dynhn
*dyn
;
123 dyn
= dynhn_find_by_id(isis
, id
);
125 dyn
= XCALLOC(MTYPE_ISIS_DYNHN
, sizeof(struct isis_dynhn
));
126 memcpy(dyn
->id
, id
, ISIS_SYS_ID_LEN
);
128 listnode_add(isis
->dyn_cache
, dyn
);
131 snprintf(dyn
->hostname
, sizeof(dyn
->hostname
), "%s", hostname
);
132 dyn
->refresh
= time(NULL
);
135 void isis_dynhn_remove(struct isis
*isis
, const uint8_t *id
)
137 struct isis_dynhn
*dyn
;
139 dyn
= dynhn_find_by_id(isis
, id
);
142 listnode_delete(isis
->dyn_cache
, dyn
);
143 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
147 * Level System ID Dynamic Hostname (notag)
148 * 2 0000.0000.0001 foo-gw
149 * 2 0000.0000.0002 bar-gw
150 * * 0000.0000.0004 this-gw
152 void dynhn_print_all(struct vty
*vty
, struct isis
*isis
)
154 struct listnode
*node
;
155 struct isis_dynhn
*dyn
;
157 vty_out(vty
, "vrf : %s\n", isis
->name
);
158 if (!isis
->sysid_set
)
160 vty_out(vty
, "Level System ID Dynamic Hostname\n");
161 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
)) {
162 vty_out(vty
, "%-7d", dyn
->level
);
163 vty_out(vty
, "%-15s%-15s\n", sysid_print(dyn
->id
),
167 vty_out(vty
, " * %s %s\n", sysid_print(isis
->sysid
),
172 struct isis_dynhn
*dynhn_snmp_next(struct isis
*isis
, const uint8_t *id
,
175 struct listnode
*node
= NULL
;
176 struct isis_dynhn
*dyn
= NULL
;
177 struct isis_dynhn
*found_dyn
= NULL
;
180 for (ALL_LIST_ELEMENTS_RO(isis
->dyn_cache
, node
, dyn
)) {
181 res
= memcmp(dyn
->id
, id
, ISIS_SYS_ID_LEN
);
186 if (res
== 0 && dyn
->level
<= level
)
191 * This is the best match, we can stop
199 if (found_dyn
== NULL
200 || memcmp(dyn
->id
, found_dyn
->id
, ISIS_SYS_ID_LEN
) < 0) {