ospf6_interface.c 43 KB

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