ospf6_neighbor.c 27 KB

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