ospf6_interface.c 40 KB

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