]>
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/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
*);
49 void dyn_cache_init(void)
51 if (dyn_cache
== NULL
)
52 dyn_cache
= list_new();
53 thread_add_timer(master
, dyn_cache_cleanup
, NULL
, 120,
58 static int dyn_cache_cleanup(struct thread
*thread
)
60 struct listnode
*node
, *nnode
;
61 struct isis_dynhn
*dyn
;
62 time_t now
= time(NULL
);
64 isis
->t_dync_clean
= NULL
;
66 for (ALL_LIST_ELEMENTS(dyn_cache
, node
, nnode
, dyn
)) {
67 if ((now
- dyn
->refresh
) < MAX_LSP_LIFETIME
)
70 list_delete_node(dyn_cache
, node
);
71 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
74 thread_add_timer(master
, dyn_cache_cleanup
, NULL
, 120,
79 struct isis_dynhn
*dynhn_find_by_id(const u_char
*id
)
81 struct listnode
*node
= NULL
;
82 struct isis_dynhn
*dyn
= NULL
;
84 for (ALL_LIST_ELEMENTS_RO(dyn_cache
, node
, dyn
))
85 if (memcmp(dyn
->id
, id
, ISIS_SYS_ID_LEN
) == 0)
91 struct isis_dynhn
*dynhn_find_by_name(const char *hostname
)
93 struct listnode
*node
= NULL
;
94 struct isis_dynhn
*dyn
= NULL
;
96 for (ALL_LIST_ELEMENTS_RO(dyn_cache
, node
, dyn
))
97 if (strncmp(dyn
->hostname
, hostname
, 255) == 0)
103 void isis_dynhn_insert(const u_char
*id
, const char *hostname
, int level
)
105 struct isis_dynhn
*dyn
;
107 dyn
= dynhn_find_by_id(id
);
109 dyn
= XCALLOC(MTYPE_ISIS_DYNHN
, sizeof(struct isis_dynhn
));
110 memcpy(dyn
->id
, id
, ISIS_SYS_ID_LEN
);
112 listnode_add(dyn_cache
, dyn
);
115 snprintf(dyn
->hostname
, sizeof(dyn
->hostname
), "%s", hostname
);
116 dyn
->refresh
= time(NULL
);
119 void isis_dynhn_remove(const u_char
*id
)
121 struct isis_dynhn
*dyn
;
123 dyn
= dynhn_find_by_id(id
);
126 listnode_delete(dyn_cache
, dyn
);
127 XFREE(MTYPE_ISIS_DYNHN
, dyn
);
131 * Level System ID Dynamic Hostname (notag)
132 * 2 0000.0000.0001 foo-gw
133 * 2 0000.0000.0002 bar-gw
134 * * 0000.0000.0004 this-gw
136 void dynhn_print_all(struct vty
*vty
)
138 struct listnode
*node
;
139 struct isis_dynhn
*dyn
;
141 vty_out(vty
, "Level System ID Dynamic Hostname\n");
142 for (ALL_LIST_ELEMENTS_RO(dyn_cache
, node
, dyn
)) {
143 vty_out(vty
, "%-7d", dyn
->level
);
144 vty_out(vty
, "%-15s%-15s\n", sysid_print(dyn
->id
),
148 vty_out(vty
, " * %s %s\n", sysid_print(isis
->sysid
),