ospf6_interface.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "memory.h"
  23. #include "if.h"
  24. #include "log.h"
  25. #include "command.h"
  26. #include "thread.h"
  27. #include "prefix.h"
  28. #include "plist.h"
  29. #include "ospf6_lsa.h"
  30. #include "ospf6_lsdb.h"
  31. #include "ospf6_network.h"
  32. #include "ospf6_message.h"
  33. #include "ospf6_route.h"
  34. #include "ospf6_top.h"
  35. #include "ospf6_area.h"
  36. #include "ospf6_interface.h"
  37. #include "ospf6_neighbor.h"
  38. #include "ospf6_intra.h"
  39. #include "ospf6_spf.h"
  40. #include "ospf6d.h"
  41. unsigned char conf_debug_ospf6_interface = 0;
  42. char *ospf6_interface_state_str[] =
  43. {
  44. "None",
  45. "Down",
  46. "Loopback",
  47. "Waiting",
  48. "PointToPoint",
  49. "DROther",
  50. "BDR",
  51. "DR",
  52. NULL
  53. };
  54. struct ospf6_interface *
  55. ospf6_interface_lookup_by_ifindex (int ifindex)
  56. {
  57. struct ospf6_interface *oi;
  58. struct interface *ifp;
  59. ifp = if_lookup_by_index (ifindex);
  60. if (ifp == NULL)
  61. return (struct ospf6_interface *) NULL;
  62. oi = (struct ospf6_interface *) ifp->info;
  63. return oi;
  64. }
  65. struct ospf6_interface *
  66. ospf6_interface_lookup_by_name (char *ifname)
  67. {
  68. struct ospf6_interface *oi;
  69. struct interface *ifp;
  70. ifp = if_lookup_by_name (ifname);
  71. if (ifp == NULL)
  72. return (struct ospf6_interface *) NULL;
  73. oi = (struct ospf6_interface *) ifp->info;
  74. return oi;
  75. }
  76. /* schedule routing table recalculation */
  77. void
  78. ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
  79. {
  80. 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->mtu6;
  126. iobuflen = ospf6_iobuf_size (ifp->mtu6);
  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->mtu6;
  228. iobuflen = ospf6_iobuf_size (ifp->mtu6);
  229. if (oi->ifmtu > iobuflen)
  230. {
  231. zlog_info ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  232. ifp->name, iobuflen);
  233. oi->ifmtu = iobuflen;
  234. }
  235. /* interface start */
  236. if (oi->area)
  237. thread_add_event (master, interface_up, oi, 0);
  238. }
  239. void
  240. ospf6_interface_if_del (struct interface *ifp)
  241. {
  242. struct ospf6_interface *oi;
  243. oi = (struct ospf6_interface *) ifp->info;
  244. if (oi == NULL)
  245. return;
  246. /* interface stop */
  247. if (oi->area)
  248. thread_execute (master, interface_down, oi, 0);
  249. listnode_delete (oi->area->if_list, oi);
  250. oi->area = (struct ospf6_area *) NULL;
  251. /* cut link */
  252. oi->interface = NULL;
  253. ifp->info = NULL;
  254. ospf6_interface_delete (oi);
  255. }
  256. void
  257. ospf6_interface_state_update (struct interface *ifp)
  258. {
  259. struct ospf6_interface *oi;
  260. oi = (struct ospf6_interface *) ifp->info;
  261. if (oi == NULL)
  262. return;
  263. if (oi->area == NULL)
  264. return;
  265. if (if_is_up (ifp))
  266. thread_add_event (master, interface_up, oi, 0);
  267. else
  268. thread_add_event (master, interface_down, oi, 0);
  269. return;
  270. }
  271. void
  272. ospf6_interface_connected_route_update (struct interface *ifp)
  273. {
  274. struct ospf6_interface *oi;
  275. struct ospf6_route *route;
  276. struct connected *c;
  277. listnode i;
  278. oi = (struct ospf6_interface *) ifp->info;
  279. if (oi == NULL)
  280. return;
  281. /* reset linklocal pointer */
  282. oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
  283. /* if area is null, do not make connected-route list */
  284. if (oi->area == NULL)
  285. return;
  286. /* update "route to advertise" interface route table */
  287. ospf6_route_remove_all (oi->route_connected);
  288. for (i = listhead (oi->interface->connected); i; nextnode (i))
  289. {
  290. c = (struct connected *) getdata (i);
  291. if (c->address->family != AF_INET6)
  292. continue;
  293. CONTINUE_IF_ADDRESS_LINKLOCAL (c->address);
  294. CONTINUE_IF_ADDRESS_UNSPECIFIED (c->address);
  295. CONTINUE_IF_ADDRESS_LOOPBACK (c->address);
  296. CONTINUE_IF_ADDRESS_V4COMPAT (c->address);
  297. CONTINUE_IF_ADDRESS_V4MAPPED (c->address);
  298. /* apply filter */
  299. if (oi->plist_name)
  300. {
  301. struct prefix_list *plist;
  302. enum prefix_list_type ret;
  303. char buf[128];
  304. prefix2str (c->address, buf, sizeof (buf));
  305. plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
  306. ret = prefix_list_apply (plist, (void *) c->address);
  307. if (ret == PREFIX_DENY)
  308. {
  309. zlog_info ("%s on %s filtered by prefix-list %s ",
  310. buf, oi->interface->name, oi->plist_name);
  311. continue;
  312. }
  313. }
  314. route = ospf6_route_create ();
  315. memcpy (&route->prefix, c->address, sizeof (struct prefix));
  316. apply_mask (&route->prefix);
  317. route->type = OSPF6_DEST_TYPE_NETWORK;
  318. route->path.area_id = oi->area->area_id;
  319. route->path.type = OSPF6_PATH_TYPE_INTRA;
  320. route->path.cost = oi->cost;
  321. route->nexthop[0].ifindex = oi->interface->ifindex;
  322. inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
  323. ospf6_route_add (route, oi->route_connected);
  324. }
  325. /* create new Link-LSA */
  326. OSPF6_LINK_LSA_SCHEDULE (oi);
  327. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  328. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  329. }
  330. static void
  331. ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
  332. {
  333. u_char prev_state;
  334. prev_state = oi->state;
  335. oi->state = next_state;
  336. if (prev_state == next_state)
  337. return;
  338. /* log */
  339. if (IS_OSPF6_DEBUG_INTERFACE)
  340. {
  341. zlog_info ("Interface state change %s: %s -> %s", oi->interface->name,
  342. ospf6_interface_state_str[prev_state],
  343. ospf6_interface_state_str[next_state]);
  344. }
  345. if ((prev_state == OSPF6_INTERFACE_DR ||
  346. prev_state == OSPF6_INTERFACE_BDR) &&
  347. (next_state != OSPF6_INTERFACE_DR &&
  348. next_state != OSPF6_INTERFACE_BDR))
  349. ospf6_leave_alldrouters (oi->interface->ifindex);
  350. if ((prev_state != OSPF6_INTERFACE_DR &&
  351. prev_state != OSPF6_INTERFACE_BDR) &&
  352. (next_state == OSPF6_INTERFACE_DR ||
  353. next_state == OSPF6_INTERFACE_BDR))
  354. ospf6_join_alldrouters (oi->interface->ifindex);
  355. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  356. if (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. VNL);
  646. vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
  647. if (ifp->info == NULL)
  648. {
  649. vty_out (vty, " OSPF not enabled on this interface%s", VNL);
  650. return 0;
  651. }
  652. else
  653. oi = (struct ospf6_interface *) ifp->info;
  654. vty_out (vty, " Internet Address:%s", VNL);
  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. VNL);
  665. break;
  666. case AF_INET6:
  667. vty_out (vty, " inet6: %s%s", strbuf,
  668. VNL);
  669. break;
  670. default:
  671. vty_out (vty, " ??? : %s%s", strbuf,
  672. VNL);
  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->mtu6, VNL);
  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. VNL);
  684. }
  685. else
  686. vty_out (vty, " Not Attached to Area%s", VNL);
  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. VNL);
  691. vty_out (vty, " Timer intervals configured:%s", VNL);
  692. vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
  693. oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
  694. VNL);
  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, VNL);
  698. vty_out (vty, " Number of I/F scoped LSAs is %u%s",
  699. oi->lsdb->count, VNL);
  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. VNL);
  709. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  710. lsa = ospf6_lsdb_next (lsa))
  711. vty_out (vty, " %s%s", lsa->name, VNL);
  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. VNL);
  720. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  721. lsa = ospf6_lsdb_next (lsa))
  722. vty_out (vty, " %s%s", lsa->name, VNL);
  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. VNL);
  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], VNL);
  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], VNL);
  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->mtu6 != 0 && ifp->mtu6 < ifmtu)
  895. {
  896. vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
  897. ifp->name, ifp->mtu6, VNL);
  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, VNL);
  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 (no_ipv6_ospf6_ifmtu,
  924. no_ipv6_ospf6_ifmtu_cmd,
  925. "no ipv6 ospf6 ifmtu",
  926. NO_STR
  927. IP6_STR
  928. OSPF6_STR
  929. "Interface MTU\n"
  930. )
  931. {
  932. struct ospf6_interface *oi;
  933. struct interface *ifp;
  934. int iobuflen;
  935. listnode node;
  936. struct ospf6_neighbor *on;
  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. if (oi->ifmtu < ifp->mtu)
  944. {
  945. iobuflen = ospf6_iobuf_size (ifp->mtu);
  946. if (iobuflen < ifp->mtu)
  947. {
  948. vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
  949. ifp->name, iobuflen, VNL);
  950. oi->ifmtu = iobuflen;
  951. }
  952. else
  953. oi->ifmtu = ifp->mtu;
  954. }
  955. else
  956. oi->ifmtu = ifp->mtu;
  957. /* re-establish adjacencies */
  958. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  959. {
  960. on = (struct ospf6_neighbor *) getdata (node);
  961. THREAD_OFF (on->inactivity_timer);
  962. thread_execute (master, inactivity_timer, on, 0);
  963. }
  964. return CMD_SUCCESS;
  965. }
  966. DEFUN (ipv6_ospf6_cost,
  967. ipv6_ospf6_cost_cmd,
  968. "ipv6 ospf6 cost <1-65535>",
  969. IP6_STR
  970. OSPF6_STR
  971. "Interface cost\n"
  972. "Outgoing metric of this interface\n"
  973. )
  974. {
  975. struct ospf6_interface *oi;
  976. struct interface *ifp;
  977. ifp = (struct interface *) vty->index;
  978. assert (ifp);
  979. oi = (struct ospf6_interface *) ifp->info;
  980. if (oi == NULL)
  981. oi = ospf6_interface_create (ifp);
  982. assert (oi);
  983. if (oi->cost == strtol (argv[0], NULL, 10))
  984. return CMD_SUCCESS;
  985. oi->cost = strtol (argv[0], NULL, 10);
  986. /* update cost held in route_connected list in ospf6_interface */
  987. ospf6_interface_connected_route_update (oi->interface);
  988. /* execute LSA hooks */
  989. if (oi->area)
  990. {
  991. OSPF6_LINK_LSA_SCHEDULE (oi);
  992. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  993. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  994. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  995. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  996. }
  997. return CMD_SUCCESS;
  998. }
  999. DEFUN (ipv6_ospf6_hellointerval,
  1000. ipv6_ospf6_hellointerval_cmd,
  1001. "ipv6 ospf6 hello-interval <1-65535>",
  1002. IP6_STR
  1003. OSPF6_STR
  1004. "Interval time of Hello packets\n"
  1005. SECONDS_STR
  1006. )
  1007. {
  1008. struct ospf6_interface *oi;
  1009. struct interface *ifp;
  1010. ifp = (struct interface *) vty->index;
  1011. assert (ifp);
  1012. oi = (struct ospf6_interface *) ifp->info;
  1013. if (oi == NULL)
  1014. oi = ospf6_interface_create (ifp);
  1015. assert (oi);
  1016. oi->hello_interval = strtol (argv[0], NULL, 10);
  1017. return CMD_SUCCESS;
  1018. }
  1019. /* interface variable set command */
  1020. DEFUN (ipv6_ospf6_deadinterval,
  1021. ipv6_ospf6_deadinterval_cmd,
  1022. "ipv6 ospf6 dead-interval <1-65535>",
  1023. IP6_STR
  1024. OSPF6_STR
  1025. "Interval time after which a neighbor is declared down\n"
  1026. SECONDS_STR
  1027. )
  1028. {
  1029. struct ospf6_interface *oi;
  1030. struct interface *ifp;
  1031. ifp = (struct interface *) vty->index;
  1032. assert (ifp);
  1033. oi = (struct ospf6_interface *) ifp->info;
  1034. if (oi == NULL)
  1035. oi = ospf6_interface_create (ifp);
  1036. assert (oi);
  1037. oi->dead_interval = strtol (argv[0], NULL, 10);
  1038. return CMD_SUCCESS;
  1039. }
  1040. /* interface variable set command */
  1041. DEFUN (ipv6_ospf6_transmitdelay,
  1042. ipv6_ospf6_transmitdelay_cmd,
  1043. "ipv6 ospf6 transmit-delay <1-3600>",
  1044. IP6_STR
  1045. OSPF6_STR
  1046. "Transmit delay of this interface\n"
  1047. SECONDS_STR
  1048. )
  1049. {
  1050. struct ospf6_interface *oi;
  1051. struct interface *ifp;
  1052. ifp = (struct interface *) vty->index;
  1053. assert (ifp);
  1054. oi = (struct ospf6_interface *) ifp->info;
  1055. if (oi == NULL)
  1056. oi = ospf6_interface_create (ifp);
  1057. assert (oi);
  1058. oi->transdelay = strtol (argv[0], NULL, 10);
  1059. return CMD_SUCCESS;
  1060. }
  1061. /* interface variable set command */
  1062. DEFUN (ipv6_ospf6_retransmitinterval,
  1063. ipv6_ospf6_retransmitinterval_cmd,
  1064. "ipv6 ospf6 retransmit-interval <1-65535>",
  1065. IP6_STR
  1066. OSPF6_STR
  1067. "Time between retransmitting lost link state advertisements\n"
  1068. SECONDS_STR
  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->rxmt_interval = strtol (argv[0], NULL, 10);
  1080. return CMD_SUCCESS;
  1081. }
  1082. /* interface variable set command */
  1083. DEFUN (ipv6_ospf6_priority,
  1084. ipv6_ospf6_priority_cmd,
  1085. "ipv6 ospf6 priority <0-255>",
  1086. IP6_STR
  1087. OSPF6_STR
  1088. "Router priority\n"
  1089. "Priority value\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. oi->priority = strtol (argv[0], NULL, 10);
  1101. if (oi->area)
  1102. ospf6_interface_state_change (dr_election (oi), oi);
  1103. return CMD_SUCCESS;
  1104. }
  1105. DEFUN (ipv6_ospf6_instance,
  1106. ipv6_ospf6_instance_cmd,
  1107. "ipv6 ospf6 instance-id <0-255>",
  1108. IP6_STR
  1109. OSPF6_STR
  1110. "Instance ID for this interface\n"
  1111. "Instance ID value\n"
  1112. )
  1113. {
  1114. struct ospf6_interface *oi;
  1115. struct interface *ifp;
  1116. ifp = (struct interface *)vty->index;
  1117. assert (ifp);
  1118. oi = (struct ospf6_interface *)ifp->info;
  1119. if (oi == NULL)
  1120. oi = ospf6_interface_create (ifp);
  1121. assert (oi);
  1122. oi->instance_id = strtol (argv[0], NULL, 10);
  1123. return CMD_SUCCESS;
  1124. }
  1125. DEFUN (ipv6_ospf6_passive,
  1126. ipv6_ospf6_passive_cmd,
  1127. "ipv6 ospf6 passive",
  1128. IP6_STR
  1129. OSPF6_STR
  1130. "passive interface, No adjacency will be formed on this interface\n"
  1131. )
  1132. {
  1133. struct ospf6_interface *oi;
  1134. struct interface *ifp;
  1135. listnode node;
  1136. struct ospf6_neighbor *on;
  1137. ifp = (struct interface *) vty->index;
  1138. assert (ifp);
  1139. oi = (struct ospf6_interface *) ifp->info;
  1140. if (oi == NULL)
  1141. oi = ospf6_interface_create (ifp);
  1142. assert (oi);
  1143. SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1144. THREAD_OFF (oi->thread_send_hello);
  1145. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  1146. {
  1147. on = (struct ospf6_neighbor *) getdata (node);
  1148. THREAD_OFF (on->inactivity_timer);
  1149. thread_execute (master, inactivity_timer, on, 0);
  1150. }
  1151. return CMD_SUCCESS;
  1152. }
  1153. DEFUN (no_ipv6_ospf6_passive,
  1154. no_ipv6_ospf6_passive_cmd,
  1155. "no ipv6 ospf6 passive",
  1156. NO_STR
  1157. IP6_STR
  1158. OSPF6_STR
  1159. "passive interface: No Adjacency will be formed on this I/F\n"
  1160. )
  1161. {
  1162. struct ospf6_interface *oi;
  1163. struct interface *ifp;
  1164. ifp = (struct interface *) vty->index;
  1165. assert (ifp);
  1166. oi = (struct ospf6_interface *) ifp->info;
  1167. if (oi == NULL)
  1168. oi = ospf6_interface_create (ifp);
  1169. assert (oi);
  1170. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1171. THREAD_OFF (oi->thread_send_hello);
  1172. oi->thread_send_hello =
  1173. thread_add_event (master, ospf6_hello_send, oi, 0);
  1174. return CMD_SUCCESS;
  1175. }
  1176. DEFUN (ipv6_ospf6_advertise_prefix_list,
  1177. ipv6_ospf6_advertise_prefix_list_cmd,
  1178. "ipv6 ospf6 advertise prefix-list WORD",
  1179. IP6_STR
  1180. OSPF6_STR
  1181. "Advertising options\n"
  1182. "Filter prefix using prefix-list\n"
  1183. "Prefix list name\n"
  1184. )
  1185. {
  1186. struct ospf6_interface *oi;
  1187. struct interface *ifp;
  1188. ifp = (struct interface *) vty->index;
  1189. assert (ifp);
  1190. oi = (struct ospf6_interface *) ifp->info;
  1191. if (oi == NULL)
  1192. oi = ospf6_interface_create (ifp);
  1193. assert (oi);
  1194. if (oi->plist_name)
  1195. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1196. oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
  1197. ospf6_interface_connected_route_update (oi->interface);
  1198. OSPF6_LINK_LSA_SCHEDULE (oi);
  1199. if (oi->state == OSPF6_INTERFACE_DR)
  1200. {
  1201. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1202. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1203. }
  1204. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1205. return CMD_SUCCESS;
  1206. }
  1207. DEFUN (no_ipv6_ospf6_advertise_prefix_list,
  1208. no_ipv6_ospf6_advertise_prefix_list_cmd,
  1209. "no ipv6 ospf6 advertise prefix-list",
  1210. NO_STR
  1211. IP6_STR
  1212. OSPF6_STR
  1213. "Advertising options\n"
  1214. "Filter prefix using prefix-list\n"
  1215. )
  1216. {
  1217. struct ospf6_interface *oi;
  1218. struct interface *ifp;
  1219. ifp = (struct interface *) vty->index;
  1220. assert (ifp);
  1221. oi = (struct ospf6_interface *) ifp->info;
  1222. if (oi == NULL)
  1223. oi = ospf6_interface_create (ifp);
  1224. assert (oi);
  1225. if (oi->plist_name)
  1226. {
  1227. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1228. oi->plist_name = NULL;
  1229. }
  1230. ospf6_interface_connected_route_update (oi->interface);
  1231. OSPF6_LINK_LSA_SCHEDULE (oi);
  1232. if (oi->state == OSPF6_INTERFACE_DR)
  1233. {
  1234. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1235. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1236. }
  1237. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1238. return CMD_SUCCESS;
  1239. }
  1240. int
  1241. config_write_ospf6_interface (struct vty *vty)
  1242. {
  1243. listnode i;
  1244. struct ospf6_interface *oi;
  1245. struct interface *ifp;
  1246. for (i = listhead (iflist); i; nextnode (i))
  1247. {
  1248. ifp = (struct interface *) getdata (i);
  1249. oi = (struct ospf6_interface *) ifp->info;
  1250. if (oi == NULL)
  1251. continue;
  1252. vty_out (vty, "interface %s%s",
  1253. oi->interface->name, VNL);
  1254. if (ifp->desc)
  1255. vty_out (vty, " description %s%s", ifp->desc, VNL);
  1256. if (ifp->mtu6 != oi->ifmtu)
  1257. vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
  1258. vty_out (vty, " ipv6 ospf6 cost %d%s",
  1259. oi->cost, VNL);
  1260. vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
  1261. oi->hello_interval, VNL);
  1262. vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
  1263. oi->dead_interval, VNL);
  1264. vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
  1265. oi->rxmt_interval, VNL);
  1266. vty_out (vty, " ipv6 ospf6 priority %d%s",
  1267. oi->priority, VNL);
  1268. vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
  1269. oi->transdelay, VNL);
  1270. vty_out (vty, " ipv6 ospf6 instance-id %d%s",
  1271. oi->instance_id, VNL);
  1272. if (oi->plist_name)
  1273. vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
  1274. oi->plist_name, VNL);
  1275. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1276. vty_out (vty, " ipv6 ospf6 passive%s", VNL);
  1277. vty_out (vty, "!%s", VNL);
  1278. }
  1279. return 0;
  1280. }
  1281. struct cmd_node interface_node =
  1282. {
  1283. INTERFACE_NODE,
  1284. "%s(config-if)# ",
  1285. };
  1286. void
  1287. ospf6_interface_init ()
  1288. {
  1289. /* Install interface node. */
  1290. install_node (&interface_node, config_write_ospf6_interface);
  1291. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
  1292. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1293. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1294. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1295. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1296. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1297. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1298. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1299. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
  1300. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1301. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1302. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1303. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1304. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1305. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1306. install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1307. install_element (CONFIG_NODE, &interface_cmd);
  1308. install_default (INTERFACE_NODE);
  1309. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1310. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1311. install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
  1312. install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
  1313. install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
  1314. install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
  1315. install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
  1316. install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
  1317. install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
  1318. install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
  1319. install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
  1320. install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
  1321. install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
  1322. install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
  1323. install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
  1324. }
  1325. DEFUN (debug_ospf6_interface,
  1326. debug_ospf6_interface_cmd,
  1327. "debug ospf6 interface",
  1328. DEBUG_STR
  1329. OSPF6_STR
  1330. "Debug OSPFv3 Interface\n"
  1331. )
  1332. {
  1333. OSPF6_DEBUG_INTERFACE_ON ();
  1334. return CMD_SUCCESS;
  1335. }
  1336. DEFUN (no_debug_ospf6_interface,
  1337. no_debug_ospf6_interface_cmd,
  1338. "no debug ospf6 interface",
  1339. NO_STR
  1340. DEBUG_STR
  1341. OSPF6_STR
  1342. "Debug OSPFv3 Interface\n"
  1343. )
  1344. {
  1345. OSPF6_DEBUG_INTERFACE_ON ();
  1346. return CMD_SUCCESS;
  1347. }
  1348. int
  1349. config_write_ospf6_debug_interface (struct vty *vty)
  1350. {
  1351. if (IS_OSPF6_DEBUG_INTERFACE)
  1352. vty_out (vty, "debug ospf6 interface%s", VNL);
  1353. return 0;
  1354. }
  1355. void
  1356. install_element_ospf6_debug_interface ()
  1357. {
  1358. install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
  1359. install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
  1360. install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
  1361. install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
  1362. }