ospf6_interface.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575
  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 adjust I/O buffer size with IfMtu */
  125. oi->ifmtu = ifp->mtu;
  126. iobuflen = ospf6_iobuf_size (ifp->mtu);
  127. if (oi->ifmtu > iobuflen)
  128. {
  129. zlog_info ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  130. ifp->name, iobuflen);
  131. oi->ifmtu = iobuflen;
  132. }
  133. oi->lsupdate_list = ospf6_lsdb_create ();
  134. oi->lsack_list = ospf6_lsdb_create ();
  135. oi->lsdb = ospf6_lsdb_create ();
  136. oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
  137. oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
  138. oi->route_connected = ospf6_route_table_create ();
  139. /* link both */
  140. oi->interface = ifp;
  141. ifp->info = oi;
  142. return oi;
  143. }
  144. void
  145. ospf6_interface_delete (struct ospf6_interface *oi)
  146. {
  147. listnode n;
  148. struct ospf6_neighbor *on;
  149. for (n = listhead (oi->neighbor_list); n; nextnode (n))
  150. {
  151. on = (struct ospf6_neighbor *) getdata (n);
  152. ospf6_neighbor_delete (on);
  153. }
  154. list_delete (oi->neighbor_list);
  155. THREAD_OFF (oi->thread_send_hello);
  156. THREAD_OFF (oi->thread_send_lsupdate);
  157. THREAD_OFF (oi->thread_send_lsack);
  158. ospf6_lsdb_remove_all (oi->lsdb);
  159. ospf6_lsdb_remove_all (oi->lsupdate_list);
  160. ospf6_lsdb_remove_all (oi->lsack_list);
  161. ospf6_lsdb_delete (oi->lsdb);
  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->mtu;
  228. iobuflen = ospf6_iobuf_size (ifp->mtu);
  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 (prev_state == OSPF6_INTERFACE_DR || next_state == OSPF6_INTERFACE_DR)
  357. {
  358. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  359. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  360. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  361. }
  362. }
  363. /* DR Election, RFC2328 section 9.4 */
  364. #define IS_ELIGIBLE(n) \
  365. ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
  366. static struct ospf6_neighbor *
  367. better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  368. {
  369. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
  370. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
  371. return NULL;
  372. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
  373. return b;
  374. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
  375. return a;
  376. if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
  377. return a;
  378. if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
  379. return b;
  380. if (a->priority > b->priority)
  381. return a;
  382. if (a->priority < b->priority)
  383. return b;
  384. if (ntohl (a->router_id) > ntohl (b->router_id))
  385. return a;
  386. if (ntohl (a->router_id) < ntohl (b->router_id))
  387. return b;
  388. zlog_warn ("Router-ID duplicate ?");
  389. return a;
  390. }
  391. static struct ospf6_neighbor *
  392. better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  393. {
  394. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
  395. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
  396. return NULL;
  397. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
  398. return b;
  399. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
  400. return a;
  401. if (a->drouter == a->router_id && b->drouter != b->router_id)
  402. return a;
  403. if (a->drouter != a->router_id && b->drouter == b->router_id)
  404. return b;
  405. if (a->priority > b->priority)
  406. return a;
  407. if (a->priority < b->priority)
  408. return b;
  409. if (ntohl (a->router_id) > ntohl (b->router_id))
  410. return a;
  411. if (ntohl (a->router_id) < ntohl (b->router_id))
  412. return b;
  413. zlog_warn ("Router-ID duplicate ?");
  414. return a;
  415. }
  416. static u_char
  417. dr_election (struct ospf6_interface *oi)
  418. {
  419. listnode i;
  420. struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
  421. struct ospf6_neighbor *best_drouter, *best_bdrouter;
  422. u_char next_state = 0;
  423. drouter = bdrouter = NULL;
  424. best_drouter = best_bdrouter = NULL;
  425. /* pseudo neighbor myself, including noting current DR/BDR (1) */
  426. memset (&myself, 0, sizeof (myself));
  427. inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
  428. sizeof (myself.name));
  429. myself.state = OSPF6_NEIGHBOR_TWOWAY;
  430. myself.drouter = oi->drouter;
  431. myself.bdrouter = oi->bdrouter;
  432. myself.priority = oi->priority;
  433. myself.router_id = oi->area->ospf6->router_id;
  434. /* Electing BDR (2) */
  435. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  436. {
  437. on = (struct ospf6_neighbor *) getdata (i);
  438. bdrouter = better_bdrouter (bdrouter, on);
  439. }
  440. best_bdrouter = bdrouter;
  441. bdrouter = better_bdrouter (best_bdrouter, &myself);
  442. /* Electing DR (3) */
  443. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  444. {
  445. on = (struct ospf6_neighbor *) getdata (i);
  446. drouter = better_drouter (drouter, on);
  447. }
  448. best_drouter = drouter;
  449. drouter = better_drouter (best_drouter, &myself);
  450. if (drouter == NULL)
  451. drouter = bdrouter;
  452. /* the router itself is newly/no longer DR/BDR (4) */
  453. if ((drouter == &myself && myself.drouter != myself.router_id) ||
  454. (drouter != &myself && myself.drouter == myself.router_id) ||
  455. (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
  456. (bdrouter != &myself && myself.bdrouter == myself.router_id))
  457. {
  458. myself.drouter = (drouter ? drouter->router_id : htonl (0));
  459. myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  460. /* compatible to Electing BDR (2) */
  461. bdrouter = better_bdrouter (best_bdrouter, &myself);
  462. /* compatible to Electing DR (3) */
  463. drouter = better_drouter (best_drouter, &myself);
  464. if (drouter == NULL)
  465. drouter = bdrouter;
  466. }
  467. /* Set interface state accordingly (5) */
  468. if (drouter && drouter == &myself)
  469. next_state = OSPF6_INTERFACE_DR;
  470. else if (bdrouter && bdrouter == &myself)
  471. next_state = OSPF6_INTERFACE_BDR;
  472. else
  473. next_state = OSPF6_INTERFACE_DROTHER;
  474. /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
  475. /* XXX */
  476. /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
  477. /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
  478. accordingly after AdjOK */
  479. if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
  480. oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
  481. {
  482. if (IS_OSPF6_DEBUG_INTERFACE)
  483. zlog_info ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
  484. (drouter ? drouter->name : "0.0.0.0"),
  485. (bdrouter ? bdrouter->name : "0.0.0.0"));
  486. for (i = listhead (oi->neighbor_list); i; nextnode (i))
  487. {
  488. on = (struct ospf6_neighbor *) getdata (i);
  489. if (on->state < OSPF6_NEIGHBOR_TWOWAY)
  490. continue;
  491. /* Schedule AdjOK. */
  492. thread_add_event (master, adj_ok, on, 0);
  493. }
  494. }
  495. oi->drouter = (drouter ? drouter->router_id : htonl (0));
  496. oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  497. return next_state;
  498. }
  499. /* Interface State Machine */
  500. int
  501. interface_up (struct thread *thread)
  502. {
  503. struct ospf6_interface *oi;
  504. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  505. assert (oi && oi->interface);
  506. if (IS_OSPF6_DEBUG_INTERFACE)
  507. zlog_info ("Interface Event %s: [InterfaceUp]",
  508. oi->interface->name);
  509. /* check physical interface is up */
  510. if (! if_is_up (oi->interface))
  511. {
  512. if (IS_OSPF6_DEBUG_INTERFACE)
  513. zlog_info ("Interface %s is down, can't execute [InterfaceUp]",
  514. oi->interface->name);
  515. return 0;
  516. }
  517. /* if already enabled, do nothing */
  518. if (oi->state > OSPF6_INTERFACE_DOWN)
  519. {
  520. if (IS_OSPF6_DEBUG_INTERFACE)
  521. zlog_info ("Interface %s already enabled",
  522. oi->interface->name);
  523. return 0;
  524. }
  525. /* Join AllSPFRouters */
  526. ospf6_join_allspfrouters (oi->interface->ifindex);
  527. /* Update interface route */
  528. ospf6_interface_connected_route_update (oi->interface);
  529. /* Schedule Hello */
  530. if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  531. thread_add_event (master, ospf6_hello_send, oi, 0);
  532. /* decide next interface state */
  533. if (if_is_pointopoint (oi->interface))
  534. ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
  535. else if (oi->priority == 0)
  536. ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
  537. else
  538. {
  539. ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
  540. thread_add_timer (master, wait_timer, oi, oi->dead_interval);
  541. }
  542. return 0;
  543. }
  544. int
  545. wait_timer (struct thread *thread)
  546. {
  547. struct ospf6_interface *oi;
  548. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  549. assert (oi && oi->interface);
  550. if (IS_OSPF6_DEBUG_INTERFACE)
  551. zlog_info ("Interface Event %s: [WaitTimer]",
  552. oi->interface->name);
  553. if (oi->state == OSPF6_INTERFACE_WAITING)
  554. ospf6_interface_state_change (dr_election (oi), oi);
  555. return 0;
  556. }
  557. int
  558. backup_seen (struct thread *thread)
  559. {
  560. struct ospf6_interface *oi;
  561. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  562. assert (oi && oi->interface);
  563. if (IS_OSPF6_DEBUG_INTERFACE)
  564. zlog_info ("Interface Event %s: [BackupSeen]",
  565. oi->interface->name);
  566. if (oi->state == OSPF6_INTERFACE_WAITING)
  567. ospf6_interface_state_change (dr_election (oi), oi);
  568. return 0;
  569. }
  570. int
  571. neighbor_change (struct thread *thread)
  572. {
  573. struct ospf6_interface *oi;
  574. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  575. assert (oi && oi->interface);
  576. if (IS_OSPF6_DEBUG_INTERFACE)
  577. zlog_info ("Interface Event %s: [NeighborChange]",
  578. oi->interface->name);
  579. if (oi->state == OSPF6_INTERFACE_DROTHER ||
  580. oi->state == OSPF6_INTERFACE_BDR ||
  581. oi->state == OSPF6_INTERFACE_DR)
  582. ospf6_interface_state_change (dr_election (oi), oi);
  583. return 0;
  584. }
  585. int
  586. loopind (struct thread *thread)
  587. {
  588. struct ospf6_interface *oi;
  589. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  590. assert (oi && oi->interface);
  591. if (IS_OSPF6_DEBUG_INTERFACE)
  592. zlog_info ("Interface Event %s: [LoopInd]",
  593. oi->interface->name);
  594. /* XXX not yet */
  595. return 0;
  596. }
  597. int
  598. interface_down (struct thread *thread)
  599. {
  600. struct ospf6_interface *oi;
  601. listnode n;
  602. struct ospf6_neighbor *on;
  603. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  604. assert (oi && oi->interface);
  605. if (IS_OSPF6_DEBUG_INTERFACE)
  606. zlog_info ("Interface Event %s: [InterfaceDown]",
  607. oi->interface->name);
  608. /* Leave AllSPFRouters */
  609. if (oi->state > OSPF6_INTERFACE_DOWN)
  610. ospf6_leave_allspfrouters (oi->interface->ifindex);
  611. ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
  612. for (n = listhead (oi->neighbor_list); n; nextnode (n))
  613. {
  614. on = (struct ospf6_neighbor *) getdata (n);
  615. ospf6_neighbor_delete (on);
  616. }
  617. list_delete_all_node (oi->neighbor_list);
  618. return 0;
  619. }
  620. /* show specified interface structure */
  621. int
  622. ospf6_interface_show (struct vty *vty, struct interface *ifp)
  623. {
  624. struct ospf6_interface *oi;
  625. struct connected *c;
  626. struct prefix *p;
  627. listnode i;
  628. char strbuf[64], drouter[32], bdrouter[32];
  629. char *updown[3] = {"down", "up", NULL};
  630. char *type;
  631. struct timeval res, now;
  632. char duration[32];
  633. struct ospf6_lsa *lsa;
  634. /* check physical interface type */
  635. if (if_is_loopback (ifp))
  636. type = "LOOPBACK";
  637. else if (if_is_broadcast (ifp))
  638. type = "BROADCAST";
  639. else if (if_is_pointopoint (ifp))
  640. type = "POINTOPOINT";
  641. else
  642. type = "UNKNOWN";
  643. vty_out (vty, "%s is %s, type %s%s",
  644. ifp->name, updown[if_is_up (ifp)], type,
  645. VTY_NEWLINE);
  646. vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VTY_NEWLINE);
  647. if (ifp->info == NULL)
  648. {
  649. vty_out (vty, " OSPF not enabled on this interface%s", VTY_NEWLINE);
  650. return 0;
  651. }
  652. else
  653. oi = (struct ospf6_interface *) ifp->info;
  654. vty_out (vty, " Internet Address:%s", VTY_NEWLINE);
  655. for (i = listhead (ifp->connected); i; nextnode (i))
  656. {
  657. c = (struct connected *)getdata (i);
  658. p = c->address;
  659. prefix2str (p, strbuf, sizeof (strbuf));
  660. switch (p->family)
  661. {
  662. case AF_INET:
  663. vty_out (vty, " inet : %s%s", strbuf,
  664. VTY_NEWLINE);
  665. break;
  666. case AF_INET6:
  667. vty_out (vty, " inet6: %s%s", strbuf,
  668. VTY_NEWLINE);
  669. break;
  670. default:
  671. vty_out (vty, " ??? : %s%s", strbuf,
  672. VTY_NEWLINE);
  673. break;
  674. }
  675. }
  676. if (oi->area)
  677. {
  678. vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
  679. oi->instance_id, oi->ifmtu, ifp->mtu, VTY_NEWLINE);
  680. inet_ntop (AF_INET, &oi->area->area_id,
  681. strbuf, sizeof (strbuf));
  682. vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
  683. VTY_NEWLINE);
  684. }
  685. else
  686. vty_out (vty, " Not Attached to Area%s", VTY_NEWLINE);
  687. vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
  688. ospf6_interface_state_str[oi->state],
  689. oi->transdelay, oi->priority,
  690. VTY_NEWLINE);
  691. vty_out (vty, " Timer intervals configured:%s", VTY_NEWLINE);
  692. vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
  693. oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
  694. VTY_NEWLINE);
  695. inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
  696. inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
  697. vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VTY_NEWLINE);
  698. vty_out (vty, " Number of I/F scoped LSAs is %u%s",
  699. oi->lsdb->count, VTY_NEWLINE);
  700. gettimeofday (&now, (struct timezone *) NULL);
  701. timerclear (&res);
  702. if (oi->thread_send_lsupdate)
  703. timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
  704. timerstring (&res, duration, sizeof (duration));
  705. vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
  706. oi->lsupdate_list->count, duration,
  707. (oi->thread_send_lsupdate ? "on" : "off"),
  708. VTY_NEWLINE);
  709. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  710. lsa = ospf6_lsdb_next (lsa))
  711. vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
  712. timerclear (&res);
  713. if (oi->thread_send_lsack)
  714. timersub (&oi->thread_send_lsack->u.sands, &now, &res);
  715. timerstring (&res, duration, sizeof (duration));
  716. vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
  717. oi->lsack_list->count, duration,
  718. (oi->thread_send_lsack ? "on" : "off"),
  719. VTY_NEWLINE);
  720. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  721. lsa = ospf6_lsdb_next (lsa))
  722. vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
  723. return 0;
  724. }
  725. /* show interface */
  726. DEFUN (show_ipv6_ospf6_interface,
  727. show_ipv6_ospf6_interface_ifname_cmd,
  728. "show ipv6 ospf6 interface IFNAME",
  729. SHOW_STR
  730. IP6_STR
  731. OSPF6_STR
  732. INTERFACE_STR
  733. IFNAME_STR
  734. )
  735. {
  736. struct interface *ifp;
  737. listnode i;
  738. if (argc)
  739. {
  740. ifp = if_lookup_by_name (argv[0]);
  741. if (ifp == NULL)
  742. {
  743. vty_out (vty, "No such Interface: %s%s", argv[0],
  744. VTY_NEWLINE);
  745. return CMD_WARNING;
  746. }
  747. ospf6_interface_show (vty, ifp);
  748. }
  749. else
  750. {
  751. for (i = listhead (iflist); i; nextnode (i))
  752. {
  753. ifp = (struct interface *) getdata (i);
  754. ospf6_interface_show (vty, ifp);
  755. }
  756. }
  757. return CMD_SUCCESS;
  758. }
  759. ALIAS (show_ipv6_ospf6_interface,
  760. show_ipv6_ospf6_interface_cmd,
  761. "show ipv6 ospf6 interface",
  762. SHOW_STR
  763. IP6_STR
  764. OSPF6_STR
  765. INTERFACE_STR
  766. );
  767. DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
  768. show_ipv6_ospf6_interface_ifname_prefix_cmd,
  769. "show ipv6 ospf6 interface IFNAME prefix",
  770. SHOW_STR
  771. IP6_STR
  772. OSPF6_STR
  773. INTERFACE_STR
  774. IFNAME_STR
  775. "Display connected prefixes to advertise\n"
  776. )
  777. {
  778. struct interface *ifp;
  779. struct ospf6_interface *oi;
  780. ifp = if_lookup_by_name (argv[0]);
  781. if (ifp == NULL)
  782. {
  783. vty_out (vty, "No such Interface: %s%s", argv[0], VTY_NEWLINE);
  784. return CMD_WARNING;
  785. }
  786. oi = ifp->info;
  787. if (oi == NULL)
  788. {
  789. vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VTY_NEWLINE);
  790. return CMD_WARNING;
  791. }
  792. argc--;
  793. argv++;
  794. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  795. return CMD_SUCCESS;
  796. }
  797. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  798. show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
  799. "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
  800. SHOW_STR
  801. IP6_STR
  802. OSPF6_STR
  803. INTERFACE_STR
  804. IFNAME_STR
  805. "Display connected prefixes to advertise\n"
  806. OSPF6_ROUTE_ADDRESS_STR
  807. OSPF6_ROUTE_PREFIX_STR
  808. "Dispaly details of the prefixes\n"
  809. );
  810. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  811. show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
  812. "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
  813. SHOW_STR
  814. IP6_STR
  815. OSPF6_STR
  816. INTERFACE_STR
  817. IFNAME_STR
  818. "Display connected prefixes to advertise\n"
  819. OSPF6_ROUTE_PREFIX_STR
  820. OSPF6_ROUTE_MATCH_STR
  821. "Dispaly details of the prefixes\n"
  822. );
  823. DEFUN (show_ipv6_ospf6_interface_prefix,
  824. show_ipv6_ospf6_interface_prefix_cmd,
  825. "show ipv6 ospf6 interface prefix",
  826. SHOW_STR
  827. IP6_STR
  828. OSPF6_STR
  829. INTERFACE_STR
  830. "Display connected prefixes to advertise\n"
  831. )
  832. {
  833. listnode i;
  834. struct ospf6_interface *oi;
  835. struct interface *ifp;
  836. for (i = listhead (iflist); i; nextnode (i))
  837. {
  838. ifp = (struct interface *) getdata (i);
  839. oi = (struct ospf6_interface *) ifp->info;
  840. if (oi == NULL)
  841. continue;
  842. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  843. }
  844. return CMD_SUCCESS;
  845. }
  846. ALIAS (show_ipv6_ospf6_interface_prefix,
  847. show_ipv6_ospf6_interface_prefix_detail_cmd,
  848. "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
  849. SHOW_STR
  850. IP6_STR
  851. OSPF6_STR
  852. INTERFACE_STR
  853. "Display connected prefixes to advertise\n"
  854. OSPF6_ROUTE_ADDRESS_STR
  855. OSPF6_ROUTE_PREFIX_STR
  856. "Dispaly details of the prefixes\n"
  857. );
  858. ALIAS (show_ipv6_ospf6_interface_prefix,
  859. show_ipv6_ospf6_interface_prefix_match_cmd,
  860. "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
  861. SHOW_STR
  862. IP6_STR
  863. OSPF6_STR
  864. INTERFACE_STR
  865. "Display connected prefixes to advertise\n"
  866. OSPF6_ROUTE_PREFIX_STR
  867. OSPF6_ROUTE_MATCH_STR
  868. "Dispaly details of the prefixes\n"
  869. );
  870. /* interface variable set command */
  871. DEFUN (ipv6_ospf6_ifmtu,
  872. ipv6_ospf6_ifmtu_cmd,
  873. "ipv6 ospf6 ifmtu <1-65535>",
  874. IP6_STR
  875. OSPF6_STR
  876. "Interface MTU\n"
  877. "OSPFv3 Interface MTU\n"
  878. )
  879. {
  880. struct ospf6_interface *oi;
  881. struct interface *ifp;
  882. int ifmtu, iobuflen;
  883. listnode node;
  884. struct ospf6_neighbor *on;
  885. ifp = (struct interface *) vty->index;
  886. assert (ifp);
  887. oi = (struct ospf6_interface *) ifp->info;
  888. if (oi == NULL)
  889. oi = ospf6_interface_create (ifp);
  890. assert (oi);
  891. ifmtu = strtol (argv[0], NULL, 10);
  892. if (oi->ifmtu == ifmtu)
  893. return CMD_SUCCESS;
  894. if (ifp->mtu != 0 && ifp->mtu < ifmtu)
  895. {
  896. vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
  897. ifp->name, ifp->mtu, VTY_NEWLINE);
  898. return CMD_WARNING;
  899. }
  900. if (oi->ifmtu < ifmtu)
  901. {
  902. iobuflen = ospf6_iobuf_size (ifmtu);
  903. if (iobuflen < ifmtu)
  904. {
  905. vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
  906. ifp->name, iobuflen, VTY_NEWLINE);
  907. oi->ifmtu = iobuflen;
  908. }
  909. else
  910. oi->ifmtu = ifmtu;
  911. }
  912. else
  913. oi->ifmtu = ifmtu;
  914. /* re-establish adjacencies */
  915. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  916. {
  917. on = (struct ospf6_neighbor *) getdata (node);
  918. THREAD_OFF (on->inactivity_timer);
  919. thread_execute (master, inactivity_timer, on, 0);
  920. }
  921. return CMD_SUCCESS;
  922. }
  923. DEFUN (ipv6_ospf6_cost,
  924. ipv6_ospf6_cost_cmd,
  925. "ipv6 ospf6 cost <1-65535>",
  926. IP6_STR
  927. OSPF6_STR
  928. "Interface cost\n"
  929. "Outgoing metric of this interface\n"
  930. )
  931. {
  932. struct ospf6_interface *oi;
  933. struct interface *ifp;
  934. ifp = (struct interface *) vty->index;
  935. assert (ifp);
  936. oi = (struct ospf6_interface *) ifp->info;
  937. if (oi == NULL)
  938. oi = ospf6_interface_create (ifp);
  939. assert (oi);
  940. if (oi->cost == strtol (argv[0], NULL, 10))
  941. return CMD_SUCCESS;
  942. oi->cost = strtol (argv[0], NULL, 10);
  943. /* update cost held in route_connected list in ospf6_interface */
  944. ospf6_interface_connected_route_update (oi->interface);
  945. /* execute LSA hooks */
  946. if (oi->area)
  947. {
  948. OSPF6_LINK_LSA_SCHEDULE (oi);
  949. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  950. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  951. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  952. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  953. }
  954. return CMD_SUCCESS;
  955. }
  956. DEFUN (ipv6_ospf6_hellointerval,
  957. ipv6_ospf6_hellointerval_cmd,
  958. "ipv6 ospf6 hello-interval <1-65535>",
  959. IP6_STR
  960. OSPF6_STR
  961. "Interval time of Hello packets\n"
  962. SECONDS_STR
  963. )
  964. {
  965. struct ospf6_interface *oi;
  966. struct interface *ifp;
  967. ifp = (struct interface *) vty->index;
  968. assert (ifp);
  969. oi = (struct ospf6_interface *) ifp->info;
  970. if (oi == NULL)
  971. oi = ospf6_interface_create (ifp);
  972. assert (oi);
  973. oi->hello_interval = strtol (argv[0], NULL, 10);
  974. return CMD_SUCCESS;
  975. }
  976. /* interface variable set command */
  977. DEFUN (ipv6_ospf6_deadinterval,
  978. ipv6_ospf6_deadinterval_cmd,
  979. "ipv6 ospf6 dead-interval <1-65535>",
  980. IP6_STR
  981. OSPF6_STR
  982. "Interval time after which a neighbor is declared down\n"
  983. SECONDS_STR
  984. )
  985. {
  986. struct ospf6_interface *oi;
  987. struct interface *ifp;
  988. ifp = (struct interface *) vty->index;
  989. assert (ifp);
  990. oi = (struct ospf6_interface *) ifp->info;
  991. if (oi == NULL)
  992. oi = ospf6_interface_create (ifp);
  993. assert (oi);
  994. oi->dead_interval = strtol (argv[0], NULL, 10);
  995. return CMD_SUCCESS;
  996. }
  997. /* interface variable set command */
  998. DEFUN (ipv6_ospf6_transmitdelay,
  999. ipv6_ospf6_transmitdelay_cmd,
  1000. "ipv6 ospf6 transmit-delay <1-3600>",
  1001. IP6_STR
  1002. OSPF6_STR
  1003. "Transmit delay of this interface\n"
  1004. SECONDS_STR
  1005. )
  1006. {
  1007. struct ospf6_interface *oi;
  1008. struct interface *ifp;
  1009. ifp = (struct interface *) vty->index;
  1010. assert (ifp);
  1011. oi = (struct ospf6_interface *) ifp->info;
  1012. if (oi == NULL)
  1013. oi = ospf6_interface_create (ifp);
  1014. assert (oi);
  1015. oi->transdelay = strtol (argv[0], NULL, 10);
  1016. return CMD_SUCCESS;
  1017. }
  1018. /* interface variable set command */
  1019. DEFUN (ipv6_ospf6_retransmitinterval,
  1020. ipv6_ospf6_retransmitinterval_cmd,
  1021. "ipv6 ospf6 retransmit-interval <1-65535>",
  1022. IP6_STR
  1023. OSPF6_STR
  1024. "Time between retransmitting lost link state advertisements\n"
  1025. SECONDS_STR
  1026. )
  1027. {
  1028. struct ospf6_interface *oi;
  1029. struct interface *ifp;
  1030. ifp = (struct interface *) vty->index;
  1031. assert (ifp);
  1032. oi = (struct ospf6_interface *) ifp->info;
  1033. if (oi == NULL)
  1034. oi = ospf6_interface_create (ifp);
  1035. assert (oi);
  1036. oi->rxmt_interval = strtol (argv[0], NULL, 10);
  1037. return CMD_SUCCESS;
  1038. }
  1039. /* interface variable set command */
  1040. DEFUN (ipv6_ospf6_priority,
  1041. ipv6_ospf6_priority_cmd,
  1042. "ipv6 ospf6 priority <0-255>",
  1043. IP6_STR
  1044. OSPF6_STR
  1045. "Router priority\n"
  1046. "Priority value\n"
  1047. )
  1048. {
  1049. struct ospf6_interface *oi;
  1050. struct interface *ifp;
  1051. ifp = (struct interface *) vty->index;
  1052. assert (ifp);
  1053. oi = (struct ospf6_interface *) ifp->info;
  1054. if (oi == NULL)
  1055. oi = ospf6_interface_create (ifp);
  1056. assert (oi);
  1057. oi->priority = strtol (argv[0], NULL, 10);
  1058. if (oi->area)
  1059. ospf6_interface_state_change (dr_election (oi), oi);
  1060. return CMD_SUCCESS;
  1061. }
  1062. DEFUN (ipv6_ospf6_instance,
  1063. ipv6_ospf6_instance_cmd,
  1064. "ipv6 ospf6 instance-id <0-255>",
  1065. IP6_STR
  1066. OSPF6_STR
  1067. "Instance ID for this interface\n"
  1068. "Instance ID value\n"
  1069. )
  1070. {
  1071. struct ospf6_interface *oi;
  1072. struct interface *ifp;
  1073. ifp = (struct interface *)vty->index;
  1074. assert (ifp);
  1075. oi = (struct ospf6_interface *)ifp->info;
  1076. if (oi == NULL)
  1077. oi = ospf6_interface_create (ifp);
  1078. assert (oi);
  1079. oi->instance_id = strtol (argv[0], NULL, 10);
  1080. return CMD_SUCCESS;
  1081. }
  1082. DEFUN (ipv6_ospf6_passive,
  1083. ipv6_ospf6_passive_cmd,
  1084. "ipv6 ospf6 passive",
  1085. IP6_STR
  1086. OSPF6_STR
  1087. "passive interface, No adjacency will be formed on this interface\n"
  1088. )
  1089. {
  1090. struct ospf6_interface *oi;
  1091. struct interface *ifp;
  1092. listnode node;
  1093. struct ospf6_neighbor *on;
  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. SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1101. THREAD_OFF (oi->thread_send_hello);
  1102. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  1103. {
  1104. on = (struct ospf6_neighbor *) getdata (node);
  1105. THREAD_OFF (on->inactivity_timer);
  1106. thread_execute (master, inactivity_timer, on, 0);
  1107. }
  1108. return CMD_SUCCESS;
  1109. }
  1110. DEFUN (no_ipv6_ospf6_passive,
  1111. no_ipv6_ospf6_passive_cmd,
  1112. "no ipv6 ospf6 passive",
  1113. NO_STR
  1114. IP6_STR
  1115. OSPF6_STR
  1116. "passive interface: No Adjacency will be formed on this I/F\n"
  1117. )
  1118. {
  1119. struct ospf6_interface *oi;
  1120. struct interface *ifp;
  1121. ifp = (struct interface *) vty->index;
  1122. assert (ifp);
  1123. oi = (struct ospf6_interface *) ifp->info;
  1124. if (oi == NULL)
  1125. oi = ospf6_interface_create (ifp);
  1126. assert (oi);
  1127. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1128. THREAD_OFF (oi->thread_send_hello);
  1129. oi->thread_send_hello =
  1130. thread_add_event (master, ospf6_hello_send, oi, 0);
  1131. return CMD_SUCCESS;
  1132. }
  1133. DEFUN (ipv6_ospf6_advertise_prefix_list,
  1134. ipv6_ospf6_advertise_prefix_list_cmd,
  1135. "ipv6 ospf6 advertise prefix-list WORD",
  1136. IP6_STR
  1137. OSPF6_STR
  1138. "Advertising options\n"
  1139. "Filter prefix using prefix-list\n"
  1140. "Prefix list name\n"
  1141. )
  1142. {
  1143. struct ospf6_interface *oi;
  1144. struct interface *ifp;
  1145. ifp = (struct interface *) vty->index;
  1146. assert (ifp);
  1147. oi = (struct ospf6_interface *) ifp->info;
  1148. if (oi == NULL)
  1149. oi = ospf6_interface_create (ifp);
  1150. assert (oi);
  1151. if (oi->plist_name)
  1152. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1153. oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
  1154. ospf6_interface_connected_route_update (oi->interface);
  1155. OSPF6_LINK_LSA_SCHEDULE (oi);
  1156. if (oi->state == OSPF6_INTERFACE_DR)
  1157. {
  1158. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1159. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1160. }
  1161. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1162. return CMD_SUCCESS;
  1163. }
  1164. DEFUN (no_ipv6_ospf6_advertise_prefix_list,
  1165. no_ipv6_ospf6_advertise_prefix_list_cmd,
  1166. "no ipv6 ospf6 advertise prefix-list",
  1167. NO_STR
  1168. IP6_STR
  1169. OSPF6_STR
  1170. "Advertising options\n"
  1171. "Filter prefix using prefix-list\n"
  1172. )
  1173. {
  1174. struct ospf6_interface *oi;
  1175. struct interface *ifp;
  1176. ifp = (struct interface *) vty->index;
  1177. assert (ifp);
  1178. oi = (struct ospf6_interface *) ifp->info;
  1179. if (oi == NULL)
  1180. oi = ospf6_interface_create (ifp);
  1181. assert (oi);
  1182. if (oi->plist_name)
  1183. {
  1184. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1185. oi->plist_name = NULL;
  1186. }
  1187. ospf6_interface_connected_route_update (oi->interface);
  1188. OSPF6_LINK_LSA_SCHEDULE (oi);
  1189. if (oi->state == OSPF6_INTERFACE_DR)
  1190. {
  1191. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1192. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1193. }
  1194. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1195. return CMD_SUCCESS;
  1196. }
  1197. int
  1198. config_write_ospf6_interface (struct vty *vty)
  1199. {
  1200. listnode i;
  1201. struct ospf6_interface *oi;
  1202. struct interface *ifp;
  1203. for (i = listhead (iflist); i; nextnode (i))
  1204. {
  1205. ifp = (struct interface *) getdata (i);
  1206. oi = (struct ospf6_interface *) ifp->info;
  1207. if (oi == NULL)
  1208. continue;
  1209. vty_out (vty, "interface %s%s",
  1210. oi->interface->name, VTY_NEWLINE);
  1211. if (ifp->desc)
  1212. vty_out (vty, " description %s%s", ifp->desc, VTY_NEWLINE);
  1213. if (ifp->mtu != oi->ifmtu)
  1214. vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VTY_NEWLINE);
  1215. vty_out (vty, " ipv6 ospf6 cost %d%s",
  1216. oi->cost, VTY_NEWLINE);
  1217. vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
  1218. oi->hello_interval, VTY_NEWLINE);
  1219. vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
  1220. oi->dead_interval, VTY_NEWLINE);
  1221. vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
  1222. oi->rxmt_interval, VTY_NEWLINE);
  1223. vty_out (vty, " ipv6 ospf6 priority %d%s",
  1224. oi->priority, VTY_NEWLINE);
  1225. vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
  1226. oi->transdelay, VTY_NEWLINE);
  1227. vty_out (vty, " ipv6 ospf6 instance-id %d%s",
  1228. oi->instance_id, VTY_NEWLINE);
  1229. if (oi->plist_name)
  1230. vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
  1231. oi->plist_name, VTY_NEWLINE);
  1232. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1233. vty_out (vty, " ipv6 ospf6 passive%s", VTY_NEWLINE);
  1234. vty_out (vty, "!%s", VTY_NEWLINE);
  1235. }
  1236. return 0;
  1237. }
  1238. struct cmd_node interface_node =
  1239. {
  1240. INTERFACE_NODE,
  1241. "%s(config-if)# ",
  1242. };
  1243. void
  1244. ospf6_interface_init ()
  1245. {
  1246. /* Install interface node. */
  1247. install_node (&interface_node, config_write_ospf6_interface);
  1248. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
  1249. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1250. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1251. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1252. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1253. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1254. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1255. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1256. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
  1257. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1258. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1259. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1260. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1261. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1262. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1263. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1264. install_element (CONFIG_NODE, &interface_cmd);
  1265. install_default (INTERFACE_NODE);
  1266. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1267. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1268. install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
  1269. install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
  1270. install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
  1271. install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
  1272. install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
  1273. install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
  1274. install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
  1275. install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
  1276. install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
  1277. install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
  1278. install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
  1279. install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
  1280. }
  1281. DEFUN (debug_ospf6_interface,
  1282. debug_ospf6_interface_cmd,
  1283. "debug ospf6 interface",
  1284. DEBUG_STR
  1285. OSPF6_STR
  1286. "Debug OSPFv3 Interface\n"
  1287. )
  1288. {
  1289. OSPF6_DEBUG_INTERFACE_ON ();
  1290. return CMD_SUCCESS;
  1291. }
  1292. DEFUN (no_debug_ospf6_interface,
  1293. no_debug_ospf6_interface_cmd,
  1294. "no debug ospf6 interface",
  1295. NO_STR
  1296. DEBUG_STR
  1297. OSPF6_STR
  1298. "Debug OSPFv3 Interface\n"
  1299. )
  1300. {
  1301. OSPF6_DEBUG_INTERFACE_ON ();
  1302. return CMD_SUCCESS;
  1303. }
  1304. int
  1305. config_write_ospf6_debug_interface (struct vty *vty)
  1306. {
  1307. if (IS_OSPF6_DEBUG_INTERFACE)
  1308. vty_out (vty, "debug ospf6 interface%s", VTY_NEWLINE);
  1309. return 0;
  1310. }
  1311. void
  1312. install_element_ospf6_debug_interface ()
  1313. {
  1314. install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
  1315. install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
  1316. install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
  1317. install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
  1318. }