ospf6_interface.c 42 KB

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