]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_dynhn.c
Add IS-IS info into array.
[mirror_frr.git] / isisd / isis_dynhn.c
CommitLineData
eb5d44eb 1/*
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
7 *
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)
11 * any later version.
12 *
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
16 * more details.
17 *
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.
21 */
22
23#include <time.h>
24#include <zebra.h>
eb5d44eb 25
26#include "vty.h"
27#include "linklist.h"
28#include "memory.h"
29#include "log.h"
30#include "stream.h"
31#include "command.h"
32#include "if.h"
33
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"
43
44extern struct isis *isis;
45extern struct host host;
46
47struct list *dyn_cache = NULL;
48
49void
50dyn_cache_init (void)
51{
52 dyn_cache = list_new ();
53
54 return;
55}
56
57struct isis_dynhn *dynhn_find_by_id (u_char * id)
58{
59 struct listnode *node = NULL;
60 struct isis_dynhn *dyn = NULL;
61
62 for (node = listhead (dyn_cache); node; nextnode (node)) {
63 dyn = getdata (node);
64 if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0)
65 return dyn;
66 }
67
68 return NULL;
69}
70
71void
72isis_dynhn_insert (u_char *id, struct hostname *hostname, int level)
73{
74 struct isis_dynhn *dyn;
75
76 dyn = dynhn_find_by_id (id);
77 if (dyn) {
78 memcpy (&dyn->name, hostname, hostname->namelen + 1);
79 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
80 dyn->refresh = time (NULL);
81 return;
82 }
83 dyn = XMALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn));
84 if (!dyn) {
85 zlog_warn ("isis_dynhn_insert(): out of memory!");
86 return;
87 }
88 memset (dyn,0,sizeof(struct isis_dynhn));
89 /* we also copy the length */
90 memcpy (&dyn->name, hostname, hostname->namelen + 1);
91 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
92 dyn->refresh = time (NULL);
93 dyn->level = level;
94
95 listnode_add (dyn_cache, dyn);
96
97 return;
98}
99
100/*
101 * Level System ID Dynamic Hostname (notag)
102 * 2 0000.0000.0001 foo-gw
103 * 2 0000.0000.0002 bar-gw
104 * * 0000.0000.0004 this-gw
105 */
106void dynhn_print_all (struct vty *vty)
107{
108 struct listnode *node;
109 struct isis_dynhn *dyn;
110
111 vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE);
112 for (node = listhead (dyn_cache); node; nextnode (node)) {
113 dyn = getdata (node);
114 vty_out (vty, "%-7d", dyn->level);
115 vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name,
116 VTY_NEWLINE);
117 }
118
9e867fe6 119 vty_out (vty, " * %s %s%s", sysid_print (isis->sysid), unix_hostname(),
eb5d44eb 120 VTY_NEWLINE);
121 return;
122}
123