ospf6_interface.c 44 KB

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