ospf6_interface.c 42 KB

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