jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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 | |
| 44 | extern struct isis *isis; |
| 45 | extern struct host host; |
| 46 | |
| 47 | struct list *dyn_cache = NULL; |
| 48 | |
| 49 | void |
| 50 | dyn_cache_init (void) |
| 51 | { |
| 52 | dyn_cache = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 53 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 54 | return; |
| 55 | } |
| 56 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 57 | struct isis_dynhn * |
| 58 | dynhn_find_by_id (u_char * id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 59 | { |
| 60 | struct listnode *node = NULL; |
| 61 | struct isis_dynhn *dyn = NULL; |
| 62 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 63 | for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn)) |
| 64 | if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0) |
| 65 | return dyn; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 66 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 71 | isis_dynhn_insert (u_char * id, struct hostname *hostname, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 72 | { |
| 73 | struct isis_dynhn *dyn; |
| 74 | |
| 75 | dyn = dynhn_find_by_id (id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 76 | if (dyn) |
| 77 | { |
| 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 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 83 | dyn = XMALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 84 | if (!dyn) |
| 85 | { |
| 86 | zlog_warn ("isis_dynhn_insert(): out of memory!"); |
| 87 | return; |
| 88 | } |
| 89 | memset (dyn, 0, sizeof (struct isis_dynhn)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 90 | /* we also copy the length */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 91 | memcpy (&dyn->name, hostname, hostname->namelen + 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 92 | memcpy (dyn->id, id, ISIS_SYS_ID_LEN); |
| 93 | dyn->refresh = time (NULL); |
| 94 | dyn->level = level; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 95 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 96 | listnode_add (dyn_cache, dyn); |
| 97 | |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Level System ID Dynamic Hostname (notag) |
| 103 | * 2 0000.0000.0001 foo-gw |
| 104 | * 2 0000.0000.0002 bar-gw |
| 105 | * * 0000.0000.0004 this-gw |
| 106 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 107 | void |
| 108 | dynhn_print_all (struct vty *vty) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 109 | { |
| 110 | struct listnode *node; |
| 111 | struct isis_dynhn *dyn; |
| 112 | |
| 113 | vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 114 | for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 115 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 116 | vty_out (vty, "%-7d", dyn->level); |
| 117 | vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name, |
| 118 | VTY_NEWLINE); |
| 119 | } |
| 120 | |
| 121 | vty_out (vty, " * %s %s%s", sysid_print (isis->sysid), unix_hostname (), |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 122 | VTY_NEWLINE); |
| 123 | return; |
| 124 | } |