isis_dynhn.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <time.h>
  23. #include <zebra.h>
  24. #include "vty.h"
  25. #include "linklist.h"
  26. #include "memory.h"
  27. #include "log.h"
  28. #include "stream.h"
  29. #include "command.h"
  30. #include "if.h"
  31. #include "isisd/dict.h"
  32. #include "isisd/isis_constants.h"
  33. #include "isisd/isis_common.h"
  34. #include "isisd/isis_flags.h"
  35. #include "isisd/isis_circuit.h"
  36. #include "isisd/isisd.h"
  37. #include "isisd/isis_dynhn.h"
  38. #include "isisd/isis_misc.h"
  39. #include "isisd/isis_constants.h"
  40. extern struct isis *isis;
  41. extern struct host host;
  42. struct list *dyn_cache = NULL;
  43. void
  44. dyn_cache_init (void)
  45. {
  46. dyn_cache = list_new ();
  47. return;
  48. }
  49. struct isis_dynhn *
  50. dynhn_find_by_id (u_char * id)
  51. {
  52. struct listnode *node = NULL;
  53. struct isis_dynhn *dyn = NULL;
  54. for (node = listhead (dyn_cache); node; nextnode (node))
  55. {
  56. dyn = getdata (node);
  57. if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0)
  58. return dyn;
  59. }
  60. return NULL;
  61. }
  62. void
  63. isis_dynhn_insert (u_char * id, struct hostname *hostname, int level)
  64. {
  65. struct isis_dynhn *dyn;
  66. dyn = dynhn_find_by_id (id);
  67. if (dyn)
  68. {
  69. memcpy (&dyn->name, hostname, hostname->namelen + 1);
  70. memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
  71. dyn->refresh = time (NULL);
  72. return;
  73. }
  74. dyn = XMALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn));
  75. if (!dyn)
  76. {
  77. zlog_warn ("isis_dynhn_insert(): out of memory!");
  78. return;
  79. }
  80. memset (dyn, 0, sizeof (struct isis_dynhn));
  81. /* we also copy the length */
  82. memcpy (&dyn->name, hostname, hostname->namelen + 1);
  83. memcpy (dyn->id, id, ISIS_SYS_ID_LEN);
  84. dyn->refresh = time (NULL);
  85. dyn->level = level;
  86. listnode_add (dyn_cache, dyn);
  87. return;
  88. }
  89. /*
  90. * Level System ID Dynamic Hostname (notag)
  91. * 2 0000.0000.0001 foo-gw
  92. * 2 0000.0000.0002 bar-gw
  93. * * 0000.0000.0004 this-gw
  94. */
  95. void
  96. dynhn_print_all (struct vty *vty)
  97. {
  98. struct listnode *node;
  99. struct isis_dynhn *dyn;
  100. vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE);
  101. for (node = listhead (dyn_cache); node; nextnode (node))
  102. {
  103. dyn = getdata (node);
  104. vty_out (vty, "%-7d", dyn->level);
  105. vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name,
  106. VTY_NEWLINE);
  107. }
  108. vty_out (vty, " * %s %s%s", sysid_print (isis->sysid), unix_hostname (),
  109. VTY_NEWLINE);
  110. return;
  111. }