isis_events.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * IS-IS Rout(e)ing protocol - isis_events.h
  3. *
  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. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "log.h"
  23. #include "memory.h"
  24. #include "if.h"
  25. #include "linklist.h"
  26. #include "command.h"
  27. #include "thread.h"
  28. #include "hash.h"
  29. #include "prefix.h"
  30. #include "stream.h"
  31. #include "table.h"
  32. #include "isisd/dict.h"
  33. #include "isisd/include-netbsd/iso.h"
  34. #include "isisd/isis_constants.h"
  35. #include "isisd/isis_common.h"
  36. #include "isisd/isis_flags.h"
  37. #include "isisd/isis_circuit.h"
  38. #include "isisd/isis_tlv.h"
  39. #include "isisd/isis_lsp.h"
  40. #include "isisd/isis_pdu.h"
  41. #include "isisd/isis_network.h"
  42. #include "isisd/isis_misc.h"
  43. #include "isisd/isis_constants.h"
  44. #include "isisd/isis_adjacency.h"
  45. #include "isisd/isis_dr.h"
  46. #include "isisd/isisd.h"
  47. #include "isisd/isis_csm.h"
  48. #include "isisd/isis_events.h"
  49. #include "isisd/isis_spf.h"
  50. /* debug isis-spf spf-events
  51. 4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
  52. 4w4d: ISIS-Spf (tlt): L2, 0000.0000.0042.01-00 TLV contents changed, code 0x2
  53. 4w4d: ISIS-Spf (tlt): L2, new LSP 0 DEAD.BEEF.0043.00-00
  54. 4w5d: ISIS-Spf (tlt): L1 SPF needed, periodic SPF, from 0x6091C844
  55. 4w5d: ISIS-Spf (tlt): L2 SPF needed, periodic SPF, from 0x6091C844
  56. */
  57. void
  58. isis_event_circuit_state_change (struct isis_circuit *circuit,
  59. struct isis_area *area, int up)
  60. {
  61. area->circuit_state_changes++;
  62. if (isis->debugs & DEBUG_EVENTS)
  63. zlog_debug ("ISIS-Evt (%s) circuit %s", area->area_tag,
  64. up ? "up" : "down");
  65. /*
  66. * Regenerate LSPs this affects
  67. */
  68. lsp_regenerate_schedule (area, IS_LEVEL_1 | IS_LEVEL_2, 0);
  69. return;
  70. }
  71. static void
  72. circuit_commence_level (struct isis_circuit *circuit, int level)
  73. {
  74. if (level == 1)
  75. {
  76. if (! circuit->is_passive)
  77. THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
  78. isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
  79. if (circuit->circ_type == CIRCUIT_T_BROADCAST)
  80. {
  81. THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
  82. circuit, 2 * circuit->hello_interval[0]);
  83. THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
  84. send_lan_l1_hello, circuit,
  85. isis_jitter (circuit->hello_interval[0],
  86. IIH_JITTER));
  87. circuit->u.bc.lan_neighs[0] = list_new ();
  88. }
  89. }
  90. else
  91. {
  92. if (! circuit->is_passive)
  93. THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
  94. isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
  95. if (circuit->circ_type == CIRCUIT_T_BROADCAST)
  96. {
  97. THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
  98. circuit, 2 * circuit->hello_interval[1]);
  99. THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
  100. send_lan_l2_hello, circuit,
  101. isis_jitter (circuit->hello_interval[1],
  102. IIH_JITTER));
  103. circuit->u.bc.lan_neighs[1] = list_new ();
  104. }
  105. }
  106. return;
  107. }
  108. static void
  109. circuit_resign_level (struct isis_circuit *circuit, int level)
  110. {
  111. int idx = level - 1;
  112. THREAD_TIMER_OFF (circuit->t_send_csnp[idx]);
  113. THREAD_TIMER_OFF (circuit->t_send_psnp[idx]);
  114. if (circuit->circ_type == CIRCUIT_T_BROADCAST)
  115. {
  116. THREAD_TIMER_OFF (circuit->u.bc.t_send_lan_hello[idx]);
  117. THREAD_TIMER_OFF (circuit->u.bc.t_run_dr[idx]);
  118. THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[idx]);
  119. circuit->lsp_regenerate_pending[idx] = 0;
  120. circuit->u.bc.run_dr_elect[idx] = 0;
  121. if (circuit->u.bc.lan_neighs[idx] != NULL) {
  122. list_delete (circuit->u.bc.lan_neighs[idx]);
  123. circuit->u.bc.lan_neighs[idx] = NULL;
  124. }
  125. }
  126. return;
  127. }
  128. void
  129. isis_circuit_is_type_set (struct isis_circuit *circuit, int newtype)
  130. {
  131. if (circuit->state != C_STATE_UP)
  132. {
  133. circuit->is_type = newtype;
  134. return;
  135. }
  136. if (isis->debugs & DEBUG_EVENTS)
  137. zlog_debug ("ISIS-Evt (%s) circuit type change %s -> %s",
  138. circuit->area->area_tag,
  139. circuit_t2string (circuit->is_type),
  140. circuit_t2string (newtype));
  141. if (circuit->is_type == newtype)
  142. return; /* No change */
  143. if (!(newtype & circuit->area->is_type))
  144. {
  145. zlog_err ("ISIS-Evt (%s) circuit type change - invalid level %s because"
  146. " area is %s", circuit->area->area_tag,
  147. circuit_t2string (newtype),
  148. circuit_t2string (circuit->area->is_type));
  149. return;
  150. }
  151. if (! circuit->is_passive)
  152. {
  153. switch (circuit->is_type)
  154. {
  155. case IS_LEVEL_1:
  156. if (newtype == IS_LEVEL_2)
  157. circuit_resign_level (circuit, 1);
  158. circuit_commence_level (circuit, 2);
  159. break;
  160. case IS_LEVEL_1_AND_2:
  161. if (newtype == IS_LEVEL_1)
  162. circuit_resign_level (circuit, 2);
  163. else
  164. circuit_resign_level (circuit, 1);
  165. break;
  166. case IS_LEVEL_2:
  167. if (newtype == IS_LEVEL_1)
  168. circuit_resign_level (circuit, 2);
  169. circuit_commence_level (circuit, 1);
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. circuit->is_type = newtype;
  176. lsp_regenerate_schedule (circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
  177. return;
  178. }
  179. /* 04/18/2002 by Gwak. */
  180. /**************************************************************************
  181. *
  182. * EVENTS for LSP generation
  183. *
  184. * 1) an Adajacency or Circuit Up/Down event
  185. * 2) a chnage in Circuit metric
  186. * 3) a change in Reachable Address metric
  187. * 4) a change in manualAreaAddresses
  188. * 5) a change in systemID
  189. * 6) a change in DIS status
  190. * 7) a chnage in the waiting status
  191. *
  192. * ***********************************************************************
  193. *
  194. * current support event
  195. *
  196. * 1) Adjacency Up/Down event
  197. * 6) a change in DIS status
  198. *
  199. * ***********************************************************************/
  200. void
  201. isis_event_adjacency_state_change (struct isis_adjacency *adj, int newstate)
  202. {
  203. /* adjacency state change event.
  204. * - the only proto-type was supported */
  205. /* invalid arguments */
  206. if (!adj || !adj->circuit || !adj->circuit->area)
  207. return;
  208. if (isis->debugs & DEBUG_EVENTS)
  209. zlog_debug ("ISIS-Evt (%s) Adjacency State change",
  210. adj->circuit->area->area_tag);
  211. /* LSP generation again */
  212. lsp_regenerate_schedule (adj->circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
  213. return;
  214. }
  215. /* events supporting code */
  216. int
  217. isis_event_dis_status_change (struct thread *thread)
  218. {
  219. struct isis_circuit *circuit;
  220. circuit = THREAD_ARG (thread);
  221. /* invalid arguments */
  222. if (!circuit || !circuit->area)
  223. return 0;
  224. if (isis->debugs & DEBUG_EVENTS)
  225. zlog_debug ("ISIS-Evt (%s) DIS status change", circuit->area->area_tag);
  226. /* LSP generation again */
  227. lsp_regenerate_schedule (circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
  228. return 0;
  229. }
  230. void
  231. isis_event_auth_failure (char *area_tag, const char *error_string, u_char *sysid)
  232. {
  233. if (isis->debugs & DEBUG_EVENTS)
  234. zlog_debug ("ISIS-Evt (%s) Authentication failure %s from %s",
  235. area_tag, error_string, sysid_print (sysid));
  236. return;
  237. }