ospf6_interface.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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 "memory.h"
  23. #include "if.h"
  24. #include "log.h"
  25. #include "command.h"
  26. #include "thread.h"
  27. #include "prefix.h"
  28. #include "plist.h"
  29. #include "ospf6d.h"
  30. #include "ospf6_lsa.h"
  31. #include "ospf6_lsdb.h"
  32. #include "ospf6_network.h"
  33. #include "ospf6_message.h"
  34. #include "ospf6_route.h"
  35. #include "ospf6_top.h"
  36. #include "ospf6_area.h"
  37. #include "ospf6_interface.h"
  38. #include "ospf6_neighbor.h"
  39. #include "ospf6_intra.h"
  40. #include "ospf6_spf.h"
  41. unsigned char conf_debug_ospf6_interface = 0;
  42. char *ospf6_interface_state_str[] =
  43. {
  44. "None",
  45. "Down",
  46. "Loopback",
  47. "Waiting",
  48. "PointToPoint",
  49. "DROther",
  50. "BDR",
  51. "DR",
  52. NULL
  53. };
  54. struct ospf6_interface *
  55. ospf6_interface_lookup_by_ifindex (int ifindex)
  56. {
  57. struct ospf6_interface *oi;
  58. struct interface *ifp;
  59. ifp = if_lookup_by_index (ifindex);
  60. if (ifp == NULL)
  61. return (struct ospf6_interface *) NULL;
  62. oi = (struct ospf6_interface *) ifp->info;
  63. return oi;
  64. }
  65. struct ospf6_interface *
  66. ospf6_interface_lookup_by_name (char *ifname)
  67. {
  68. struct ospf6_interface *oi;
  69. struct interface *ifp;
  70. ifp = if_lookup_by_name (ifname);
  71. if (ifp == NULL)
  72. return (struct ospf6_interface *) NULL;
  73. oi = (struct ospf6_interface *) ifp->info;
  74. return oi;
  75. }
  76. /* schedule routing table recalculation */
  77. void
  78. ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
  79. {
  80. struct ospf6_interface *oi;
  81. oi = (struct ospf6_interface *) lsa->scope;
  82. switch (ntohs (lsa->header->type))
  83. {
  84. case OSPF6_LSTYPE_LINK:
  85. if (oi->state == OSPF6_INTERFACE_DR)
  86. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  87. ospf6_spf_schedule (oi->area);
  88. break;
  89. default:
  90. if (IS_OSPF6_DEBUG_LSA (RECV))
  91. zlog_info ("Unknown LSA in Interface %s's lsdb",
  92. oi->interface->name);
  93. break;
  94. }
  95. }
  96. /* Create new ospf6 interface structure */
  97. struct ospf6_interface *
  98. ospf6_interface_create (struct interface *ifp)
  99. {
  100. struct ospf6_interface *oi;
  101. int iobuflen;
  102. oi = (struct ospf6_interface *)
  103. XMALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
  104. if (oi)
  105. memset (oi, 0, sizeof (struct ospf6_interface));
  106. else
  107. {
  108. zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
  109. return (struct ospf6_interface *) NULL;
  110. }
  111. oi->area = (struct ospf6_area *) NULL;
  112. oi->neighbor_list = list_new ();
  113. oi->neighbor_list->cmp = ospf6_neighbor_cmp;
  114. oi->linklocal_addr = (struct in6_addr *) NULL;
  115. oi->instance_id = 0;
  116. oi->transdelay = 1;
  117. oi->priority = 1;
  118. oi->hello_interval = 10;
  119. oi->dead_interval = 40;
  120. oi->rxmt_interval = 5;
  121. oi->cost = 1;
  122. oi->state = OSPF6_INTERFACE_DOWN;
  123. oi->flag = 0;
  124. /* Try to adust I/O buffer size with IfMtu */
  125. iobuflen = ospf6_iobuf_size (ifp->mtu);
  126. if (iobuflen < ifp->mtu)
  127. {
  128. zlog_info ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  129. ifp->name, iobuflen);
  130. oi->ifmtu = iobuflen;
  131. }
  132. else
  133. oi->ifmtu = ifp->mtu;
  134. oi->lsupdate_list = ospf6_lsdb_create ();
  135. oi->lsack_list = ospf6_lsdb_create ();
  136. oi->lsdb = ospf6_lsdb_create ();
  137. oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
  138. oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
  139. oi->route_connected = ospf6_route_table_create ();
  140. /* link both */
  141. oi->interface = ifp;
  142. ifp->info = oi;
  143. return oi;
  144. }
  145. void
  146. ospf6_interface_delete (struct ospf6_interface *oi)
  147. {
  148. listnode n;
  149. struct ospf6_neighbor *on;
  150. for (n = listhead (oi->neighbor_list); n; nextnode (n))
  151. {
  152. on = (struct ospf6_neighbor *) getdata (n);
  153. ospf6_neighbor_delete (on);
  154. }
  155. list_delete (oi->neighbor_list);
  156. THREAD_OFF (oi->thread_send_hello);
  157. THREAD_OFF (oi->thread_send_lsupdate);
  158. THREAD_OFF (oi->thread_send_lsack);
  159. ospf6_lsdb_remove_all (oi->lsdb);
  160. ospf6_lsdb_remove_all (oi->lsupdate_list);
  161. ospf6_lsdb_remove_all (oi->lsack_list);
  162. ospf6_lsdb_delete (oi->lsdb);
  163. ospf6_lsdb_delete (oi->lsupdate_list);
  164. ospf6_lsdb_delete (oi->lsack_list);
  165. ospf6_route_table_delete (oi->route_connected);
  166. /* cut link */
  167. oi->interface->info = NULL;
  168. /* plist_name */
  169. if (oi->plist_name)
  170. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  171. XFREE (MTYPE_OSPF6_IF, oi);
  172. }
  173. void
  174. ospf6_interface_enable (struct ospf6_interface *oi)
  175. {
  176. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
  177. oi->thread_send_hello =
  178. thread_add_event (master, ospf6_hello_send, oi, 0);
  179. }
  180. void
  181. ospf6_interface_disable (struct ospf6_interface *oi)
  182. {
  183. listnode i;
  184. struct ospf6_neighbor *on;
  185. SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
  186. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  187. {
  188. on = (struct ospf6_neighbor *) getdata (i);
  189. ospf6_neighbor_delete (on);
  190. }
  191. list_delete_all_node (oi->neighbor_list);
  192. ospf6_lsdb_remove_all (oi->lsdb);
  193. ospf6_lsdb_remove_all (oi->lsupdate_list);
  194. ospf6_lsdb_remove_all (oi->lsack_list);
  195. THREAD_OFF (oi->thread_send_hello);
  196. THREAD_OFF (oi->thread_send_lsupdate);
  197. THREAD_OFF (oi->thread_send_lsack);
  198. }
  199. static struct in6_addr *
  200. ospf6_interface_get_linklocal_address (struct interface *ifp)
  201. {
  202. listnode n;
  203. struct connected *c;
  204. struct in6_addr *l = (struct in6_addr *) NULL;
  205. /* for each connected address */
  206. for (n = listhead (ifp->connected); n; nextnode (n))
  207. {
  208. c = (struct connected *) getdata (n);
  209. /* if family not AF_INET6, ignore */
  210. if (c->address->family != AF_INET6)
  211. continue;
  212. /* linklocal scope check */
  213. if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
  214. l = &c->address->u.prefix6;
  215. }
  216. return l;
  217. }
  218. void
  219. ospf6_interface_if_add (struct interface *ifp)
  220. {
  221. struct ospf6_interface *oi;
  222. int iobuflen;
  223. oi = (struct ospf6_interface *) ifp->info;
  224. if (oi == NULL)
  225. return;
  226. /* Try to adust I/O buffer size with IfMtu */
  227. iobuflen = ospf6_iobuf_size (ifp->mtu);
  228. if (iobuflen < ifp->mtu)
  229. {
  230. zlog_info ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  231. ifp->name, iobuflen);
  232. oi->ifmtu = iobuflen;
  233. }
  234. else
  235. oi->ifmtu = ifp->mtu;
  236. /* interface start */
  237. if (oi->area)
  238. thread_add_event (master, interface_up, oi, 0);
  239. }
  240. void
  241. ospf6_interface_if_del (struct interface *ifp)
  242. {
  243. struct ospf6_interface *oi;
  244. oi = (struct ospf6_interface *) ifp->info;
  245. if (oi == NULL)
  246. return;
  247. /* interface stop */
  248. if (oi->area)
  249. thread_execute (master, interface_down, oi, 0);
  250. listnode_delete (oi->area->if_list, oi);
  251. oi->area = (struct ospf6_area *) NULL;
  252. /* cut link */
  253. oi->interface = NULL;
  254. ifp->info = NULL;
  255. ospf6_interface_delete (oi);
  256. }
  257. void
  258. ospf6_interface_state_update (struct interface *ifp)
  259. {
  260. struct ospf6_interface *oi;
  261. oi = (struct ospf6_interface *) ifp->info;
  262. if (oi == NULL)
  263. return;
  264. if (oi->area == NULL)
  265. return;
  266. if (if_is_up (ifp))
  267. thread_add_event (master, interface_up, oi, 0);
  268. else
  269. thread_add_event (master, interface_down, oi, 0);
  270. return;
  271. }
  272. void
  273. ospf6_interface_connected_route_update (struct interface *ifp)
  274. {
  275. struct ospf6_interface *oi;
  276. struct ospf6_route *route;
  277. struct connected *c;
  278. listnode i;
  279. oi = (struct ospf6_interface *) ifp->info;
  280. if (oi == NULL)
  281. return;
  282. /* reset linklocal pointer */
  283. oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
  284. /* if area is null, do not make connected-route list */
  285. if (oi->area == NULL)
  286. return;
  287. /* update "route to advertise" interface route table */
  288. ospf6_route_remove_all (oi->route_connected);
  289. for (i = listhead (oi->interface->connected); i; nextnode (i))
  290. {
  291. c = (struct connected *) getdata (i);
  292. if (c->address->family != AF_INET6)
  293. continue;
  294. CONTINUE_IF_ADDRESS_LINKLOCAL (c->address);
  295. CONTINUE_IF_ADDRESS_UNSPECIFIED (c->address);
  296. CONTINUE_IF_ADDRESS_LOOPBACK (c->address);
  297. CONTINUE_IF_ADDRESS_V4COMPAT (c->address);
  298. CONTINUE_IF_ADDRESS_V4MAPPED (c->address);
  299. /* apply filter */
  300. if (oi->plist_name)
  301. {
  302. struct prefix_list *plist;
  303. enum prefix_list_type ret;
  304. char buf[128];
  305. prefix2str (c->address, buf, sizeof (buf));
  306. plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
  307. ret = prefix_list_apply (plist, (void *) c->address);
  308. if (ret == PREFIX_DENY)
  309. {
  310. zlog_info ("%s on %s filtered by prefix-list %s ",
  311. buf, oi->interface->name, oi->plist_name);
  312. continue;
  313. }
  314. }
  315. route = ospf6_route_create ();
  316. memcpy (&route->prefix, c->address, sizeof (struct prefix));
  317. apply_mask (&route->prefix);
  318. route->type = OSPF6_DEST_TYPE_NETWORK;
  319. route->path.area_id = oi->area->area_id;
  320. route->path.type = OSPF6_PATH_TYPE_INTRA;
  321. route->path.cost = oi->cost;
  322. route->nexthop[0].ifindex = oi->interface->ifindex;
  323. inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
  324. ospf6_route_add (route, oi->route_connected);
  325. }
  326. /* create new Link-LSA */
  327. OSPF6_LINK_LSA_SCHEDULE (oi);
  328. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  329. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  330. }
  331. static void
  332. ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
  333. {
  334. u_char prev_state;
  335. prev_state = oi->state;
  336. oi->state = next_state;
  337. if (prev_state == next_state)
  338. return;
  339. /* log */
  340. if (IS_OSPF6_DEBUG_INTERFACE)
  341. {
  342. zlog_info ("Interface state change %s: %s -> %s", oi->interface->name,
  343. ospf6_interface_state_str[prev_state],
  344. ospf6_interface_state_str[next_state]);
  345. }
  346. if ((prev_state == OSPF6_INTERFACE_DR ||
  347. prev_state == OSPF6_INTERFACE_BDR) &&
  348. (next_state != OSPF6_INTERFACE_DR &&
  349. next_state != OSPF6_INTERFACE_BDR))
  350. ospf6_leave_alldrouters (oi->interface->ifindex);
  351. if ((prev_state != OSPF6_INTERFACE_DR &&
  352. prev_state != OSPF6_INTERFACE_BDR) &&
  353. (next_state == OSPF6_INTERFACE_DR ||
  354. next_state == OSPF6_INTERFACE_BDR))
  355. ospf6_join_alldrouters (oi->interface->ifindex);
  356. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  357. if (prev_state == OSPF6_INTERFACE_DR || next_state == OSPF6_INTERFACE_DR)
  358. {
  359. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  360. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  361. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  362. }
  363. }
  364. /* DR Election, RFC2328 section 9.4 */
  365. #define IS_ELIGIBLE(n) \
  366. ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
  367. static struct ospf6_neighbor *
  368. better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  369. {
  370. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
  371. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
  372. return NULL;
  373. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
  374. return b;
  375. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
  376. return a;
  377. if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
  378. return a;
  379. if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
  380. return b;
  381. if (a->priority > b->priority)
  382. return a;
  383. if (a->priority < b->priority)
  384. return b;
  385. if (ntohl (a->router_id) > ntohl (b->router_id))
  386. return a;
  387. if (ntohl (a->router_id) < ntohl (b->router_id))
  388. return b;
  389. zlog_warn ("Router-ID duplicate ?");
  390. return a;
  391. }
  392. static struct ospf6_neighbor *
  393. better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  394. {
  395. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
  396. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
  397. return NULL;
  398. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
  399. return b;
  400. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
  401. return a;
  402. if (a->drouter == a->router_id && b->drouter != b->router_id)
  403. return a;
  404. if (a->drouter != a->router_id && b->drouter == b->router_id)
  405. return b;
  406. if (a->priority > b->priority)
  407. return a;
  408. if (a->priority < b->priority)
  409. return b;
  410. if (ntohl (a->router_id) > ntohl (b->router_id))
  411. return a;
  412. if (ntohl (a->router_id) < ntohl (b->router_id))
  413. return b;
  414. zlog_warn ("Router-ID duplicate ?");
  415. return a;
  416. }
  417. static u_char
  418. dr_election (struct ospf6_interface *oi)
  419. {
  420. listnode i;
  421. struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
  422. struct ospf6_neighbor *best_drouter, *best_bdrouter;
  423. u_char next_state = 0;
  424. drouter = bdrouter = NULL;
  425. best_drouter = best_bdrouter = NULL;
  426. /* pseudo neighbor myself, including noting current DR/BDR (1) */
  427. memset (&myself, 0, sizeof (myself));
  428. inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
  429. sizeof (myself.name));
  430. myself.state = OSPF6_NEIGHBOR_TWOWAY;
  431. myself.drouter = oi->drouter;
  432. myself.bdrouter = oi->bdrouter;
  433. myself.priority = oi->priority;
  434. myself.router_id = oi->area->ospf6->router_id;
  435. /* Electing BDR (2) */
  436. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  437. {
  438. on = (struct ospf6_neighbor *) getdata (i);
  439. bdrouter = better_bdrouter (bdrouter, on);
  440. }
  441. best_bdrouter = bdrouter;
  442. bdrouter = better_bdrouter (best_bdrouter, &myself);
  443. /* Electing DR (3) */
  444. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  445. {
  446. on = (struct ospf6_neighbor *) getdata (i);
  447. drouter = better_drouter (drouter, on);
  448. }
  449. best_drouter = drouter;
  450. drouter = better_drouter (best_drouter, &myself);
  451. if (drouter == NULL)
  452. drouter = bdrouter;
  453. /* the router itself is newly/no longer DR/BDR (4) */
  454. if ((drouter == &myself && myself.drouter != myself.router_id) ||
  455. (drouter != &myself && myself.drouter == myself.router_id) ||
  456. (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
  457. (bdrouter != &myself && myself.bdrouter == myself.router_id))
  458. {
  459. myself.drouter = (drouter ? drouter->router_id : htonl (0));
  460. myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  461. /* compatible to Electing BDR (2) */
  462. bdrouter = better_bdrouter (best_bdrouter, &myself);
  463. /* compatible to Electing DR (3) */
  464. drouter = better_drouter (best_drouter, &myself);
  465. if (drouter == NULL)
  466. drouter = bdrouter;
  467. }
  468. /* Set interface state accordingly (5) */
  469. if (drouter && drouter == &myself)
  470. next_state = OSPF6_INTERFACE_DR;
  471. else if (bdrouter && bdrouter == &myself)
  472. next_state = OSPF6_INTERFACE_BDR;
  473. else
  474. next_state = OSPF6_INTERFACE_DROTHER;
  475. /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
  476. /* XXX */
  477. /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
  478. /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
  479. accordingly after AdjOK */
  480. if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
  481. oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
  482. {
  483. if (IS_OSPF6_DEBUG_INTERFACE)
  484. zlog_info ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
  485. (drouter ? drouter->name : "0.0.0.0"),
  486. (bdrouter ? bdrouter->name : "0.0.0.0"));
  487. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  488. {
  489. on = (struct ospf6_neighbor *) getdata (i);
  490. if (on->state < OSPF6_NEIGHBOR_TWOWAY)
  491. continue;
  492. /* Schedule AdjOK. */
  493. thread_add_event (master, adj_ok, on, 0);
  494. }
  495. }
  496. oi->drouter = (drouter ? drouter->router_id : htonl (0));
  497. oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  498. return next_state;
  499. }
  500. /* Interface State Machine */
  501. int
  502. interface_up (struct thread *thread)
  503. {
  504. struct ospf6_interface *oi;
  505. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  506. assert (oi && oi->interface);
  507. if (IS_OSPF6_DEBUG_INTERFACE)
  508. zlog_info ("Interface Event %s: [InterfaceUp]",
  509. oi->interface->name);
  510. /* check physical interface is up */
  511. if (! if_is_up (oi->interface))
  512. {
  513. if (IS_OSPF6_DEBUG_INTERFACE)
  514. zlog_info ("Interface %s is down, can't execute [InterfaceUp]",
  515. oi->interface->name);
  516. return 0;
  517. }
  518. /* if already enabled, do nothing */
  519. if (oi->state > OSPF6_INTERFACE_DOWN)
  520. {
  521. if (IS_OSPF6_DEBUG_INTERFACE)
  522. zlog_info ("Interface %s already enabled",
  523. oi->interface->name);
  524. return 0;
  525. }
  526. /* Join AllSPFRouters */
  527. ospf6_join_allspfrouters (oi->interface->ifindex);
  528. /* Update interface route */
  529. ospf6_interface_connected_route_update (oi->interface);
  530. /* Schedule Hello */
  531. if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  532. thread_add_event (master, ospf6_hello_send, oi, 0);
  533. /* decide next interface state */
  534. if (if_is_pointopoint (oi->interface))
  535. ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
  536. else if (oi->priority == 0)
  537. ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
  538. else
  539. {
  540. ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
  541. thread_add_timer (master, wait_timer, oi, oi->dead_interval);
  542. }
  543. return 0;
  544. }
  545. int
  546. wait_timer (struct thread *thread)
  547. {
  548. struct ospf6_interface *oi;
  549. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  550. assert (oi && oi->interface);
  551. if (IS_OSPF6_DEBUG_INTERFACE)
  552. zlog_info ("Interface Event %s: [WaitTimer]",
  553. oi->interface->name);
  554. if (oi->state == OSPF6_INTERFACE_WAITING)
  555. ospf6_interface_state_change (dr_election (oi), oi);
  556. return 0;
  557. }
  558. int
  559. backup_seen (struct thread *thread)
  560. {
  561. struct ospf6_interface *oi;
  562. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  563. assert (oi && oi->interface);
  564. if (IS_OSPF6_DEBUG_INTERFACE)
  565. zlog_info ("Interface Event %s: [BackupSeen]",
  566. oi->interface->name);
  567. if (oi->state == OSPF6_INTERFACE_WAITING)
  568. ospf6_interface_state_change (dr_election (oi), oi);
  569. return 0;
  570. }
  571. int
  572. neighbor_change (struct thread *thread)
  573. {
  574. struct ospf6_interface *oi;
  575. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  576. assert (oi && oi->interface);
  577. if (IS_OSPF6_DEBUG_INTERFACE)
  578. zlog_info ("Interface Event %s: [NeighborChange]",
  579. oi->interface->name);
  580. if (oi->state == OSPF6_INTERFACE_DROTHER ||
  581. oi->state == OSPF6_INTERFACE_BDR ||
  582. oi->state == OSPF6_INTERFACE_DR)
  583. ospf6_interface_state_change (dr_election (oi), oi);
  584. return 0;
  585. }
  586. int
  587. loopind (struct thread *thread)
  588. {
  589. struct ospf6_interface *oi;
  590. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  591. assert (oi && oi->interface);
  592. if (IS_OSPF6_DEBUG_INTERFACE)
  593. zlog_info ("Interface Event %s: [LoopInd]",
  594. oi->interface->name);
  595. /* XXX not yet */
  596. return 0;
  597. }
  598. int
  599. interface_down (struct thread *thread)
  600. {
  601. struct ospf6_interface *oi;
  602. listnode n;
  603. struct ospf6_neighbor *on;
  604. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  605. assert (oi && oi->interface);
  606. if (IS_OSPF6_DEBUG_INTERFACE)
  607. zlog_info ("Interface Event %s: [InterfaceDown]",
  608. oi->interface->name);
  609. /* Leave AllSPFRouters */
  610. if (oi->state > OSPF6_INTERFACE_DOWN)
  611. ospf6_leave_allspfrouters (oi->interface->ifindex);
  612. ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
  613. for (n = listhead (oi->neighbor_list); n; nextnode (n))
  614. {
  615. on = (struct ospf6_neighbor *) getdata (n);
  616. ospf6_neighbor_delete (on);
  617. }
  618. list_delete_all_node (oi->neighbor_list);
  619. return 0;
  620. }
  621. /* show specified interface structure */
  622. int
  623. ospf6_interface_show (struct vty *vty, struct interface *ifp)
  624. {
  625. struct ospf6_interface *oi;
  626. struct connected *c;
  627. struct prefix *p;
  628. listnode i;
  629. char strbuf[64], drouter[32], bdrouter[32];
  630. char *updown[3] = {"down", "up", NULL};
  631. char *type;
  632. struct timeval res, now;
  633. char duration[32];
  634. struct ospf6_lsa *lsa;
  635. /* check physical interface type */
  636. if (if_is_loopback (ifp))
  637. type = "LOOPBACK";
  638. else if (if_is_broadcast (ifp))
  639. type = "BROADCAST";
  640. else if (if_is_pointopoint (ifp))
  641. type = "POINTOPOINT";
  642. else
  643. type = "UNKNOWN";
  644. vty_out (vty, "%s is %s, type %s%s",
  645. ifp->name, updown[if_is_up (ifp)], type,
  646. VTY_NEWLINE);
  647. vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VTY_NEWLINE);
  648. if (ifp->info == NULL)
  649. {
  650. vty_out (vty, " OSPF not enabled on this interface%s", VTY_NEWLINE);
  651. return 0;
  652. }
  653. else
  654. oi = (struct ospf6_interface *) ifp->info;
  655. vty_out (vty, " Internet Address:%s", VTY_NEWLINE);
  656. for (i = listhead (ifp->connected); i; nextnode (i))
  657. {
  658. c = (struct connected *)getdata (i);
  659. p = c->address;
  660. prefix2str (p, strbuf, sizeof (strbuf));
  661. switch (p->family)
  662. {
  663. case AF_INET:
  664. vty_out (vty, " inet : %s%s", strbuf,
  665. VTY_NEWLINE);
  666. break;
  667. case AF_INET6:
  668. vty_out (vty, " inet6: %s%s", strbuf,
  669. VTY_NEWLINE);
  670. break;
  671. default:
  672. vty_out (vty, " ??? : %s%s", strbuf,
  673. VTY_NEWLINE);
  674. break;
  675. }
  676. }
  677. if (oi->area)
  678. {
  679. vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
  680. oi->instance_id, oi->ifmtu, ifp->mtu, VTY_NEWLINE);
  681. inet_ntop (AF_INET, &oi->area->area_id,
  682. strbuf, sizeof (strbuf));
  683. vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
  684. VTY_NEWLINE);
  685. }
  686. else
  687. vty_out (vty, " Not Attached to Area%s", VTY_NEWLINE);
  688. vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
  689. ospf6_interface_state_str[oi->state],
  690. oi->transdelay, oi->priority,
  691. VTY_NEWLINE);
  692. vty_out (vty, " Timer intervals configured:%s", VTY_NEWLINE);
  693. vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
  694. oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
  695. VTY_NEWLINE);
  696. inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
  697. inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
  698. vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VTY_NEWLINE);
  699. vty_out (vty, " Number of I/F scoped LSAs is %u%s",
  700. oi->lsdb->count, VTY_NEWLINE);
  701. gettimeofday (&now, (struct timezone *) NULL);
  702. timerclear (&res);
  703. if (oi->thread_send_lsupdate)
  704. timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
  705. timerstring (&res, duration, sizeof (duration));
  706. vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
  707. oi->lsupdate_list->count, duration,
  708. (oi->thread_send_lsupdate ? "on" : "off"),
  709. VTY_NEWLINE);
  710. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  711. lsa = ospf6_lsdb_next (lsa))
  712. vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
  713. timerclear (&res);
  714. if (oi->thread_send_lsack)
  715. timersub (&oi->thread_send_lsack->u.sands, &now, &res);
  716. timerstring (&res, duration, sizeof (duration));
  717. vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
  718. oi->lsack_list->count, duration,
  719. (oi->thread_send_lsack ? "on" : "off"),
  720. VTY_NEWLINE);
  721. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  722. lsa = ospf6_lsdb_next (lsa))
  723. vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
  724. return 0;
  725. }
  726. /* show interface */
  727. DEFUN (show_ipv6_ospf6_interface,
  728. show_ipv6_ospf6_interface_ifname_cmd,
  729. "show ipv6 ospf6 interface IFNAME",
  730. SHOW_STR
  731. IP6_STR
  732. OSPF6_STR
  733. INTERFACE_STR
  734. IFNAME_STR
  735. )
  736. {
  737. struct interface *ifp;
  738. listnode i;
  739. if (argc)
  740. {
  741. ifp = if_lookup_by_name (argv[0]);
  742. if (ifp == NULL)
  743. {
  744. vty_out (vty, "No such Interface: %s%s", argv[0],
  745. VTY_NEWLINE);
  746. return CMD_WARNING;
  747. }
  748. ospf6_interface_show (vty, ifp);
  749. }
  750. else
  751. {
  752. for (i = listhead (iflist); i; nextnode (i))
  753. {
  754. ifp = (struct interface *) getdata (i);
  755. ospf6_interface_show (vty, ifp);
  756. }
  757. }
  758. return CMD_SUCCESS;
  759. }
  760. ALIAS (show_ipv6_ospf6_interface,
  761. show_ipv6_ospf6_interface_cmd,
  762. "show ipv6 ospf6 interface",
  763. SHOW_STR
  764. IP6_STR
  765. OSPF6_STR
  766. INTERFACE_STR
  767. );
  768. DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
  769. show_ipv6_ospf6_interface_ifname_prefix_cmd,
  770. "show ipv6 ospf6 interface IFNAME prefix",
  771. SHOW_STR
  772. IP6_STR
  773. OSPF6_STR
  774. INTERFACE_STR
  775. IFNAME_STR
  776. "Display connected prefixes to advertise\n"
  777. )
  778. {
  779. struct interface *ifp;
  780. struct ospf6_interface *oi;
  781. ifp = if_lookup_by_name (argv[0]);
  782. if (ifp == NULL)
  783. {
  784. vty_out (vty, "No such Interface: %s%s", argv[0], VTY_NEWLINE);
  785. return CMD_WARNING;
  786. }
  787. oi = ifp->info;
  788. if (oi == NULL)
  789. {
  790. vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VTY_NEWLINE);
  791. return CMD_WARNING;
  792. }
  793. argc--;
  794. argv++;
  795. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  796. return CMD_SUCCESS;
  797. }
  798. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  799. show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
  800. "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
  801. SHOW_STR
  802. IP6_STR
  803. OSPF6_STR
  804. INTERFACE_STR
  805. IFNAME_STR
  806. "Display connected prefixes to advertise\n"
  807. OSPF6_ROUTE_ADDRESS_STR
  808. OSPF6_ROUTE_PREFIX_STR
  809. "Dispaly details of the prefixes\n"
  810. );
  811. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  812. show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
  813. "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
  814. SHOW_STR
  815. IP6_STR
  816. OSPF6_STR
  817. INTERFACE_STR
  818. IFNAME_STR
  819. "Display connected prefixes to advertise\n"
  820. OSPF6_ROUTE_PREFIX_STR
  821. OSPF6_ROUTE_MATCH_STR
  822. "Dispaly details of the prefixes\n"
  823. );
  824. DEFUN (show_ipv6_ospf6_interface_prefix,
  825. show_ipv6_ospf6_interface_prefix_cmd,
  826. "show ipv6 ospf6 interface prefix",
  827. SHOW_STR
  828. IP6_STR
  829. OSPF6_STR
  830. INTERFACE_STR
  831. "Display connected prefixes to advertise\n"
  832. )
  833. {
  834. listnode i;
  835. struct ospf6_interface *oi;
  836. struct interface *ifp;
  837. for (i = listhead (iflist); i; nextnode (i))
  838. {
  839. ifp = (struct interface *) getdata (i);
  840. oi = (struct ospf6_interface *) ifp->info;
  841. if (oi == NULL)
  842. continue;
  843. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  844. }
  845. return CMD_SUCCESS;
  846. }
  847. ALIAS (show_ipv6_ospf6_interface_prefix,
  848. show_ipv6_ospf6_interface_prefix_detail_cmd,
  849. "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
  850. SHOW_STR
  851. IP6_STR
  852. OSPF6_STR
  853. INTERFACE_STR
  854. "Display connected prefixes to advertise\n"
  855. OSPF6_ROUTE_ADDRESS_STR
  856. OSPF6_ROUTE_PREFIX_STR
  857. "Dispaly details of the prefixes\n"
  858. );
  859. ALIAS (show_ipv6_ospf6_interface_prefix,
  860. show_ipv6_ospf6_interface_prefix_match_cmd,
  861. "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
  862. SHOW_STR
  863. IP6_STR
  864. OSPF6_STR
  865. INTERFACE_STR
  866. "Display connected prefixes to advertise\n"
  867. OSPF6_ROUTE_PREFIX_STR
  868. OSPF6_ROUTE_MATCH_STR
  869. "Dispaly details of the prefixes\n"
  870. );
  871. /* interface variable set command */
  872. DEFUN (ipv6_ospf6_cost,
  873. ipv6_ospf6_cost_cmd,
  874. "ipv6 ospf6 cost <1-65535>",
  875. IP6_STR
  876. OSPF6_STR
  877. "Interface cost\n"
  878. "Outgoing metric of this interface\n"
  879. )
  880. {
  881. struct ospf6_interface *oi;
  882. struct interface *ifp;
  883. ifp = (struct interface *) vty->index;
  884. assert (ifp);
  885. oi = (struct ospf6_interface *) ifp->info;
  886. if (oi == NULL)
  887. oi = ospf6_interface_create (ifp);
  888. assert (oi);
  889. if (oi->cost == strtol (argv[0], NULL, 10))
  890. return CMD_SUCCESS;
  891. oi->cost = strtol (argv[0], NULL, 10);
  892. /* update cost held in route_connected list in ospf6_interface */
  893. ospf6_interface_connected_route_update (oi->interface);
  894. /* execute LSA hooks */
  895. if (oi->area)
  896. {
  897. OSPF6_LINK_LSA_SCHEDULE (oi);
  898. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  899. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  900. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  901. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  902. }
  903. return CMD_SUCCESS;
  904. }
  905. DEFUN (ipv6_ospf6_hellointerval,
  906. ipv6_ospf6_hellointerval_cmd,
  907. "ipv6 ospf6 hello-interval <1-65535>",
  908. IP6_STR
  909. OSPF6_STR
  910. "Interval time of Hello packets\n"
  911. SECONDS_STR
  912. )
  913. {
  914. struct ospf6_interface *oi;
  915. struct interface *ifp;
  916. ifp = (struct interface *) vty->index;
  917. assert (ifp);
  918. oi = (struct ospf6_interface *) ifp->info;
  919. if (oi == NULL)
  920. oi = ospf6_interface_create (ifp);
  921. assert (oi);
  922. oi->hello_interval = strtol (argv[0], NULL, 10);
  923. return CMD_SUCCESS;
  924. }
  925. /* interface variable set command */
  926. DEFUN (ipv6_ospf6_deadinterval,
  927. ipv6_ospf6_deadinterval_cmd,
  928. "ipv6 ospf6 dead-interval <1-65535>",
  929. IP6_STR
  930. OSPF6_STR
  931. "Interval time after which a neighbor is declared down\n"
  932. SECONDS_STR
  933. )
  934. {
  935. struct ospf6_interface *oi;
  936. struct interface *ifp;
  937. ifp = (struct interface *) vty->index;
  938. assert (ifp);
  939. oi = (struct ospf6_interface *) ifp->info;
  940. if (oi == NULL)
  941. oi = ospf6_interface_create (ifp);
  942. assert (oi);
  943. oi->dead_interval = strtol (argv[0], NULL, 10);
  944. return CMD_SUCCESS;
  945. }
  946. /* interface variable set command */
  947. DEFUN (ipv6_ospf6_transmitdelay,
  948. ipv6_ospf6_transmitdelay_cmd,
  949. "ipv6 ospf6 transmit-delay <1-3600>",
  950. IP6_STR
  951. OSPF6_STR
  952. "Transmit delay of this interface\n"
  953. SECONDS_STR
  954. )
  955. {
  956. struct ospf6_interface *oi;
  957. struct interface *ifp;
  958. ifp = (struct interface *) vty->index;
  959. assert (ifp);
  960. oi = (struct ospf6_interface *) ifp->info;
  961. if (oi == NULL)
  962. oi = ospf6_interface_create (ifp);
  963. assert (oi);
  964. oi->transdelay = strtol (argv[0], NULL, 10);
  965. return CMD_SUCCESS;
  966. }
  967. /* interface variable set command */
  968. DEFUN (ipv6_ospf6_retransmitinterval,
  969. ipv6_ospf6_retransmitinterval_cmd,
  970. "ipv6 ospf6 retransmit-interval <1-65535>",
  971. IP6_STR
  972. OSPF6_STR
  973. "Time between retransmitting lost link state advertisements\n"
  974. SECONDS_STR
  975. )
  976. {
  977. struct ospf6_interface *oi;
  978. struct interface *ifp;
  979. ifp = (struct interface *) vty->index;
  980. assert (ifp);
  981. oi = (struct ospf6_interface *) ifp->info;
  982. if (oi == NULL)
  983. oi = ospf6_interface_create (ifp);
  984. assert (oi);
  985. oi->rxmt_interval = strtol (argv[0], NULL, 10);
  986. return CMD_SUCCESS;
  987. }
  988. /* interface variable set command */
  989. DEFUN (ipv6_ospf6_priority,
  990. ipv6_ospf6_priority_cmd,
  991. "ipv6 ospf6 priority <0-255>",
  992. IP6_STR
  993. OSPF6_STR
  994. "Router priority\n"
  995. "Priority value\n"
  996. )
  997. {
  998. struct ospf6_interface *oi;
  999. struct interface *ifp;
  1000. ifp = (struct interface *) vty->index;
  1001. assert (ifp);
  1002. oi = (struct ospf6_interface *) ifp->info;
  1003. if (oi == NULL)
  1004. oi = ospf6_interface_create (ifp);
  1005. assert (oi);
  1006. oi->priority = strtol (argv[0], NULL, 10);
  1007. if (oi->area)
  1008. ospf6_interface_state_change (dr_election (oi), oi);
  1009. return CMD_SUCCESS;
  1010. }
  1011. DEFUN (ipv6_ospf6_instance,
  1012. ipv6_ospf6_instance_cmd,
  1013. "ipv6 ospf6 instance-id <0-255>",
  1014. IP6_STR
  1015. OSPF6_STR
  1016. "Instance ID for this interface\n"
  1017. "Instance ID value\n"
  1018. )
  1019. {
  1020. struct ospf6_interface *oi;
  1021. struct interface *ifp;
  1022. ifp = (struct interface *)vty->index;
  1023. assert (ifp);
  1024. oi = (struct ospf6_interface *)ifp->info;
  1025. if (oi == NULL)
  1026. oi = ospf6_interface_create (ifp);
  1027. assert (oi);
  1028. oi->instance_id = strtol (argv[0], NULL, 10);
  1029. return CMD_SUCCESS;
  1030. }
  1031. DEFUN (ipv6_ospf6_passive,
  1032. ipv6_ospf6_passive_cmd,
  1033. "ipv6 ospf6 passive",
  1034. IP6_STR
  1035. OSPF6_STR
  1036. "passive interface, No adjacency will be formed on this interface\n"
  1037. )
  1038. {
  1039. struct ospf6_interface *oi;
  1040. struct interface *ifp;
  1041. listnode node;
  1042. struct ospf6_neighbor *on;
  1043. ifp = (struct interface *) vty->index;
  1044. assert (ifp);
  1045. oi = (struct ospf6_interface *) ifp->info;
  1046. if (oi == NULL)
  1047. oi = ospf6_interface_create (ifp);
  1048. assert (oi);
  1049. SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1050. THREAD_OFF (oi->thread_send_hello);
  1051. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  1052. {
  1053. on = (struct ospf6_neighbor *) getdata (node);
  1054. THREAD_OFF (on->inactivity_timer);
  1055. thread_execute (master, inactivity_timer, on, 0);
  1056. }
  1057. return CMD_SUCCESS;
  1058. }
  1059. DEFUN (no_ipv6_ospf6_passive,
  1060. no_ipv6_ospf6_passive_cmd,
  1061. "no ipv6 ospf6 passive",
  1062. NO_STR
  1063. IP6_STR
  1064. OSPF6_STR
  1065. "passive interface: No Adjacency will be formed on this I/F\n"
  1066. )
  1067. {
  1068. struct ospf6_interface *oi;
  1069. struct interface *ifp;
  1070. ifp = (struct interface *) vty->index;
  1071. assert (ifp);
  1072. oi = (struct ospf6_interface *) ifp->info;
  1073. if (oi == NULL)
  1074. oi = ospf6_interface_create (ifp);
  1075. assert (oi);
  1076. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1077. THREAD_OFF (oi->thread_send_hello);
  1078. oi->thread_send_hello =
  1079. thread_add_event (master, ospf6_hello_send, oi, 0);
  1080. return CMD_SUCCESS;
  1081. }
  1082. DEFUN (ipv6_ospf6_advertise_prefix_list,
  1083. ipv6_ospf6_advertise_prefix_list_cmd,
  1084. "ipv6 ospf6 advertise prefix-list WORD",
  1085. IP6_STR
  1086. OSPF6_STR
  1087. "Advertising options\n"
  1088. "Filter prefix using prefix-list\n"
  1089. "Prefix list name\n"
  1090. )
  1091. {
  1092. struct ospf6_interface *oi;
  1093. struct interface *ifp;
  1094. ifp = (struct interface *) vty->index;
  1095. assert (ifp);
  1096. oi = (struct ospf6_interface *) ifp->info;
  1097. if (oi == NULL)
  1098. oi = ospf6_interface_create (ifp);
  1099. assert (oi);
  1100. if (oi->plist_name)
  1101. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1102. oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
  1103. ospf6_interface_connected_route_update (oi->interface);
  1104. OSPF6_LINK_LSA_SCHEDULE (oi);
  1105. if (oi->state == OSPF6_INTERFACE_DR)
  1106. {
  1107. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1108. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1109. }
  1110. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1111. return CMD_SUCCESS;
  1112. }
  1113. DEFUN (no_ipv6_ospf6_advertise_prefix_list,
  1114. no_ipv6_ospf6_advertise_prefix_list_cmd,
  1115. "no ipv6 ospf6 advertise prefix-list",
  1116. NO_STR
  1117. IP6_STR
  1118. OSPF6_STR
  1119. "Advertising options\n"
  1120. "Filter prefix using prefix-list\n"
  1121. )
  1122. {
  1123. struct ospf6_interface *oi;
  1124. struct interface *ifp;
  1125. ifp = (struct interface *) vty->index;
  1126. assert (ifp);
  1127. oi = (struct ospf6_interface *) ifp->info;
  1128. if (oi == NULL)
  1129. oi = ospf6_interface_create (ifp);
  1130. assert (oi);
  1131. if (oi->plist_name)
  1132. {
  1133. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1134. oi->plist_name = NULL;
  1135. }
  1136. ospf6_interface_connected_route_update (oi->interface);
  1137. OSPF6_LINK_LSA_SCHEDULE (oi);
  1138. if (oi->state == OSPF6_INTERFACE_DR)
  1139. {
  1140. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1141. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1142. }
  1143. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1144. return CMD_SUCCESS;
  1145. }
  1146. int
  1147. config_write_ospf6_interface (struct vty *vty)
  1148. {
  1149. listnode i;
  1150. struct ospf6_interface *oi;
  1151. struct interface *ifp;
  1152. for (i = listhead (iflist); i; nextnode (i))
  1153. {
  1154. ifp = (struct interface *) getdata (i);
  1155. oi = (struct ospf6_interface *) ifp->info;
  1156. if (oi == NULL)
  1157. continue;
  1158. vty_out (vty, "interface %s%s",
  1159. oi->interface->name, VTY_NEWLINE);
  1160. if (ifp->desc)
  1161. vty_out (vty, " description %s%s", ifp->desc, VTY_NEWLINE);
  1162. vty_out (vty, " ipv6 ospf6 cost %d%s",
  1163. oi->cost, VTY_NEWLINE);
  1164. vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
  1165. oi->hello_interval, VTY_NEWLINE);
  1166. vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
  1167. oi->dead_interval, VTY_NEWLINE);
  1168. vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
  1169. oi->rxmt_interval, VTY_NEWLINE);
  1170. vty_out (vty, " ipv6 ospf6 priority %d%s",
  1171. oi->priority, VTY_NEWLINE);
  1172. vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
  1173. oi->transdelay, VTY_NEWLINE);
  1174. vty_out (vty, " ipv6 ospf6 instance-id %d%s",
  1175. oi->instance_id, VTY_NEWLINE);
  1176. if (oi->plist_name)
  1177. vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
  1178. oi->plist_name, VTY_NEWLINE);
  1179. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1180. vty_out (vty, " ipv6 ospf6 passive%s", VTY_NEWLINE);
  1181. vty_out (vty, "!%s", VTY_NEWLINE);
  1182. }
  1183. return 0;
  1184. }
  1185. struct cmd_node interface_node =
  1186. {
  1187. INTERFACE_NODE,
  1188. "%s(config-if)# ",
  1189. };
  1190. void
  1191. ospf6_interface_init ()
  1192. {
  1193. /* Install interface node. */
  1194. install_node (&interface_node, config_write_ospf6_interface);
  1195. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
  1196. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1197. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1198. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1199. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1200. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1201. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1202. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1203. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
  1204. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1205. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1206. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1207. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1208. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1209. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1210. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1211. install_element (CONFIG_NODE, &interface_cmd);
  1212. install_default (INTERFACE_NODE);
  1213. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1214. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1215. install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
  1216. install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
  1217. install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
  1218. install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
  1219. install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
  1220. install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
  1221. install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
  1222. install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
  1223. install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
  1224. install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
  1225. install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
  1226. }
  1227. DEFUN (debug_ospf6_interface,
  1228. debug_ospf6_interface_cmd,
  1229. "debug ospf6 interface",
  1230. DEBUG_STR
  1231. OSPF6_STR
  1232. "Debug OSPFv3 Interface\n"
  1233. )
  1234. {
  1235. OSPF6_DEBUG_INTERFACE_ON ();
  1236. return CMD_SUCCESS;
  1237. }
  1238. DEFUN (no_debug_ospf6_interface,
  1239. no_debug_ospf6_interface_cmd,
  1240. "no debug ospf6 interface",
  1241. NO_STR
  1242. DEBUG_STR
  1243. OSPF6_STR
  1244. "Debug OSPFv3 Interface\n"
  1245. )
  1246. {
  1247. OSPF6_DEBUG_INTERFACE_ON ();
  1248. return CMD_SUCCESS;
  1249. }
  1250. int
  1251. config_write_ospf6_debug_interface (struct vty *vty)
  1252. {
  1253. if (IS_OSPF6_DEBUG_INTERFACE)
  1254. vty_out (vty, "debug ospf6 interface%s", VTY_NEWLINE);
  1255. return 0;
  1256. }
  1257. void
  1258. install_element_ospf6_debug_interface ()
  1259. {
  1260. install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
  1261. install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
  1262. install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
  1263. install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
  1264. }