ospf6_neighbor.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "log.h"
  23. #include "memory.h"
  24. #include "thread.h"
  25. #include "linklist.h"
  26. #include "vty.h"
  27. #include "command.h"
  28. #include "ospf6_proto.h"
  29. #include "ospf6_lsa.h"
  30. #include "ospf6_lsdb.h"
  31. #include "ospf6_message.h"
  32. #include "ospf6_top.h"
  33. #include "ospf6_area.h"
  34. #include "ospf6_interface.h"
  35. #include "ospf6_neighbor.h"
  36. #include "ospf6_intra.h"
  37. #include "ospf6_flood.h"
  38. #include "ospf6d.h"
  39. unsigned char conf_debug_ospf6_neighbor = 0;
  40. const char *ospf6_neighbor_state_str[] =
  41. { "None", "Down", "Attempt", "Init", "Twoway", "ExStart", "ExChange",
  42. "Loading", "Full", NULL };
  43. static const char *ospf6_neighbor_event_str[] =
  44. {
  45. "NoEvent",
  46. "HelloReceived",
  47. "2-WayReceived",
  48. "NegotiationDone",
  49. "ExchangeDone",
  50. "LoadingDone",
  51. "AdjOK?",
  52. "SeqNumberMismatch",
  53. "BadLSReq",
  54. "1-WayReceived",
  55. "InactivityTimer",
  56. };
  57. static const char *
  58. ospf6_neighbor_event_string (int event)
  59. {
  60. #define OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING "UnknownEvent"
  61. if (event < OSPF6_NEIGHBOR_EVENT_MAX_EVENT)
  62. return ospf6_neighbor_event_str[event];
  63. return OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING;
  64. }
  65. int
  66. ospf6_neighbor_cmp (void *va, void *vb)
  67. {
  68. struct ospf6_neighbor *ona = (struct ospf6_neighbor *) va;
  69. struct ospf6_neighbor *onb = (struct ospf6_neighbor *) vb;
  70. return (ntohl (ona->router_id) < ntohl (onb->router_id) ? -1 : 1);
  71. }
  72. struct ospf6_neighbor *
  73. ospf6_neighbor_lookup (u_int32_t router_id,
  74. struct ospf6_interface *oi)
  75. {
  76. struct listnode *n;
  77. struct ospf6_neighbor *on;
  78. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, n, on))
  79. if (on->router_id == router_id)
  80. return on;
  81. return (struct ospf6_neighbor *) NULL;
  82. }
  83. /* create ospf6_neighbor */
  84. struct ospf6_neighbor *
  85. ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *oi)
  86. {
  87. struct ospf6_neighbor *on;
  88. char buf[16];
  89. on = (struct ospf6_neighbor *)
  90. XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor));
  91. if (on == NULL)
  92. {
  93. zlog_warn ("neighbor: malloc failed");
  94. return NULL;
  95. }
  96. memset (on, 0, sizeof (struct ospf6_neighbor));
  97. inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
  98. snprintf (on->name, sizeof (on->name), "%s%%%s",
  99. buf, oi->interface->name);
  100. on->ospf6_if = oi;
  101. on->state = OSPF6_NEIGHBOR_DOWN;
  102. on->state_change = 0;
  103. quagga_gettime (QUAGGA_CLK_MONOTONIC, &on->last_changed);
  104. on->router_id = router_id;
  105. on->summary_list = ospf6_lsdb_create (on);
  106. on->request_list = ospf6_lsdb_create (on);
  107. on->retrans_list = ospf6_lsdb_create (on);
  108. on->dbdesc_list = ospf6_lsdb_create (on);
  109. on->lsupdate_list = ospf6_lsdb_create (on);
  110. on->lsack_list = ospf6_lsdb_create (on);
  111. listnode_add_sort (oi->neighbor_list, on);
  112. return on;
  113. }
  114. void
  115. ospf6_neighbor_delete (struct ospf6_neighbor *on)
  116. {
  117. struct ospf6_lsa *lsa;
  118. ospf6_lsdb_remove_all (on->summary_list);
  119. ospf6_lsdb_remove_all (on->request_list);
  120. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  121. lsa = ospf6_lsdb_next (lsa))
  122. {
  123. ospf6_decrement_retrans_count (lsa);
  124. ospf6_lsdb_remove (lsa, on->retrans_list);
  125. }
  126. ospf6_lsdb_remove_all (on->dbdesc_list);
  127. ospf6_lsdb_remove_all (on->lsupdate_list);
  128. ospf6_lsdb_remove_all (on->lsack_list);
  129. ospf6_lsdb_delete (on->summary_list);
  130. ospf6_lsdb_delete (on->request_list);
  131. ospf6_lsdb_delete (on->retrans_list);
  132. ospf6_lsdb_delete (on->dbdesc_list);
  133. ospf6_lsdb_delete (on->lsupdate_list);
  134. ospf6_lsdb_delete (on->lsack_list);
  135. THREAD_OFF (on->inactivity_timer);
  136. THREAD_OFF (on->thread_send_dbdesc);
  137. THREAD_OFF (on->thread_send_lsreq);
  138. THREAD_OFF (on->thread_send_lsupdate);
  139. THREAD_OFF (on->thread_send_lsack);
  140. XFREE (MTYPE_OSPF6_NEIGHBOR, on);
  141. }
  142. static void
  143. ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on, int event)
  144. {
  145. u_char prev_state;
  146. prev_state = on->state;
  147. on->state = next_state;
  148. if (prev_state == next_state)
  149. return;
  150. on->state_change++;
  151. quagga_gettime (QUAGGA_CLK_MONOTONIC, &on->last_changed);
  152. /* log */
  153. if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
  154. {
  155. zlog_debug ("Neighbor state change %s: [%s]->[%s] (%s)", on->name,
  156. ospf6_neighbor_state_str[prev_state],
  157. ospf6_neighbor_state_str[next_state],
  158. ospf6_neighbor_event_string(event));
  159. }
  160. /* Optionally notify about adjacency changes */
  161. if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
  162. OSPF6_LOG_ADJACENCY_CHANGES) &&
  163. (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
  164. OSPF6_LOG_ADJACENCY_DETAIL) ||
  165. (next_state == OSPF6_NEIGHBOR_FULL) || (next_state < prev_state)))
  166. zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
  167. ospf6_neighbor_state_str[prev_state],
  168. ospf6_neighbor_state_str[next_state],
  169. ospf6_neighbor_event_string(event));
  170. if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
  171. {
  172. OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
  173. if (on->ospf6_if->state == OSPF6_INTERFACE_DR)
  174. {
  175. OSPF6_NETWORK_LSA_SCHEDULE (on->ospf6_if);
  176. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (on->ospf6_if);
  177. }
  178. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (on->ospf6_if->area);
  179. }
  180. if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE ||
  181. prev_state == OSPF6_NEIGHBOR_LOADING) &&
  182. (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
  183. next_state != OSPF6_NEIGHBOR_LOADING))
  184. ospf6_maxage_remove (on->ospf6_if->area->ospf6);
  185. #ifdef HAVE_SNMP
  186. /* Terminal state or regression */
  187. if ((next_state == OSPF6_NEIGHBOR_FULL) ||
  188. (next_state == OSPF6_NEIGHBOR_TWOWAY) ||
  189. (next_state < prev_state))
  190. ospf6TrapNbrStateChange (on);
  191. #endif
  192. }
  193. /* RFC2328 section 10.4 */
  194. static int
  195. need_adjacency (struct ospf6_neighbor *on)
  196. {
  197. if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT ||
  198. on->ospf6_if->state == OSPF6_INTERFACE_DR ||
  199. on->ospf6_if->state == OSPF6_INTERFACE_BDR)
  200. return 1;
  201. if (on->ospf6_if->drouter == on->router_id ||
  202. on->ospf6_if->bdrouter == on->router_id)
  203. return 1;
  204. return 0;
  205. }
  206. int
  207. hello_received (struct thread *thread)
  208. {
  209. struct ospf6_neighbor *on;
  210. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  211. assert (on);
  212. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  213. zlog_debug ("Neighbor Event %s: *HelloReceived*", on->name);
  214. /* reset Inactivity Timer */
  215. THREAD_OFF (on->inactivity_timer);
  216. on->inactivity_timer = thread_add_timer (master, inactivity_timer, on,
  217. on->ospf6_if->dead_interval);
  218. if (on->state <= OSPF6_NEIGHBOR_DOWN)
  219. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
  220. OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
  221. return 0;
  222. }
  223. int
  224. twoway_received (struct thread *thread)
  225. {
  226. struct ospf6_neighbor *on;
  227. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  228. assert (on);
  229. if (on->state > OSPF6_NEIGHBOR_INIT)
  230. return 0;
  231. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  232. zlog_debug ("Neighbor Event %s: *2Way-Received*", on->name);
  233. thread_add_event (master, neighbor_change, on->ospf6_if, 0);
  234. if (! need_adjacency (on))
  235. {
  236. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
  237. OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
  238. return 0;
  239. }
  240. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
  241. OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
  242. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  243. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  244. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
  245. THREAD_OFF (on->thread_send_dbdesc);
  246. on->thread_send_dbdesc =
  247. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  248. return 0;
  249. }
  250. int
  251. negotiation_done (struct thread *thread)
  252. {
  253. struct ospf6_neighbor *on;
  254. struct ospf6_lsa *lsa;
  255. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  256. assert (on);
  257. if (on->state != OSPF6_NEIGHBOR_EXSTART)
  258. return 0;
  259. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  260. zlog_debug ("Neighbor Event %s: *NegotiationDone*", on->name);
  261. /* clear ls-list */
  262. ospf6_lsdb_remove_all (on->summary_list);
  263. ospf6_lsdb_remove_all (on->request_list);
  264. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  265. lsa = ospf6_lsdb_next (lsa))
  266. {
  267. ospf6_decrement_retrans_count (lsa);
  268. ospf6_lsdb_remove (lsa, on->retrans_list);
  269. }
  270. /* Interface scoped LSAs */
  271. for (lsa = ospf6_lsdb_head (on->ospf6_if->lsdb); lsa;
  272. lsa = ospf6_lsdb_next (lsa))
  273. {
  274. if (OSPF6_LSA_IS_MAXAGE (lsa))
  275. {
  276. ospf6_increment_retrans_count (lsa);
  277. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
  278. }
  279. else
  280. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
  281. }
  282. /* Area scoped LSAs */
  283. for (lsa = ospf6_lsdb_head (on->ospf6_if->area->lsdb); lsa;
  284. lsa = ospf6_lsdb_next (lsa))
  285. {
  286. if (OSPF6_LSA_IS_MAXAGE (lsa))
  287. {
  288. ospf6_increment_retrans_count (lsa);
  289. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
  290. }
  291. else
  292. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
  293. }
  294. /* AS scoped LSAs */
  295. for (lsa = ospf6_lsdb_head (on->ospf6_if->area->ospf6->lsdb); lsa;
  296. lsa = ospf6_lsdb_next (lsa))
  297. {
  298. if (OSPF6_LSA_IS_MAXAGE (lsa))
  299. {
  300. ospf6_increment_retrans_count (lsa);
  301. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
  302. }
  303. else
  304. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
  305. }
  306. UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
  307. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on,
  308. OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
  309. return 0;
  310. }
  311. int
  312. exchange_done (struct thread *thread)
  313. {
  314. struct ospf6_neighbor *on;
  315. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  316. assert (on);
  317. if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
  318. return 0;
  319. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  320. zlog_debug ("Neighbor Event %s: *ExchangeDone*", on->name);
  321. THREAD_OFF (on->thread_send_dbdesc);
  322. ospf6_lsdb_remove_all (on->dbdesc_list);
  323. /* XXX
  324. thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
  325. on->ospf6_if->dead_interval);
  326. */
  327. if (on->request_list->count == 0)
  328. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
  329. OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
  330. else
  331. {
  332. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on,
  333. OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
  334. if (on->thread_send_lsreq == NULL)
  335. on->thread_send_lsreq =
  336. thread_add_event (master, ospf6_lsreq_send, on, 0);
  337. }
  338. return 0;
  339. }
  340. /* Check loading state. */
  341. void
  342. ospf6_check_nbr_loading (struct ospf6_neighbor *on)
  343. {
  344. /* RFC2328 Section 10.9: When the neighbor responds to these requests
  345. with the proper Link State Update packet(s), the Link state request
  346. list is truncated and a new Link State Request packet is sent.
  347. */
  348. if ((on->state == OSPF6_NEIGHBOR_LOADING) ||
  349. (on->state == OSPF6_NEIGHBOR_EXCHANGE))
  350. {
  351. if (on->request_list->count == 0)
  352. thread_add_event (master, loading_done, on, 0);
  353. else if (on->last_ls_req == NULL)
  354. {
  355. if (on->thread_send_lsreq != NULL)
  356. THREAD_OFF (on->thread_send_lsreq);
  357. on->thread_send_lsreq =
  358. thread_add_event (master, ospf6_lsreq_send, on, 0);
  359. }
  360. }
  361. }
  362. int
  363. loading_done (struct thread *thread)
  364. {
  365. struct ospf6_neighbor *on;
  366. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  367. assert (on);
  368. if (on->state != OSPF6_NEIGHBOR_LOADING)
  369. return 0;
  370. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  371. zlog_debug ("Neighbor Event %s: *LoadingDone*", on->name);
  372. assert (on->request_list->count == 0);
  373. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
  374. OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
  375. return 0;
  376. }
  377. int
  378. adj_ok (struct thread *thread)
  379. {
  380. struct ospf6_neighbor *on;
  381. struct ospf6_lsa *lsa;
  382. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  383. assert (on);
  384. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  385. zlog_debug ("Neighbor Event %s: *AdjOK?*", on->name);
  386. if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
  387. {
  388. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
  389. OSPF6_NEIGHBOR_EVENT_ADJ_OK);
  390. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  391. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  392. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
  393. THREAD_OFF (on->thread_send_dbdesc);
  394. on->thread_send_dbdesc =
  395. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  396. }
  397. else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
  398. ! need_adjacency (on))
  399. {
  400. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
  401. OSPF6_NEIGHBOR_EVENT_ADJ_OK);
  402. ospf6_lsdb_remove_all (on->summary_list);
  403. ospf6_lsdb_remove_all (on->request_list);
  404. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  405. lsa = ospf6_lsdb_next (lsa))
  406. {
  407. ospf6_decrement_retrans_count (lsa);
  408. ospf6_lsdb_remove (lsa, on->retrans_list);
  409. }
  410. }
  411. return 0;
  412. }
  413. int
  414. seqnumber_mismatch (struct thread *thread)
  415. {
  416. struct ospf6_neighbor *on;
  417. struct ospf6_lsa *lsa;
  418. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  419. assert (on);
  420. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  421. return 0;
  422. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  423. zlog_debug ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
  424. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
  425. OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
  426. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  427. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  428. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
  429. ospf6_lsdb_remove_all (on->summary_list);
  430. ospf6_lsdb_remove_all (on->request_list);
  431. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  432. lsa = ospf6_lsdb_next (lsa))
  433. {
  434. ospf6_decrement_retrans_count (lsa);
  435. ospf6_lsdb_remove (lsa, on->retrans_list);
  436. }
  437. THREAD_OFF (on->thread_send_dbdesc);
  438. on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
  439. on->thread_send_dbdesc =
  440. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  441. return 0;
  442. }
  443. int
  444. bad_lsreq (struct thread *thread)
  445. {
  446. struct ospf6_neighbor *on;
  447. struct ospf6_lsa *lsa;
  448. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  449. assert (on);
  450. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  451. return 0;
  452. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  453. zlog_debug ("Neighbor Event %s: *BadLSReq*", on->name);
  454. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
  455. OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
  456. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  457. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  458. SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
  459. ospf6_lsdb_remove_all (on->summary_list);
  460. ospf6_lsdb_remove_all (on->request_list);
  461. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  462. lsa = ospf6_lsdb_next (lsa))
  463. {
  464. ospf6_decrement_retrans_count (lsa);
  465. ospf6_lsdb_remove (lsa, on->retrans_list);
  466. }
  467. THREAD_OFF (on->thread_send_dbdesc);
  468. on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
  469. on->thread_send_dbdesc =
  470. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  471. return 0;
  472. }
  473. int
  474. oneway_received (struct thread *thread)
  475. {
  476. struct ospf6_neighbor *on;
  477. struct ospf6_lsa *lsa;
  478. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  479. assert (on);
  480. if (on->state < OSPF6_NEIGHBOR_TWOWAY)
  481. return 0;
  482. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  483. zlog_debug ("Neighbor Event %s: *1Way-Received*", on->name);
  484. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
  485. OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
  486. thread_add_event (master, neighbor_change, on->ospf6_if, 0);
  487. ospf6_lsdb_remove_all (on->summary_list);
  488. ospf6_lsdb_remove_all (on->request_list);
  489. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  490. lsa = ospf6_lsdb_next (lsa))
  491. {
  492. ospf6_decrement_retrans_count (lsa);
  493. ospf6_lsdb_remove (lsa, on->retrans_list);
  494. }
  495. THREAD_OFF (on->thread_send_dbdesc);
  496. THREAD_OFF (on->thread_send_lsreq);
  497. THREAD_OFF (on->thread_send_lsupdate);
  498. THREAD_OFF (on->thread_send_lsack);
  499. return 0;
  500. }
  501. int
  502. inactivity_timer (struct thread *thread)
  503. {
  504. struct ospf6_neighbor *on;
  505. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  506. assert (on);
  507. if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  508. zlog_debug ("Neighbor Event %s: *InactivityTimer*", on->name);
  509. on->inactivity_timer = NULL;
  510. on->drouter = on->prev_drouter = 0;
  511. on->bdrouter = on->prev_bdrouter = 0;
  512. ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on,
  513. OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
  514. thread_add_event (master, neighbor_change, on->ospf6_if, 0);
  515. listnode_delete (on->ospf6_if->neighbor_list, on);
  516. ospf6_neighbor_delete (on);
  517. return 0;
  518. }
  519. /* vty functions */
  520. /* show neighbor structure */
  521. static void
  522. ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on)
  523. {
  524. char router_id[16];
  525. char duration[16];
  526. struct timeval now, res;
  527. char nstate[16];
  528. char deadtime[16];
  529. long h, m, s;
  530. /* Router-ID (Name) */
  531. inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
  532. #ifdef HAVE_GETNAMEINFO
  533. {
  534. }
  535. #endif /*HAVE_GETNAMEINFO*/
  536. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  537. /* Dead time */
  538. h = m = s = 0;
  539. if (on->inactivity_timer)
  540. {
  541. s = on->inactivity_timer->u.sands.tv_sec - recent_relative_time().tv_sec;
  542. h = s / 3600;
  543. s -= h * 3600;
  544. m = s / 60;
  545. s -= m * 60;
  546. }
  547. snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
  548. /* Neighbor State */
  549. if (if_is_pointopoint (on->ospf6_if->interface))
  550. snprintf (nstate, sizeof (nstate), "PointToPoint");
  551. else
  552. {
  553. if (on->router_id == on->drouter)
  554. snprintf (nstate, sizeof (nstate), "DR");
  555. else if (on->router_id == on->bdrouter)
  556. snprintf (nstate, sizeof (nstate), "BDR");
  557. else
  558. snprintf (nstate, sizeof (nstate), "DROther");
  559. }
  560. /* Duration */
  561. timersub (&now, &on->last_changed, &res);
  562. timerstring (&res, duration, sizeof (duration));
  563. /*
  564. vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
  565. "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
  566. "I/F", "State", VNL);
  567. */
  568. vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
  569. router_id, on->priority, deadtime,
  570. ospf6_neighbor_state_str[on->state], nstate, duration,
  571. on->ospf6_if->interface->name,
  572. ospf6_interface_state_str[on->ospf6_if->state], VNL);
  573. }
  574. static void
  575. ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
  576. {
  577. char router_id[16];
  578. char drouter[16], bdrouter[16];
  579. char duration[16];
  580. struct timeval now, res;
  581. /*
  582. vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
  583. "RouterID", "State", "Duration", "DR", "BDR", "I/F",
  584. "State", VNL);
  585. */
  586. inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
  587. inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
  588. inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
  589. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  590. timersub (&now, &on->last_changed, &res);
  591. timerstring (&res, duration, sizeof (duration));
  592. vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
  593. router_id, ospf6_neighbor_state_str[on->state],
  594. duration, drouter, bdrouter, on->ospf6_if->interface->name,
  595. ospf6_interface_state_str[on->ospf6_if->state],
  596. VNL);
  597. }
  598. static void
  599. ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
  600. {
  601. char drouter[16], bdrouter[16];
  602. char linklocal_addr[64], duration[32];
  603. struct timeval now, res;
  604. struct ospf6_lsa *lsa;
  605. inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
  606. sizeof (linklocal_addr));
  607. inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
  608. inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
  609. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  610. timersub (&now, &on->last_changed, &res);
  611. timerstring (&res, duration, sizeof (duration));
  612. vty_out (vty, " Neighbor %s%s", on->name,
  613. VNL);
  614. vty_out (vty, " Area %s via interface %s (ifindex %d)%s",
  615. on->ospf6_if->area->name,
  616. on->ospf6_if->interface->name,
  617. on->ospf6_if->interface->ifindex,
  618. VNL);
  619. vty_out (vty, " His IfIndex: %d Link-local address: %s%s",
  620. on->ifindex, linklocal_addr,
  621. VNL);
  622. vty_out (vty, " State %s for a duration of %s%s",
  623. ospf6_neighbor_state_str[on->state], duration,
  624. VNL);
  625. vty_out (vty, " His choice of DR/BDR %s/%s, Priority %d%s",
  626. drouter, bdrouter, on->priority,
  627. VNL);
  628. vty_out (vty, " DbDesc status: %s%s%s SeqNum: %#lx%s",
  629. (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
  630. (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
  631. (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
  632. "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum),
  633. VNL);
  634. vty_out (vty, " Summary-List: %d LSAs%s", on->summary_list->count,
  635. VNL);
  636. for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
  637. lsa = ospf6_lsdb_next (lsa))
  638. vty_out (vty, " %s%s", lsa->name, VNL);
  639. vty_out (vty, " Request-List: %d LSAs%s", on->request_list->count,
  640. VNL);
  641. for (lsa = ospf6_lsdb_head (on->request_list); lsa;
  642. lsa = ospf6_lsdb_next (lsa))
  643. vty_out (vty, " %s%s", lsa->name, VNL);
  644. vty_out (vty, " Retrans-List: %d LSAs%s", on->retrans_list->count,
  645. VNL);
  646. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  647. lsa = ospf6_lsdb_next (lsa))
  648. vty_out (vty, " %s%s", lsa->name, VNL);
  649. timerclear (&res);
  650. if (on->thread_send_dbdesc)
  651. timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
  652. timerstring (&res, duration, sizeof (duration));
  653. vty_out (vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]%s",
  654. on->dbdesc_list->count, duration,
  655. (on->thread_send_dbdesc ? "on" : "off"),
  656. VNL);
  657. for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
  658. lsa = ospf6_lsdb_next (lsa))
  659. vty_out (vty, " %s%s", lsa->name, VNL);
  660. timerclear (&res);
  661. if (on->thread_send_lsreq)
  662. timersub (&on->thread_send_lsreq->u.sands, &now, &res);
  663. timerstring (&res, duration, sizeof (duration));
  664. vty_out (vty, " %d Pending LSAs for LSReq in Time %s [thread %s]%s",
  665. on->request_list->count, duration,
  666. (on->thread_send_lsreq ? "on" : "off"),
  667. VNL);
  668. for (lsa = ospf6_lsdb_head (on->request_list); lsa;
  669. lsa = ospf6_lsdb_next (lsa))
  670. vty_out (vty, " %s%s", lsa->name, VNL);
  671. timerclear (&res);
  672. if (on->thread_send_lsupdate)
  673. timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
  674. timerstring (&res, duration, sizeof (duration));
  675. vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
  676. on->lsupdate_list->count, duration,
  677. (on->thread_send_lsupdate ? "on" : "off"),
  678. VNL);
  679. for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
  680. lsa = ospf6_lsdb_next (lsa))
  681. vty_out (vty, " %s%s", lsa->name, VNL);
  682. timerclear (&res);
  683. if (on->thread_send_lsack)
  684. timersub (&on->thread_send_lsack->u.sands, &now, &res);
  685. timerstring (&res, duration, sizeof (duration));
  686. vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
  687. on->lsack_list->count, duration,
  688. (on->thread_send_lsack ? "on" : "off"),
  689. VNL);
  690. for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
  691. lsa = ospf6_lsdb_next (lsa))
  692. vty_out (vty, " %s%s", lsa->name, VNL);
  693. }
  694. DEFUN (show_ipv6_ospf6_neighbor,
  695. show_ipv6_ospf6_neighbor_cmd,
  696. "show ipv6 ospf6 neighbor",
  697. SHOW_STR
  698. IP6_STR
  699. OSPF6_STR
  700. "Neighbor list\n"
  701. )
  702. {
  703. struct ospf6_neighbor *on;
  704. struct ospf6_interface *oi;
  705. struct ospf6_area *oa;
  706. struct listnode *i, *j, *k;
  707. void (*showfunc) (struct vty *, struct ospf6_neighbor *);
  708. OSPF6_CMD_CHECK_RUNNING ();
  709. showfunc = ospf6_neighbor_show;
  710. if (argc)
  711. {
  712. if (! strncmp (argv[0], "de", 2))
  713. showfunc = ospf6_neighbor_show_detail;
  714. else if (! strncmp (argv[0], "dr", 2))
  715. showfunc = ospf6_neighbor_show_drchoice;
  716. }
  717. if (showfunc == ospf6_neighbor_show)
  718. vty_out (vty, "%-15s %3s %11s %6s/%-12s %11s %s[%s]%s",
  719. "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
  720. "I/F", "State", VNL);
  721. else if (showfunc == ospf6_neighbor_show_drchoice)
  722. vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
  723. "RouterID", "State", "Duration", "DR", "BDR", "I/F",
  724. "State", VNL);
  725. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
  726. for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
  727. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
  728. (*showfunc) (vty, on);
  729. return CMD_SUCCESS;
  730. }
  731. ALIAS (show_ipv6_ospf6_neighbor,
  732. show_ipv6_ospf6_neighbor_detail_cmd,
  733. "show ipv6 ospf6 neighbor (detail|drchoice)",
  734. SHOW_STR
  735. IP6_STR
  736. OSPF6_STR
  737. "Neighbor list\n"
  738. "Display details\n"
  739. "Display DR choices\n"
  740. )
  741. DEFUN (show_ipv6_ospf6_neighbor_one,
  742. show_ipv6_ospf6_neighbor_one_cmd,
  743. "show ipv6 ospf6 neighbor A.B.C.D",
  744. SHOW_STR
  745. IP6_STR
  746. OSPF6_STR
  747. "Neighbor list\n"
  748. "Specify Router-ID as IPv4 address notation\n"
  749. )
  750. {
  751. struct ospf6_neighbor *on;
  752. struct ospf6_interface *oi;
  753. struct ospf6_area *oa;
  754. struct listnode *i, *j, *k;
  755. void (*showfunc) (struct vty *, struct ospf6_neighbor *);
  756. u_int32_t router_id;
  757. OSPF6_CMD_CHECK_RUNNING ();
  758. showfunc = ospf6_neighbor_show_detail;
  759. if ((inet_pton (AF_INET, argv[0], &router_id)) != 1)
  760. {
  761. vty_out (vty, "Router-ID is not parsable: %s%s", argv[0],
  762. VNL);
  763. return CMD_SUCCESS;
  764. }
  765. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
  766. for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
  767. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
  768. (*showfunc) (vty, on);
  769. return CMD_SUCCESS;
  770. }
  771. void
  772. ospf6_neighbor_init (void)
  773. {
  774. install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
  775. install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
  776. install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_cmd);
  777. install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
  778. }
  779. DEFUN (debug_ospf6_neighbor,
  780. debug_ospf6_neighbor_cmd,
  781. "debug ospf6 neighbor",
  782. DEBUG_STR
  783. OSPF6_STR
  784. "Debug OSPFv3 Neighbor\n"
  785. )
  786. {
  787. unsigned char level = 0;
  788. if (argc)
  789. {
  790. if (! strncmp (argv[0], "s", 1))
  791. level = OSPF6_DEBUG_NEIGHBOR_STATE;
  792. if (! strncmp (argv[0], "e", 1))
  793. level = OSPF6_DEBUG_NEIGHBOR_EVENT;
  794. }
  795. else
  796. level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
  797. OSPF6_DEBUG_NEIGHBOR_ON (level);
  798. return CMD_SUCCESS;
  799. }
  800. ALIAS (debug_ospf6_neighbor,
  801. debug_ospf6_neighbor_detail_cmd,
  802. "debug ospf6 neighbor (state|event)",
  803. DEBUG_STR
  804. OSPF6_STR
  805. "Debug OSPFv3 Neighbor\n"
  806. "Debug OSPFv3 Neighbor State Change\n"
  807. "Debug OSPFv3 Neighbor Event\n"
  808. )
  809. DEFUN (no_debug_ospf6_neighbor,
  810. no_debug_ospf6_neighbor_cmd,
  811. "no debug ospf6 neighbor",
  812. NO_STR
  813. DEBUG_STR
  814. OSPF6_STR
  815. "Debug OSPFv3 Neighbor\n"
  816. )
  817. {
  818. unsigned char level = 0;
  819. if (argc)
  820. {
  821. if (! strncmp (argv[0], "s", 1))
  822. level = OSPF6_DEBUG_NEIGHBOR_STATE;
  823. if (! strncmp (argv[0], "e", 1))
  824. level = OSPF6_DEBUG_NEIGHBOR_EVENT;
  825. }
  826. else
  827. level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
  828. OSPF6_DEBUG_NEIGHBOR_OFF (level);
  829. return CMD_SUCCESS;
  830. }
  831. ALIAS (no_debug_ospf6_neighbor,
  832. no_debug_ospf6_neighbor_detail_cmd,
  833. "no debug ospf6 neighbor (state|event)",
  834. NO_STR
  835. DEBUG_STR
  836. OSPF6_STR
  837. "Debug OSPFv3 Neighbor\n"
  838. "Debug OSPFv3 Neighbor State Change\n"
  839. "Debug OSPFv3 Neighbor Event\n"
  840. )
  841. int
  842. config_write_ospf6_debug_neighbor (struct vty *vty)
  843. {
  844. if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
  845. IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  846. vty_out (vty, "debug ospf6 neighbor%s", VNL);
  847. else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
  848. vty_out (vty, "debug ospf6 neighbor state%s", VNL);
  849. else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
  850. vty_out (vty, "debug ospf6 neighbor event%s", VNL);
  851. return 0;
  852. }
  853. void
  854. install_element_ospf6_debug_neighbor (void)
  855. {
  856. install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
  857. install_element (ENABLE_NODE, &debug_ospf6_neighbor_detail_cmd);
  858. install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
  859. install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_detail_cmd);
  860. install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
  861. install_element (CONFIG_NODE, &debug_ospf6_neighbor_detail_cmd);
  862. install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
  863. install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_detail_cmd);
  864. }