blob: 41c36371467d51267ee3fd5c63a3368218a3b370 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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>
jardineb5d44e2003-12-23 08:09:43 +000025
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 ();
hassof390d2c2004-09-10 20:48:21 +000053
jardineb5d44e2003-12-23 08:09:43 +000054 return;
55}
56
hassof390d2c2004-09-10 20:48:21 +000057struct isis_dynhn *
58dynhn_find_by_id (u_char * id)
jardineb5d44e2003-12-23 08:09:43 +000059{
60 struct listnode *node = NULL;
61 struct isis_dynhn *dyn = NULL;
62
hassof390d2c2004-09-10 20:48:21 +000063 for (node = listhead (dyn_cache); node; nextnode (node))
64 {
65 dyn = getdata (node);
66 if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0)
67 return dyn;
68 }
69
jardineb5d44e2003-12-23 08:09:43 +000070 return NULL;
71}
72
73void
hassof390d2c2004-09-10 20:48:21 +000074isis_dynhn_insert (u_char * id, struct hostname *hostname, int level)
jardineb5d44e2003-12-23 08:09:43 +000075{
76 struct isis_dynhn *dyn;
77
78 dyn = dynhn_find_by_id (id);
hassof390d2c2004-09-10 20:48:21 +000079 if (dyn)
80 {
81 memcpy (&dyn->name, hostname, hostname->namelen + 1);
82 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
83 dyn->refresh = time (NULL);
84 return;
85 }
jardineb5d44e2003-12-23 08:09:43 +000086 dyn = XMALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn));
hassof390d2c2004-09-10 20:48:21 +000087 if (!dyn)
88 {
89 zlog_warn ("isis_dynhn_insert(): out of memory!");
90 return;
91 }
92 memset (dyn, 0, sizeof (struct isis_dynhn));
jardineb5d44e2003-12-23 08:09:43 +000093 /* we also copy the length */
hassof390d2c2004-09-10 20:48:21 +000094 memcpy (&dyn->name, hostname, hostname->namelen + 1);
jardineb5d44e2003-12-23 08:09:43 +000095 memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
96 dyn->refresh = time (NULL);
97 dyn->level = level;
hassof390d2c2004-09-10 20:48:21 +000098
jardineb5d44e2003-12-23 08:09:43 +000099 listnode_add (dyn_cache, dyn);
100
101 return;
102}
103
104/*
105 * Level System ID Dynamic Hostname (notag)
106 * 2 0000.0000.0001 foo-gw
107 * 2 0000.0000.0002 bar-gw
108 * * 0000.0000.0004 this-gw
109 */
hassof390d2c2004-09-10 20:48:21 +0000110void
111dynhn_print_all (struct vty *vty)
jardineb5d44e2003-12-23 08:09:43 +0000112{
113 struct listnode *node;
114 struct isis_dynhn *dyn;
115
116 vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000117 for (node = listhead (dyn_cache); node; nextnode (node))
118 {
119 dyn = getdata (node);
120 vty_out (vty, "%-7d", dyn->level);
121 vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name,
122 VTY_NEWLINE);
123 }
124
125 vty_out (vty, " * %s %s%s", sysid_print (isis->sysid), unix_hostname (),
jardineb5d44e2003-12-23 08:09:43 +0000126 VTY_NEWLINE);
127 return;
128}