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; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include "isisd/dict.h"
35 #include "isisd/isis_constants.h"
36 #include "isisd/isis_common.h"
37 #include "isisd/isis_flags.h"
38 #include "isisd/isis_circuit.h"
39 #include "isisd/isisd.h"
40 #include "isisd/isis_dynhn.h"
41 #include "isisd/isis_misc.h"
42 #include "isisd/isis_constants.h"
44 extern struct host host;
46 struct list *dyn_cache = NULL;
47 static int dyn_cache_cleanup (struct thread *);
52 if (dyn_cache == NULL)
53 dyn_cache = list_new ();
54 THREAD_TIMER_ON (master, isis->t_dync_clean, dyn_cache_cleanup, NULL, 120);
59 dyn_cache_cleanup (struct thread *thread)
61 struct listnode *node, *nnode;
62 struct isis_dynhn *dyn;
63 time_t now = time (NULL);
65 isis->t_dync_clean = NULL;
67 for (ALL_LIST_ELEMENTS (dyn_cache, node, nnode, dyn))
69 if ((now - dyn->refresh) < MAX_LSP_LIFETIME)
72 list_delete_node (dyn_cache, node);
73 XFREE (MTYPE_ISIS_DYNHN, dyn);
76 THREAD_TIMER_ON (master, isis->t_dync_clean, dyn_cache_cleanup, NULL, 120);
81 dynhn_find_by_id (const u_char * id)
83 struct listnode *node = NULL;
84 struct isis_dynhn *dyn = NULL;
86 for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn))
87 if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0)
94 dynhn_find_by_name (const char *hostname)
96 struct listnode *node = NULL;
97 struct isis_dynhn *dyn = NULL;
99 for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn))
100 if (strncmp ((char *)dyn->name.name, hostname, 255) == 0)
107 isis_dynhn_insert (const u_char * id, struct hostname *hostname, int level)
109 struct isis_dynhn *dyn;
111 dyn = dynhn_find_by_id (id);
114 memcpy (&dyn->name, hostname, hostname->namelen + 1);
115 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
116 dyn->refresh = time (NULL);
119 dyn = XCALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn));
122 zlog_warn ("isis_dynhn_insert(): out of memory!");
126 /* we also copy the length */
127 memcpy (&dyn->name, hostname, hostname->namelen + 1);
128 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
129 dyn->refresh = time (NULL);
132 listnode_add (dyn_cache, dyn);
138 isis_dynhn_remove (const u_char * id)
140 struct isis_dynhn *dyn;
142 dyn = dynhn_find_by_id (id);
145 listnode_delete (dyn_cache, dyn);
146 XFREE (MTYPE_ISIS_DYNHN, dyn);
151 * Level System ID Dynamic Hostname (notag)
152 * 2 0000.0000.0001 foo-gw
153 * 2 0000.0000.0002 bar-gw
154 * * 0000.0000.0004 this-gw
157 dynhn_print_all (struct vty *vty)
159 struct listnode *node;
160 struct isis_dynhn *dyn;
162 vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE);
163 for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn))
165 vty_out (vty, "%-7d", dyn->level);
166 vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name,
170 vty_out (vty, " * %s %s%s", sysid_print (isis->sysid), unix_hostname (),