ospf6_interface.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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 "ospf6_snmp.h"
  41. #include "ospf6d.h"
  42. unsigned char conf_debug_ospf6_interface = 0;
  43. const char *ospf6_interface_state_str[] =
  44. {
  45. "None",
  46. "Down",
  47. "Loopback",
  48. "Waiting",
  49. "PointToPoint",
  50. "DROther",
  51. "BDR",
  52. "DR",
  53. NULL
  54. };
  55. struct ospf6_interface *
  56. ospf6_interface_lookup_by_ifindex (ifindex_t ifindex)
  57. {
  58. struct ospf6_interface *oi;
  59. struct interface *ifp;
  60. ifp = if_lookup_by_index (ifindex);
  61. if (ifp == NULL)
  62. return (struct ospf6_interface *) NULL;
  63. oi = (struct ospf6_interface *) ifp->info;
  64. return oi;
  65. }
  66. /* schedule routing table recalculation */
  67. static void
  68. ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa, unsigned int reason)
  69. {
  70. struct ospf6_interface *oi;
  71. if (lsa == NULL)
  72. return;
  73. oi = lsa->lsdb->data;
  74. switch (ntohs (lsa->header->type))
  75. {
  76. case OSPF6_LSTYPE_LINK:
  77. if (oi->state == OSPF6_INTERFACE_DR)
  78. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  79. ospf6_spf_schedule (oi->area->ospf6, reason);
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. static void
  86. ospf6_interface_lsdb_hook_add (struct ospf6_lsa *lsa)
  87. {
  88. ospf6_interface_lsdb_hook(lsa, ospf6_lsadd_to_spf_reason(lsa));
  89. }
  90. static void
  91. ospf6_interface_lsdb_hook_remove (struct ospf6_lsa *lsa)
  92. {
  93. ospf6_interface_lsdb_hook(lsa, ospf6_lsremove_to_spf_reason(lsa));
  94. }
  95. static u_char
  96. ospf6_default_iftype(struct interface *ifp)
  97. {
  98. if (if_is_pointopoint (ifp))
  99. return OSPF_IFTYPE_POINTOPOINT;
  100. else if (if_is_loopback (ifp))
  101. return OSPF_IFTYPE_LOOPBACK;
  102. else
  103. return OSPF_IFTYPE_BROADCAST;
  104. }
  105. static u_int32_t
  106. ospf6_interface_get_cost (struct ospf6_interface *oi)
  107. {
  108. /* If all else fails, use default OSPF cost */
  109. u_int32_t cost;
  110. u_int32_t bw, refbw;
  111. bw = oi->interface->bandwidth ? oi->interface->bandwidth : OSPF6_INTERFACE_BANDWIDTH;
  112. refbw = ospf6 ? ospf6->ref_bandwidth : OSPF6_REFERENCE_BANDWIDTH;
  113. /* A specifed ip ospf cost overrides a calculated one. */
  114. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST))
  115. cost = oi->cost;
  116. else
  117. {
  118. cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
  119. if (cost < 1) cost = 1;
  120. else if (cost > UINT32_MAX) cost = UINT32_MAX;
  121. }
  122. return cost;
  123. }
  124. static void
  125. ospf6_interface_recalculate_cost (struct ospf6_interface *oi)
  126. {
  127. u_int32_t newcost;
  128. newcost = ospf6_interface_get_cost (oi);
  129. if (newcost == oi->cost) return;
  130. oi->cost = newcost;
  131. /* update cost held in route_connected list in ospf6_interface */
  132. ospf6_interface_connected_route_update (oi->interface);
  133. /* execute LSA hooks */
  134. if (oi->area)
  135. {
  136. OSPF6_LINK_LSA_SCHEDULE (oi);
  137. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  138. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  139. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  140. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  141. }
  142. }
  143. /* Create new ospf6 interface structure */
  144. struct ospf6_interface *
  145. ospf6_interface_create (struct interface *ifp)
  146. {
  147. struct ospf6_interface *oi;
  148. unsigned int iobuflen;
  149. oi = (struct ospf6_interface *)
  150. XCALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
  151. if (!oi)
  152. {
  153. zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
  154. return (struct ospf6_interface *) NULL;
  155. }
  156. oi->area = (struct ospf6_area *) NULL;
  157. oi->neighbor_list = list_new ();
  158. oi->neighbor_list->cmp = ospf6_neighbor_cmp;
  159. oi->linklocal_addr = (struct in6_addr *) NULL;
  160. oi->instance_id = OSPF6_INTERFACE_INSTANCE_ID;
  161. oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
  162. oi->priority = OSPF6_INTERFACE_PRIORITY;
  163. oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
  164. oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
  165. oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
  166. oi->type = ospf6_default_iftype (ifp);
  167. oi->state = OSPF6_INTERFACE_DOWN;
  168. oi->flag = 0;
  169. oi->mtu_ignore = 0;
  170. /* Try to adjust I/O buffer size with IfMtu */
  171. oi->ifmtu = ifp->mtu6;
  172. iobuflen = ospf6_iobuf_size (ifp->mtu6);
  173. if (oi->ifmtu > iobuflen)
  174. {
  175. if (IS_OSPF6_DEBUG_INTERFACE)
  176. zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  177. ifp->name, iobuflen);
  178. oi->ifmtu = iobuflen;
  179. }
  180. oi->lsupdate_list = ospf6_lsdb_create (oi);
  181. oi->lsack_list = ospf6_lsdb_create (oi);
  182. oi->lsdb = ospf6_lsdb_create (oi);
  183. oi->lsdb->hook_add = ospf6_interface_lsdb_hook_add;
  184. oi->lsdb->hook_remove = ospf6_interface_lsdb_hook_remove;
  185. oi->lsdb_self = ospf6_lsdb_create (oi);
  186. oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
  187. oi->route_connected->scope = oi;
  188. /* link both */
  189. oi->interface = ifp;
  190. ifp->info = oi;
  191. /* Compute cost. */
  192. oi->cost = ospf6_interface_get_cost(oi);
  193. return oi;
  194. }
  195. void
  196. ospf6_interface_delete (struct ospf6_interface *oi)
  197. {
  198. struct listnode *node, *nnode;
  199. struct ospf6_neighbor *on;
  200. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  201. ospf6_neighbor_delete (on);
  202. list_delete (oi->neighbor_list);
  203. THREAD_OFF (oi->thread_send_hello);
  204. THREAD_OFF (oi->thread_send_lsupdate);
  205. THREAD_OFF (oi->thread_send_lsack);
  206. ospf6_lsdb_remove_all (oi->lsdb);
  207. ospf6_lsdb_remove_all (oi->lsupdate_list);
  208. ospf6_lsdb_remove_all (oi->lsack_list);
  209. ospf6_lsdb_delete (oi->lsdb);
  210. ospf6_lsdb_delete (oi->lsdb_self);
  211. ospf6_lsdb_delete (oi->lsupdate_list);
  212. ospf6_lsdb_delete (oi->lsack_list);
  213. ospf6_route_table_delete (oi->route_connected);
  214. /* cut link */
  215. oi->interface->info = NULL;
  216. /* plist_name */
  217. if (oi->plist_name)
  218. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  219. XFREE (MTYPE_OSPF6_IF, oi);
  220. }
  221. void
  222. ospf6_interface_enable (struct ospf6_interface *oi)
  223. {
  224. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
  225. ospf6_interface_state_update (oi->interface);
  226. }
  227. void
  228. ospf6_interface_disable (struct ospf6_interface *oi)
  229. {
  230. SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
  231. thread_execute (master, interface_down, oi, 0);
  232. ospf6_lsdb_remove_all (oi->lsdb);
  233. ospf6_lsdb_remove_all (oi->lsdb_self);
  234. ospf6_lsdb_remove_all (oi->lsupdate_list);
  235. ospf6_lsdb_remove_all (oi->lsack_list);
  236. THREAD_OFF (oi->thread_send_hello);
  237. THREAD_OFF (oi->thread_send_lsupdate);
  238. THREAD_OFF (oi->thread_send_lsack);
  239. THREAD_OFF (oi->thread_network_lsa);
  240. THREAD_OFF (oi->thread_link_lsa);
  241. THREAD_OFF (oi->thread_intra_prefix_lsa);
  242. }
  243. static struct in6_addr *
  244. ospf6_interface_get_linklocal_address (struct interface *ifp)
  245. {
  246. struct listnode *n;
  247. struct connected *c;
  248. struct in6_addr *l = (struct in6_addr *) NULL;
  249. /* for each connected address */
  250. for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
  251. {
  252. /* if family not AF_INET6, ignore */
  253. if (c->address->family != AF_INET6)
  254. continue;
  255. /* linklocal scope check */
  256. if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
  257. l = &c->address->u.prefix6;
  258. }
  259. return l;
  260. }
  261. void
  262. ospf6_interface_if_add (struct interface *ifp)
  263. {
  264. struct ospf6_interface *oi;
  265. unsigned int iobuflen;
  266. oi = (struct ospf6_interface *) ifp->info;
  267. if (oi == NULL)
  268. return;
  269. /* Try to adjust I/O buffer size with IfMtu */
  270. if (oi->ifmtu == 0)
  271. oi->ifmtu = ifp->mtu6;
  272. iobuflen = ospf6_iobuf_size (ifp->mtu6);
  273. if (oi->ifmtu > iobuflen)
  274. {
  275. if (IS_OSPF6_DEBUG_INTERFACE)
  276. zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
  277. ifp->name, iobuflen);
  278. oi->ifmtu = iobuflen;
  279. }
  280. /* interface start */
  281. ospf6_interface_state_update(oi->interface);
  282. }
  283. void
  284. ospf6_interface_state_update (struct interface *ifp)
  285. {
  286. struct ospf6_interface *oi;
  287. oi = (struct ospf6_interface *) ifp->info;
  288. if (oi == NULL)
  289. return;
  290. if (oi->area == NULL)
  291. return;
  292. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
  293. return;
  294. if (if_is_operative (ifp)
  295. && (ospf6_interface_get_linklocal_address(oi->interface)
  296. || if_is_loopback(oi->interface)))
  297. thread_add_event (master, interface_up, oi, 0);
  298. else
  299. thread_add_event (master, interface_down, oi, 0);
  300. return;
  301. }
  302. void
  303. ospf6_interface_connected_route_update (struct interface *ifp)
  304. {
  305. struct ospf6_interface *oi;
  306. struct ospf6_route *route;
  307. struct connected *c;
  308. struct listnode *node, *nnode;
  309. oi = (struct ospf6_interface *) ifp->info;
  310. if (oi == NULL)
  311. return;
  312. /* reset linklocal pointer */
  313. oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
  314. /* if area is null, do not make connected-route list */
  315. if (oi->area == NULL)
  316. return;
  317. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
  318. return;
  319. /* update "route to advertise" interface route table */
  320. ospf6_route_remove_all (oi->route_connected);
  321. for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
  322. {
  323. if (c->address->family != AF_INET6)
  324. continue;
  325. CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
  326. CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
  327. CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
  328. CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
  329. CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
  330. /* apply filter */
  331. if (oi->plist_name)
  332. {
  333. struct prefix_list *plist;
  334. enum prefix_list_type ret;
  335. char buf[128];
  336. prefix2str (c->address, buf, sizeof (buf));
  337. plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
  338. ret = prefix_list_apply (plist, (void *) c->address);
  339. if (ret == PREFIX_DENY)
  340. {
  341. if (IS_OSPF6_DEBUG_INTERFACE)
  342. zlog_debug ("%s on %s filtered by prefix-list %s ",
  343. buf, oi->interface->name, oi->plist_name);
  344. continue;
  345. }
  346. }
  347. route = ospf6_route_create ();
  348. memcpy (&route->prefix, c->address, sizeof (struct prefix));
  349. apply_mask (&route->prefix);
  350. route->type = OSPF6_DEST_TYPE_NETWORK;
  351. route->path.area_id = oi->area->area_id;
  352. route->path.type = OSPF6_PATH_TYPE_INTRA;
  353. route->path.cost = oi->cost;
  354. route->nexthop[0].ifindex = oi->interface->ifindex;
  355. inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
  356. ospf6_route_add (route, oi->route_connected);
  357. }
  358. /* create new Link-LSA */
  359. OSPF6_LINK_LSA_SCHEDULE (oi);
  360. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  361. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  362. }
  363. static void
  364. ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
  365. {
  366. u_char prev_state;
  367. prev_state = oi->state;
  368. oi->state = next_state;
  369. if (prev_state == next_state)
  370. return;
  371. /* log */
  372. if (IS_OSPF6_DEBUG_INTERFACE)
  373. {
  374. zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
  375. ospf6_interface_state_str[prev_state],
  376. ospf6_interface_state_str[next_state]);
  377. }
  378. oi->state_change++;
  379. if ((prev_state == OSPF6_INTERFACE_DR ||
  380. prev_state == OSPF6_INTERFACE_BDR) &&
  381. (next_state != OSPF6_INTERFACE_DR &&
  382. next_state != OSPF6_INTERFACE_BDR))
  383. ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP);
  384. if ((prev_state != OSPF6_INTERFACE_DR &&
  385. prev_state != OSPF6_INTERFACE_BDR) &&
  386. (next_state == OSPF6_INTERFACE_DR ||
  387. next_state == OSPF6_INTERFACE_BDR))
  388. ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP);
  389. OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
  390. if (next_state == OSPF6_INTERFACE_DOWN)
  391. {
  392. OSPF6_NETWORK_LSA_EXECUTE (oi);
  393. OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
  394. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  395. }
  396. else if (prev_state == OSPF6_INTERFACE_DR ||
  397. next_state == OSPF6_INTERFACE_DR)
  398. {
  399. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  400. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  401. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  402. }
  403. #ifdef HAVE_SNMP
  404. /* Terminal state or regression */
  405. if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
  406. (next_state == OSPF6_INTERFACE_DROTHER) ||
  407. (next_state == OSPF6_INTERFACE_BDR) ||
  408. (next_state == OSPF6_INTERFACE_DR) ||
  409. (next_state < prev_state))
  410. ospf6TrapIfStateChange (oi);
  411. #endif
  412. }
  413. /* DR Election, RFC2328 section 9.4 */
  414. #define IS_ELIGIBLE(n) \
  415. ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
  416. static struct ospf6_neighbor *
  417. better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  418. {
  419. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
  420. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
  421. return NULL;
  422. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
  423. return b;
  424. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
  425. return a;
  426. if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
  427. return a;
  428. if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
  429. return b;
  430. if (a->priority > b->priority)
  431. return a;
  432. if (a->priority < b->priority)
  433. return b;
  434. if (ntohl (a->router_id) > ntohl (b->router_id))
  435. return a;
  436. if (ntohl (a->router_id) < ntohl (b->router_id))
  437. return b;
  438. zlog_warn ("Router-ID duplicate ?");
  439. return a;
  440. }
  441. static struct ospf6_neighbor *
  442. better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
  443. {
  444. if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
  445. (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
  446. return NULL;
  447. else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
  448. return b;
  449. else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
  450. return a;
  451. if (a->drouter == a->router_id && b->drouter != b->router_id)
  452. return a;
  453. if (a->drouter != a->router_id && b->drouter == b->router_id)
  454. return b;
  455. if (a->priority > b->priority)
  456. return a;
  457. if (a->priority < b->priority)
  458. return b;
  459. if (ntohl (a->router_id) > ntohl (b->router_id))
  460. return a;
  461. if (ntohl (a->router_id) < ntohl (b->router_id))
  462. return b;
  463. zlog_warn ("Router-ID duplicate ?");
  464. return a;
  465. }
  466. static u_char
  467. dr_election (struct ospf6_interface *oi)
  468. {
  469. struct listnode *node, *nnode;
  470. struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
  471. struct ospf6_neighbor *best_drouter, *best_bdrouter;
  472. u_char next_state = 0;
  473. drouter = bdrouter = NULL;
  474. best_drouter = best_bdrouter = NULL;
  475. /* pseudo neighbor myself, including noting current DR/BDR (1) */
  476. memset (&myself, 0, sizeof (myself));
  477. inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
  478. sizeof (myself.name));
  479. myself.state = OSPF6_NEIGHBOR_TWOWAY;
  480. myself.drouter = oi->drouter;
  481. myself.bdrouter = oi->bdrouter;
  482. myself.priority = oi->priority;
  483. myself.router_id = oi->area->ospf6->router_id;
  484. /* Electing BDR (2) */
  485. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  486. bdrouter = better_bdrouter (bdrouter, on);
  487. best_bdrouter = bdrouter;
  488. bdrouter = better_bdrouter (best_bdrouter, &myself);
  489. /* Electing DR (3) */
  490. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  491. drouter = better_drouter (drouter, on);
  492. best_drouter = drouter;
  493. drouter = better_drouter (best_drouter, &myself);
  494. if (drouter == NULL)
  495. drouter = bdrouter;
  496. /* the router itself is newly/no longer DR/BDR (4) */
  497. if ((drouter == &myself && myself.drouter != myself.router_id) ||
  498. (drouter != &myself && myself.drouter == myself.router_id) ||
  499. (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
  500. (bdrouter != &myself && myself.bdrouter == myself.router_id))
  501. {
  502. myself.drouter = (drouter ? drouter->router_id : htonl (0));
  503. myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  504. /* compatible to Electing BDR (2) */
  505. bdrouter = better_bdrouter (best_bdrouter, &myself);
  506. /* compatible to Electing DR (3) */
  507. drouter = better_drouter (best_drouter, &myself);
  508. if (drouter == NULL)
  509. drouter = bdrouter;
  510. }
  511. /* Set interface state accordingly (5) */
  512. if (drouter && drouter == &myself)
  513. next_state = OSPF6_INTERFACE_DR;
  514. else if (bdrouter && bdrouter == &myself)
  515. next_state = OSPF6_INTERFACE_BDR;
  516. else
  517. next_state = OSPF6_INTERFACE_DROTHER;
  518. /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
  519. /* XXX */
  520. /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
  521. /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
  522. accordingly after AdjOK */
  523. if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
  524. oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
  525. {
  526. if (IS_OSPF6_DEBUG_INTERFACE)
  527. zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
  528. (drouter ? drouter->name : "0.0.0.0"),
  529. (bdrouter ? bdrouter->name : "0.0.0.0"));
  530. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
  531. {
  532. if (on->state < OSPF6_NEIGHBOR_TWOWAY)
  533. continue;
  534. /* Schedule AdjOK. */
  535. thread_add_event (master, adj_ok, on, 0);
  536. }
  537. }
  538. oi->drouter = (drouter ? drouter->router_id : htonl (0));
  539. oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
  540. return next_state;
  541. }
  542. /* Interface State Machine */
  543. int
  544. interface_up (struct thread *thread)
  545. {
  546. struct ospf6_interface *oi;
  547. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  548. assert (oi && oi->interface);
  549. if (IS_OSPF6_DEBUG_INTERFACE)
  550. zlog_debug ("Interface Event %s: [InterfaceUp]",
  551. oi->interface->name);
  552. /* check physical interface is up */
  553. if (! if_is_operative (oi->interface))
  554. {
  555. if (IS_OSPF6_DEBUG_INTERFACE)
  556. zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
  557. oi->interface->name);
  558. return 0;
  559. }
  560. /* check interface has a link-local address */
  561. if (! (ospf6_interface_get_linklocal_address(oi->interface)
  562. || if_is_loopback(oi->interface)))
  563. {
  564. if (IS_OSPF6_DEBUG_INTERFACE)
  565. zlog_debug ("Interface %s has no link local address, can't execute [InterfaceUp]",
  566. oi->interface->name);
  567. return 0;
  568. }
  569. /* Recompute cost */
  570. ospf6_interface_recalculate_cost (oi);
  571. /* if already enabled, do nothing */
  572. if (oi->state > OSPF6_INTERFACE_DOWN)
  573. {
  574. if (IS_OSPF6_DEBUG_INTERFACE)
  575. zlog_debug ("Interface %s already enabled",
  576. oi->interface->name);
  577. return 0;
  578. }
  579. /* If no area assigned, return */
  580. if (oi->area == NULL)
  581. {
  582. zlog_debug ("%s: Not scheduleing Hello for %s as there is no area assigned yet", __func__,
  583. oi->interface->name);
  584. return 0;
  585. }
  586. /* Join AllSPFRouters */
  587. if (ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP) < 0)
  588. {
  589. if (oi->sso_try_cnt++ < OSPF6_INTERFACE_SSO_RETRY_MAX)
  590. {
  591. zlog_info("Scheduling %s for sso retry, trial count: %d",
  592. oi->interface->name, oi->sso_try_cnt);
  593. thread_add_timer (master, interface_up, oi,
  594. OSPF6_INTERFACE_SSO_RETRY_INT);
  595. }
  596. return 0;
  597. }
  598. oi->sso_try_cnt = 0; /* Reset on success */
  599. /* Update interface route */
  600. ospf6_interface_connected_route_update (oi->interface);
  601. /* Schedule Hello */
  602. if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  603. oi->thread_send_hello = thread_add_event (master, ospf6_hello_send, oi, 0);
  604. /* decide next interface state */
  605. if ((if_is_pointopoint (oi->interface)) ||
  606. (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
  607. ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
  608. }
  609. else if (oi->priority == 0)
  610. ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
  611. else
  612. {
  613. ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
  614. thread_add_timer (master, wait_timer, oi, oi->dead_interval);
  615. }
  616. return 0;
  617. }
  618. int
  619. wait_timer (struct thread *thread)
  620. {
  621. struct ospf6_interface *oi;
  622. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  623. assert (oi && oi->interface);
  624. if (IS_OSPF6_DEBUG_INTERFACE)
  625. zlog_debug ("Interface Event %s: [WaitTimer]",
  626. oi->interface->name);
  627. if (oi->state == OSPF6_INTERFACE_WAITING)
  628. ospf6_interface_state_change (dr_election (oi), oi);
  629. return 0;
  630. }
  631. int
  632. backup_seen (struct thread *thread)
  633. {
  634. struct ospf6_interface *oi;
  635. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  636. assert (oi && oi->interface);
  637. if (IS_OSPF6_DEBUG_INTERFACE)
  638. zlog_debug ("Interface Event %s: [BackupSeen]",
  639. oi->interface->name);
  640. if (oi->state == OSPF6_INTERFACE_WAITING)
  641. ospf6_interface_state_change (dr_election (oi), oi);
  642. return 0;
  643. }
  644. int
  645. neighbor_change (struct thread *thread)
  646. {
  647. struct ospf6_interface *oi;
  648. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  649. assert (oi && oi->interface);
  650. if (IS_OSPF6_DEBUG_INTERFACE)
  651. zlog_debug ("Interface Event %s: [NeighborChange]",
  652. oi->interface->name);
  653. if (oi->state == OSPF6_INTERFACE_DROTHER ||
  654. oi->state == OSPF6_INTERFACE_BDR ||
  655. oi->state == OSPF6_INTERFACE_DR)
  656. ospf6_interface_state_change (dr_election (oi), oi);
  657. return 0;
  658. }
  659. int
  660. interface_down (struct thread *thread)
  661. {
  662. struct ospf6_interface *oi;
  663. struct listnode *node, *nnode;
  664. struct ospf6_neighbor *on;
  665. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  666. assert (oi && oi->interface);
  667. if (IS_OSPF6_DEBUG_INTERFACE)
  668. zlog_debug ("Interface Event %s: [InterfaceDown]",
  669. oi->interface->name);
  670. /* Stop Hellos */
  671. THREAD_OFF (oi->thread_send_hello);
  672. /* Leave AllSPFRouters */
  673. if (oi->state > OSPF6_INTERFACE_DOWN)
  674. ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_LEAVE_GROUP);
  675. ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
  676. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  677. ospf6_neighbor_delete (on);
  678. list_delete_all_node (oi->neighbor_list);
  679. /* When interface state is reset, also reset information about
  680. * DR election, as it is no longer valid. */
  681. oi->drouter = oi->prev_drouter = htonl(0);
  682. oi->bdrouter = oi->prev_bdrouter = htonl(0);
  683. return 0;
  684. }
  685. /* show specified interface structure */
  686. static int
  687. ospf6_interface_show (struct vty *vty, struct interface *ifp)
  688. {
  689. struct ospf6_interface *oi;
  690. struct connected *c;
  691. struct prefix *p;
  692. struct listnode *i;
  693. char strbuf[64], drouter[32], bdrouter[32];
  694. const char *updown[3] = {"down", "up", NULL};
  695. const char *type;
  696. struct timeval res, now;
  697. char duration[32];
  698. struct ospf6_lsa *lsa;
  699. /* check physical interface type */
  700. if (if_is_loopback (ifp))
  701. type = "LOOPBACK";
  702. else if (if_is_broadcast (ifp))
  703. type = "BROADCAST";
  704. else if (if_is_pointopoint (ifp))
  705. type = "POINTOPOINT";
  706. else
  707. type = "UNKNOWN";
  708. vty_out (vty, "%s is %s, type %s%s",
  709. ifp->name, updown[if_is_operative (ifp)], type,
  710. VNL);
  711. vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
  712. if (ifp->info == NULL)
  713. {
  714. vty_out (vty, " OSPF not enabled on this interface%s", VNL);
  715. return 0;
  716. }
  717. else
  718. oi = (struct ospf6_interface *) ifp->info;
  719. vty_out (vty, " Internet Address:%s", VNL);
  720. for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
  721. {
  722. p = c->address;
  723. prefix2str (p, strbuf, sizeof (strbuf));
  724. switch (p->family)
  725. {
  726. case AF_INET:
  727. vty_out (vty, " inet : %s%s", strbuf,
  728. VNL);
  729. break;
  730. case AF_INET6:
  731. vty_out (vty, " inet6: %s%s", strbuf,
  732. VNL);
  733. break;
  734. default:
  735. vty_out (vty, " ??? : %s%s", strbuf,
  736. VNL);
  737. break;
  738. }
  739. }
  740. if (oi->area)
  741. {
  742. vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
  743. oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
  744. vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ?
  745. "disabled" : "enabled", VNL);
  746. inet_ntop (AF_INET, &oi->area->area_id,
  747. strbuf, sizeof (strbuf));
  748. vty_out (vty, " Area ID %s, Cost %u%s", strbuf, oi->cost,
  749. VNL);
  750. }
  751. else
  752. vty_out (vty, " Not Attached to Area%s", VNL);
  753. vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
  754. ospf6_interface_state_str[oi->state],
  755. oi->transdelay, oi->priority,
  756. VNL);
  757. vty_out (vty, " Timer intervals configured:%s", VNL);
  758. vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
  759. oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
  760. VNL);
  761. inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
  762. inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
  763. vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
  764. vty_out (vty, " Number of I/F scoped LSAs is %u%s",
  765. oi->lsdb->count, VNL);
  766. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  767. timerclear (&res);
  768. if (oi->thread_send_lsupdate)
  769. timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
  770. timerstring (&res, duration, sizeof (duration));
  771. vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
  772. oi->lsupdate_list->count, duration,
  773. (oi->thread_send_lsupdate ? "on" : "off"),
  774. VNL);
  775. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  776. lsa = ospf6_lsdb_next (lsa))
  777. vty_out (vty, " %s%s", lsa->name, VNL);
  778. timerclear (&res);
  779. if (oi->thread_send_lsack)
  780. timersub (&oi->thread_send_lsack->u.sands, &now, &res);
  781. timerstring (&res, duration, sizeof (duration));
  782. vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
  783. oi->lsack_list->count, duration,
  784. (oi->thread_send_lsack ? "on" : "off"),
  785. VNL);
  786. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  787. lsa = ospf6_lsdb_next (lsa))
  788. vty_out (vty, " %s%s", lsa->name, VNL);
  789. return 0;
  790. }
  791. /* show interface */
  792. DEFUN (show_ipv6_ospf6_interface,
  793. show_ipv6_ospf6_interface_ifname_cmd,
  794. "show ipv6 ospf6 interface IFNAME",
  795. SHOW_STR
  796. IP6_STR
  797. OSPF6_STR
  798. INTERFACE_STR
  799. IFNAME_STR
  800. )
  801. {
  802. struct interface *ifp;
  803. struct listnode *i;
  804. if (argc)
  805. {
  806. ifp = if_lookup_by_name (argv[0]);
  807. if (ifp == NULL)
  808. {
  809. vty_out (vty, "No such Interface: %s%s", argv[0],
  810. VNL);
  811. return CMD_WARNING;
  812. }
  813. ospf6_interface_show (vty, ifp);
  814. }
  815. else
  816. {
  817. for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
  818. ospf6_interface_show (vty, ifp);
  819. }
  820. return CMD_SUCCESS;
  821. }
  822. ALIAS (show_ipv6_ospf6_interface,
  823. show_ipv6_ospf6_interface_cmd,
  824. "show ipv6 ospf6 interface",
  825. SHOW_STR
  826. IP6_STR
  827. OSPF6_STR
  828. INTERFACE_STR
  829. )
  830. DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
  831. show_ipv6_ospf6_interface_ifname_prefix_cmd,
  832. "show ipv6 ospf6 interface IFNAME prefix",
  833. SHOW_STR
  834. IP6_STR
  835. OSPF6_STR
  836. INTERFACE_STR
  837. IFNAME_STR
  838. "Display connected prefixes to advertise\n"
  839. )
  840. {
  841. struct interface *ifp;
  842. struct ospf6_interface *oi;
  843. ifp = if_lookup_by_name (argv[0]);
  844. if (ifp == NULL)
  845. {
  846. vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
  847. return CMD_WARNING;
  848. }
  849. oi = ifp->info;
  850. if (oi == NULL)
  851. {
  852. vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
  853. return CMD_WARNING;
  854. }
  855. argc--;
  856. argv++;
  857. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  858. return CMD_SUCCESS;
  859. }
  860. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  861. show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
  862. "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
  863. SHOW_STR
  864. IP6_STR
  865. OSPF6_STR
  866. INTERFACE_STR
  867. IFNAME_STR
  868. "Display connected prefixes to advertise\n"
  869. OSPF6_ROUTE_ADDRESS_STR
  870. OSPF6_ROUTE_PREFIX_STR
  871. "Display details of the prefixes\n"
  872. )
  873. ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
  874. show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
  875. "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
  876. SHOW_STR
  877. IP6_STR
  878. OSPF6_STR
  879. INTERFACE_STR
  880. IFNAME_STR
  881. "Display connected prefixes to advertise\n"
  882. OSPF6_ROUTE_PREFIX_STR
  883. OSPF6_ROUTE_MATCH_STR
  884. "Display details of the prefixes\n"
  885. )
  886. DEFUN (show_ipv6_ospf6_interface_prefix,
  887. show_ipv6_ospf6_interface_prefix_cmd,
  888. "show ipv6 ospf6 interface prefix",
  889. SHOW_STR
  890. IP6_STR
  891. OSPF6_STR
  892. INTERFACE_STR
  893. "Display connected prefixes to advertise\n"
  894. )
  895. {
  896. struct listnode *i;
  897. struct ospf6_interface *oi;
  898. struct interface *ifp;
  899. for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
  900. {
  901. oi = (struct ospf6_interface *) ifp->info;
  902. if (oi == NULL)
  903. continue;
  904. ospf6_route_table_show (vty, argc, argv, oi->route_connected);
  905. }
  906. return CMD_SUCCESS;
  907. }
  908. ALIAS (show_ipv6_ospf6_interface_prefix,
  909. show_ipv6_ospf6_interface_prefix_detail_cmd,
  910. "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
  911. SHOW_STR
  912. IP6_STR
  913. OSPF6_STR
  914. INTERFACE_STR
  915. "Display connected prefixes to advertise\n"
  916. OSPF6_ROUTE_ADDRESS_STR
  917. OSPF6_ROUTE_PREFIX_STR
  918. "Display details of the prefixes\n"
  919. )
  920. ALIAS (show_ipv6_ospf6_interface_prefix,
  921. show_ipv6_ospf6_interface_prefix_match_cmd,
  922. "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
  923. SHOW_STR
  924. IP6_STR
  925. OSPF6_STR
  926. INTERFACE_STR
  927. "Display connected prefixes to advertise\n"
  928. OSPF6_ROUTE_PREFIX_STR
  929. OSPF6_ROUTE_MATCH_STR
  930. "Display details of the prefixes\n"
  931. )
  932. /* interface variable set command */
  933. DEFUN (ipv6_ospf6_ifmtu,
  934. ipv6_ospf6_ifmtu_cmd,
  935. "ipv6 ospf6 ifmtu <1-65535>",
  936. IP6_STR
  937. OSPF6_STR
  938. "Interface MTU\n"
  939. "OSPFv3 Interface MTU\n"
  940. )
  941. {
  942. struct ospf6_interface *oi;
  943. struct interface *ifp;
  944. unsigned int ifmtu, iobuflen;
  945. struct listnode *node, *nnode;
  946. struct ospf6_neighbor *on;
  947. ifp = (struct interface *) vty->index;
  948. assert (ifp);
  949. oi = (struct ospf6_interface *) ifp->info;
  950. if (oi == NULL)
  951. oi = ospf6_interface_create (ifp);
  952. assert (oi);
  953. ifmtu = strtol (argv[0], NULL, 10);
  954. if (oi->ifmtu == ifmtu)
  955. return CMD_SUCCESS;
  956. if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
  957. {
  958. vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
  959. ifp->name, ifp->mtu6, VNL);
  960. return CMD_WARNING;
  961. }
  962. if (oi->ifmtu < ifmtu)
  963. {
  964. iobuflen = ospf6_iobuf_size (ifmtu);
  965. if (iobuflen < ifmtu)
  966. {
  967. vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
  968. ifp->name, iobuflen, VNL);
  969. oi->ifmtu = iobuflen;
  970. }
  971. else
  972. oi->ifmtu = ifmtu;
  973. }
  974. else
  975. oi->ifmtu = ifmtu;
  976. /* re-establish adjacencies */
  977. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  978. {
  979. THREAD_OFF (on->inactivity_timer);
  980. thread_add_event (master, inactivity_timer, on, 0);
  981. }
  982. return CMD_SUCCESS;
  983. }
  984. DEFUN (no_ipv6_ospf6_ifmtu,
  985. no_ipv6_ospf6_ifmtu_cmd,
  986. "no ipv6 ospf6 ifmtu",
  987. NO_STR
  988. IP6_STR
  989. OSPF6_STR
  990. "Interface MTU\n"
  991. )
  992. {
  993. struct ospf6_interface *oi;
  994. struct interface *ifp;
  995. unsigned int iobuflen;
  996. struct listnode *node, *nnode;
  997. struct ospf6_neighbor *on;
  998. ifp = (struct interface *) vty->index;
  999. assert (ifp);
  1000. oi = (struct ospf6_interface *) ifp->info;
  1001. if (oi == NULL)
  1002. oi = ospf6_interface_create (ifp);
  1003. assert (oi);
  1004. if (oi->ifmtu < ifp->mtu)
  1005. {
  1006. iobuflen = ospf6_iobuf_size (ifp->mtu);
  1007. if (iobuflen < ifp->mtu)
  1008. {
  1009. vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
  1010. ifp->name, iobuflen, VNL);
  1011. oi->ifmtu = iobuflen;
  1012. }
  1013. else
  1014. oi->ifmtu = ifp->mtu;
  1015. }
  1016. else
  1017. oi->ifmtu = ifp->mtu;
  1018. /* re-establish adjacencies */
  1019. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  1020. {
  1021. THREAD_OFF (on->inactivity_timer);
  1022. thread_add_event (master, inactivity_timer, on, 0);
  1023. }
  1024. return CMD_SUCCESS;
  1025. }
  1026. DEFUN (ipv6_ospf6_cost,
  1027. ipv6_ospf6_cost_cmd,
  1028. "ipv6 ospf6 cost <1-65535>",
  1029. IP6_STR
  1030. OSPF6_STR
  1031. "Interface cost\n"
  1032. "Outgoing metric of this interface\n"
  1033. )
  1034. {
  1035. struct ospf6_interface *oi;
  1036. struct interface *ifp;
  1037. unsigned long int lcost;
  1038. ifp = (struct interface *) vty->index;
  1039. assert (ifp);
  1040. oi = (struct ospf6_interface *) ifp->info;
  1041. if (oi == NULL)
  1042. oi = ospf6_interface_create (ifp);
  1043. assert (oi);
  1044. lcost = strtol (argv[0], NULL, 10);
  1045. if (lcost > UINT32_MAX)
  1046. {
  1047. vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
  1048. return CMD_WARNING;
  1049. }
  1050. if (oi->cost == lcost)
  1051. return CMD_SUCCESS;
  1052. oi->cost = lcost;
  1053. SET_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST);
  1054. ospf6_interface_recalculate_cost(oi);
  1055. return CMD_SUCCESS;
  1056. }
  1057. DEFUN (no_ipv6_ospf6_cost,
  1058. no_ipv6_ospf6_cost_cmd,
  1059. "no ipv6 ospf6 cost",
  1060. NO_STR
  1061. IP6_STR
  1062. OSPF6_STR
  1063. "Calculate interface cost from bandwidth\n"
  1064. )
  1065. {
  1066. struct ospf6_interface *oi;
  1067. struct interface *ifp;
  1068. ifp = (struct interface *) vty->index;
  1069. assert (ifp);
  1070. oi = (struct ospf6_interface *) ifp->info;
  1071. if (oi == NULL)
  1072. oi = ospf6_interface_create (ifp);
  1073. assert (oi);
  1074. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST);
  1075. ospf6_interface_recalculate_cost(oi);
  1076. return CMD_SUCCESS;
  1077. }
  1078. DEFUN (auto_cost_reference_bandwidth,
  1079. auto_cost_reference_bandwidth_cmd,
  1080. "auto-cost reference-bandwidth <1-4294967>",
  1081. "Calculate OSPF interface cost according to bandwidth\n"
  1082. "Use reference bandwidth method to assign OSPF cost\n"
  1083. "The reference bandwidth in terms of Mbits per second\n")
  1084. {
  1085. struct ospf6 *o = vty->index;
  1086. struct ospf6_area *oa;
  1087. struct ospf6_interface *oi;
  1088. struct listnode *i, *j;
  1089. u_int32_t refbw;
  1090. refbw = strtol (argv[0], NULL, 10);
  1091. if (refbw < 1 || refbw > 4294967)
  1092. {
  1093. vty_out (vty, "reference-bandwidth value is invalid%s", VTY_NEWLINE);
  1094. return CMD_WARNING;
  1095. }
  1096. /* If reference bandwidth is changed. */
  1097. if ((refbw * 1000) == o->ref_bandwidth)
  1098. return CMD_SUCCESS;
  1099. o->ref_bandwidth = refbw * 1000;
  1100. for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
  1101. for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
  1102. ospf6_interface_recalculate_cost (oi);
  1103. return CMD_SUCCESS;
  1104. }
  1105. DEFUN (no_auto_cost_reference_bandwidth,
  1106. no_auto_cost_reference_bandwidth_cmd,
  1107. "no auto-cost reference-bandwidth",
  1108. NO_STR
  1109. "Calculate OSPF interface cost according to bandwidth\n"
  1110. "Use reference bandwidth method to assign OSPF cost\n")
  1111. {
  1112. struct ospf6 *o = vty->index;
  1113. struct ospf6_area *oa;
  1114. struct ospf6_interface *oi;
  1115. struct listnode *i, *j;
  1116. if (o->ref_bandwidth == OSPF6_REFERENCE_BANDWIDTH)
  1117. return CMD_SUCCESS;
  1118. o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;
  1119. for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
  1120. for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
  1121. ospf6_interface_recalculate_cost (oi);
  1122. return CMD_SUCCESS;
  1123. }
  1124. DEFUN (ipv6_ospf6_hellointerval,
  1125. ipv6_ospf6_hellointerval_cmd,
  1126. "ipv6 ospf6 hello-interval <1-65535>",
  1127. IP6_STR
  1128. OSPF6_STR
  1129. "Interval time of Hello packets\n"
  1130. SECONDS_STR
  1131. )
  1132. {
  1133. struct ospf6_interface *oi;
  1134. struct interface *ifp;
  1135. ifp = (struct interface *) vty->index;
  1136. assert (ifp);
  1137. oi = (struct ospf6_interface *) ifp->info;
  1138. if (oi == NULL)
  1139. oi = ospf6_interface_create (ifp);
  1140. assert (oi);
  1141. oi->hello_interval = strtol (argv[0], NULL, 10);
  1142. return CMD_SUCCESS;
  1143. }
  1144. /* interface variable set command */
  1145. DEFUN (ipv6_ospf6_deadinterval,
  1146. ipv6_ospf6_deadinterval_cmd,
  1147. "ipv6 ospf6 dead-interval <1-65535>",
  1148. IP6_STR
  1149. OSPF6_STR
  1150. "Interval time after which a neighbor is declared down\n"
  1151. SECONDS_STR
  1152. )
  1153. {
  1154. struct ospf6_interface *oi;
  1155. struct interface *ifp;
  1156. ifp = (struct interface *) vty->index;
  1157. assert (ifp);
  1158. oi = (struct ospf6_interface *) ifp->info;
  1159. if (oi == NULL)
  1160. oi = ospf6_interface_create (ifp);
  1161. assert (oi);
  1162. oi->dead_interval = strtol (argv[0], NULL, 10);
  1163. return CMD_SUCCESS;
  1164. }
  1165. /* interface variable set command */
  1166. DEFUN (ipv6_ospf6_transmitdelay,
  1167. ipv6_ospf6_transmitdelay_cmd,
  1168. "ipv6 ospf6 transmit-delay <1-3600>",
  1169. IP6_STR
  1170. OSPF6_STR
  1171. "Transmit delay of this interface\n"
  1172. SECONDS_STR
  1173. )
  1174. {
  1175. struct ospf6_interface *oi;
  1176. struct interface *ifp;
  1177. ifp = (struct interface *) vty->index;
  1178. assert (ifp);
  1179. oi = (struct ospf6_interface *) ifp->info;
  1180. if (oi == NULL)
  1181. oi = ospf6_interface_create (ifp);
  1182. assert (oi);
  1183. oi->transdelay = strtol (argv[0], NULL, 10);
  1184. return CMD_SUCCESS;
  1185. }
  1186. /* interface variable set command */
  1187. DEFUN (ipv6_ospf6_retransmitinterval,
  1188. ipv6_ospf6_retransmitinterval_cmd,
  1189. "ipv6 ospf6 retransmit-interval <1-65535>",
  1190. IP6_STR
  1191. OSPF6_STR
  1192. "Time between retransmitting lost link state advertisements\n"
  1193. SECONDS_STR
  1194. )
  1195. {
  1196. struct ospf6_interface *oi;
  1197. struct interface *ifp;
  1198. ifp = (struct interface *) vty->index;
  1199. assert (ifp);
  1200. oi = (struct ospf6_interface *) ifp->info;
  1201. if (oi == NULL)
  1202. oi = ospf6_interface_create (ifp);
  1203. assert (oi);
  1204. oi->rxmt_interval = strtol (argv[0], NULL, 10);
  1205. return CMD_SUCCESS;
  1206. }
  1207. /* interface variable set command */
  1208. DEFUN (ipv6_ospf6_priority,
  1209. ipv6_ospf6_priority_cmd,
  1210. "ipv6 ospf6 priority <0-255>",
  1211. IP6_STR
  1212. OSPF6_STR
  1213. "Router priority\n"
  1214. "Priority value\n"
  1215. )
  1216. {
  1217. struct ospf6_interface *oi;
  1218. struct interface *ifp;
  1219. ifp = (struct interface *) vty->index;
  1220. assert (ifp);
  1221. oi = (struct ospf6_interface *) ifp->info;
  1222. if (oi == NULL)
  1223. oi = ospf6_interface_create (ifp);
  1224. assert (oi);
  1225. oi->priority = strtol (argv[0], NULL, 10);
  1226. if (oi->area &&
  1227. (oi->state == OSPF6_INTERFACE_DROTHER ||
  1228. oi->state == OSPF6_INTERFACE_BDR ||
  1229. oi->state == OSPF6_INTERFACE_DR))
  1230. ospf6_interface_state_change (dr_election (oi), oi);
  1231. return CMD_SUCCESS;
  1232. }
  1233. DEFUN (ipv6_ospf6_instance,
  1234. ipv6_ospf6_instance_cmd,
  1235. "ipv6 ospf6 instance-id <0-255>",
  1236. IP6_STR
  1237. OSPF6_STR
  1238. "Instance ID for this interface\n"
  1239. "Instance ID value\n"
  1240. )
  1241. {
  1242. struct ospf6_interface *oi;
  1243. struct interface *ifp;
  1244. ifp = (struct interface *)vty->index;
  1245. assert (ifp);
  1246. oi = (struct ospf6_interface *)ifp->info;
  1247. if (oi == NULL)
  1248. oi = ospf6_interface_create (ifp);
  1249. assert (oi);
  1250. oi->instance_id = strtol (argv[0], NULL, 10);
  1251. return CMD_SUCCESS;
  1252. }
  1253. DEFUN (ipv6_ospf6_passive,
  1254. ipv6_ospf6_passive_cmd,
  1255. "ipv6 ospf6 passive",
  1256. IP6_STR
  1257. OSPF6_STR
  1258. "passive interface, No adjacency will be formed on this interface\n"
  1259. )
  1260. {
  1261. struct ospf6_interface *oi;
  1262. struct interface *ifp;
  1263. struct listnode *node, *nnode;
  1264. struct ospf6_neighbor *on;
  1265. ifp = (struct interface *) vty->index;
  1266. assert (ifp);
  1267. oi = (struct ospf6_interface *) ifp->info;
  1268. if (oi == NULL)
  1269. oi = ospf6_interface_create (ifp);
  1270. assert (oi);
  1271. SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1272. THREAD_OFF (oi->thread_send_hello);
  1273. for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
  1274. {
  1275. THREAD_OFF (on->inactivity_timer);
  1276. thread_add_event (master, inactivity_timer, on, 0);
  1277. }
  1278. return CMD_SUCCESS;
  1279. }
  1280. DEFUN (no_ipv6_ospf6_passive,
  1281. no_ipv6_ospf6_passive_cmd,
  1282. "no ipv6 ospf6 passive",
  1283. NO_STR
  1284. IP6_STR
  1285. OSPF6_STR
  1286. "passive interface: No Adjacency will be formed on this I/F\n"
  1287. )
  1288. {
  1289. struct ospf6_interface *oi;
  1290. struct interface *ifp;
  1291. ifp = (struct interface *) vty->index;
  1292. assert (ifp);
  1293. oi = (struct ospf6_interface *) ifp->info;
  1294. if (oi == NULL)
  1295. oi = ospf6_interface_create (ifp);
  1296. assert (oi);
  1297. UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
  1298. THREAD_OFF (oi->thread_send_hello);
  1299. oi->thread_send_hello =
  1300. thread_add_event (master, ospf6_hello_send, oi, 0);
  1301. return CMD_SUCCESS;
  1302. }
  1303. DEFUN (ipv6_ospf6_mtu_ignore,
  1304. ipv6_ospf6_mtu_ignore_cmd,
  1305. "ipv6 ospf6 mtu-ignore",
  1306. IP6_STR
  1307. OSPF6_STR
  1308. "Ignore MTU mismatch on this interface\n"
  1309. )
  1310. {
  1311. struct ospf6_interface *oi;
  1312. struct interface *ifp;
  1313. ifp = (struct interface *) vty->index;
  1314. assert (ifp);
  1315. oi = (struct ospf6_interface *) ifp->info;
  1316. if (oi == NULL)
  1317. oi = ospf6_interface_create (ifp);
  1318. assert (oi);
  1319. oi->mtu_ignore = 1;
  1320. return CMD_SUCCESS;
  1321. }
  1322. DEFUN (no_ipv6_ospf6_mtu_ignore,
  1323. no_ipv6_ospf6_mtu_ignore_cmd,
  1324. "no ipv6 ospf6 mtu-ignore",
  1325. NO_STR
  1326. IP6_STR
  1327. OSPF6_STR
  1328. "Ignore MTU mismatch on this interface\n"
  1329. )
  1330. {
  1331. struct ospf6_interface *oi;
  1332. struct interface *ifp;
  1333. ifp = (struct interface *) vty->index;
  1334. assert (ifp);
  1335. oi = (struct ospf6_interface *) ifp->info;
  1336. if (oi == NULL)
  1337. oi = ospf6_interface_create (ifp);
  1338. assert (oi);
  1339. oi->mtu_ignore = 0;
  1340. return CMD_SUCCESS;
  1341. }
  1342. DEFUN (ipv6_ospf6_advertise_prefix_list,
  1343. ipv6_ospf6_advertise_prefix_list_cmd,
  1344. "ipv6 ospf6 advertise prefix-list WORD",
  1345. IP6_STR
  1346. OSPF6_STR
  1347. "Advertising options\n"
  1348. "Filter prefix using prefix-list\n"
  1349. "Prefix list name\n"
  1350. )
  1351. {
  1352. struct ospf6_interface *oi;
  1353. struct interface *ifp;
  1354. ifp = (struct interface *) vty->index;
  1355. assert (ifp);
  1356. oi = (struct ospf6_interface *) ifp->info;
  1357. if (oi == NULL)
  1358. oi = ospf6_interface_create (ifp);
  1359. assert (oi);
  1360. if (oi->plist_name)
  1361. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1362. oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
  1363. ospf6_interface_connected_route_update (oi->interface);
  1364. if (oi->area)
  1365. {
  1366. OSPF6_LINK_LSA_SCHEDULE (oi);
  1367. if (oi->state == OSPF6_INTERFACE_DR)
  1368. {
  1369. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1370. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1371. }
  1372. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1373. }
  1374. return CMD_SUCCESS;
  1375. }
  1376. DEFUN (no_ipv6_ospf6_advertise_prefix_list,
  1377. no_ipv6_ospf6_advertise_prefix_list_cmd,
  1378. "no ipv6 ospf6 advertise prefix-list",
  1379. NO_STR
  1380. IP6_STR
  1381. OSPF6_STR
  1382. "Advertising options\n"
  1383. "Filter prefix using prefix-list\n"
  1384. )
  1385. {
  1386. struct ospf6_interface *oi;
  1387. struct interface *ifp;
  1388. ifp = (struct interface *) vty->index;
  1389. assert (ifp);
  1390. oi = (struct ospf6_interface *) ifp->info;
  1391. if (oi == NULL)
  1392. oi = ospf6_interface_create (ifp);
  1393. assert (oi);
  1394. if (oi->plist_name)
  1395. {
  1396. XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
  1397. oi->plist_name = NULL;
  1398. }
  1399. ospf6_interface_connected_route_update (oi->interface);
  1400. if (oi->area)
  1401. {
  1402. OSPF6_LINK_LSA_SCHEDULE (oi);
  1403. if (oi->state == OSPF6_INTERFACE_DR)
  1404. {
  1405. OSPF6_NETWORK_LSA_SCHEDULE (oi);
  1406. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
  1407. }
  1408. OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
  1409. }
  1410. return CMD_SUCCESS;
  1411. }
  1412. DEFUN (ipv6_ospf6_network,
  1413. ipv6_ospf6_network_cmd,
  1414. "ipv6 ospf6 network (broadcast|point-to-point)",
  1415. IP6_STR
  1416. OSPF6_STR
  1417. "Network Type\n"
  1418. "Specify OSPFv6 broadcast network\n"
  1419. "Specify OSPF6 point-to-point network\n"
  1420. )
  1421. {
  1422. struct ospf6_interface *oi;
  1423. struct interface *ifp;
  1424. ifp = (struct interface *) vty->index;
  1425. assert (ifp);
  1426. oi = (struct ospf6_interface *) ifp->info;
  1427. if (oi == NULL) {
  1428. oi = ospf6_interface_create (ifp);
  1429. }
  1430. assert (oi);
  1431. if (strncmp (argv[0], "b", 1) == 0)
  1432. {
  1433. if (oi->type == OSPF_IFTYPE_BROADCAST)
  1434. return CMD_SUCCESS;
  1435. oi->type = OSPF_IFTYPE_BROADCAST;
  1436. }
  1437. else if (strncmp (argv[0], "point-to-p", 10) == 0)
  1438. {
  1439. if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
  1440. return CMD_SUCCESS;
  1441. }
  1442. oi->type = OSPF_IFTYPE_POINTOPOINT;
  1443. }
  1444. /* Reset the interface */
  1445. thread_add_event (master, interface_down, oi, 0);
  1446. thread_add_event (master, interface_up, oi, 0);
  1447. return CMD_SUCCESS;
  1448. }
  1449. DEFUN (no_ipv6_ospf6_network,
  1450. no_ipv6_ospf6_network_cmd,
  1451. "no ipv6 ospf6 network",
  1452. NO_STR
  1453. IP6_STR
  1454. OSPF6_STR
  1455. "Network Type\n"
  1456. "Default to whatever interface type system specifies"
  1457. )
  1458. {
  1459. struct ospf6_interface *oi;
  1460. struct interface *ifp;
  1461. int type;
  1462. ifp = (struct interface *) vty->index;
  1463. assert (ifp);
  1464. oi = (struct ospf6_interface *) ifp->info;
  1465. if (oi == NULL) {
  1466. return CMD_SUCCESS;
  1467. }
  1468. type = ospf6_default_iftype (ifp);
  1469. if (oi->type == type)
  1470. {
  1471. return CMD_SUCCESS;
  1472. }
  1473. oi->type = type;
  1474. /* Reset the interface */
  1475. thread_add_event (master, interface_down, oi, 0);
  1476. thread_add_event (master, interface_up, oi, 0);
  1477. return CMD_SUCCESS;
  1478. }
  1479. static int
  1480. config_write_ospf6_interface (struct vty *vty)
  1481. {
  1482. struct listnode *i;
  1483. struct ospf6_interface *oi;
  1484. struct interface *ifp;
  1485. for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
  1486. {
  1487. oi = (struct ospf6_interface *) ifp->info;
  1488. if (oi == NULL)
  1489. continue;
  1490. vty_out (vty, "interface %s%s",
  1491. oi->interface->name, VNL);
  1492. if (ifp->desc)
  1493. vty_out (vty, " description %s%s", ifp->desc, VNL);
  1494. if (ifp->mtu6 != oi->ifmtu)
  1495. vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
  1496. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST))
  1497. vty_out (vty, " ipv6 ospf6 cost %d%s",
  1498. oi->cost, VNL);
  1499. if (oi->hello_interval != OSPF6_INTERFACE_HELLO_INTERVAL)
  1500. vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
  1501. oi->hello_interval, VNL);
  1502. if (oi->dead_interval != OSPF6_INTERFACE_DEAD_INTERVAL)
  1503. vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
  1504. oi->dead_interval, VNL);
  1505. if (oi->rxmt_interval != OSPF6_INTERFACE_RXMT_INTERVAL)
  1506. vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
  1507. oi->rxmt_interval, VNL);
  1508. if (oi->priority != OSPF6_INTERFACE_PRIORITY)
  1509. vty_out (vty, " ipv6 ospf6 priority %d%s",
  1510. oi->priority, VNL);
  1511. if (oi->transdelay != OSPF6_INTERFACE_TRANSDELAY)
  1512. vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
  1513. oi->transdelay, VNL);
  1514. if (oi->instance_id != OSPF6_INTERFACE_INSTANCE_ID)
  1515. vty_out (vty, " ipv6 ospf6 instance-id %d%s",
  1516. oi->instance_id, VNL);
  1517. if (oi->plist_name)
  1518. vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
  1519. oi->plist_name, VNL);
  1520. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1521. vty_out (vty, " ipv6 ospf6 passive%s", VNL);
  1522. if (oi->mtu_ignore)
  1523. vty_out (vty, " ipv6 ospf6 mtu-ignore%s", VNL);
  1524. if (oi->type == OSPF_IFTYPE_POINTOPOINT)
  1525. vty_out (vty, " ipv6 ospf6 network point-to-point%s", VNL);
  1526. else if (oi->type == OSPF_IFTYPE_BROADCAST)
  1527. vty_out (vty, " ipv6 ospf6 network broadcast%s", VNL);
  1528. vty_out (vty, "!%s", VNL);
  1529. }
  1530. return 0;
  1531. }
  1532. static struct cmd_node interface_node =
  1533. {
  1534. INTERFACE_NODE,
  1535. "%s(config-if)# ",
  1536. 1 /* VTYSH */
  1537. };
  1538. void
  1539. ospf6_interface_init (void)
  1540. {
  1541. /* Install interface node. */
  1542. install_node (&interface_node, config_write_ospf6_interface);
  1543. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
  1544. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
  1545. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
  1546. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
  1547. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
  1548. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
  1549. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
  1550. install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
  1551. install_element (CONFIG_NODE, &interface_cmd);
  1552. install_default (INTERFACE_NODE);
  1553. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1554. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1555. install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
  1556. install_element (INTERFACE_NODE, &no_ipv6_ospf6_cost_cmd);
  1557. install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
  1558. install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
  1559. install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
  1560. install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
  1561. install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
  1562. install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
  1563. install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
  1564. install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
  1565. install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
  1566. install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
  1567. install_element (INTERFACE_NODE, &ipv6_ospf6_mtu_ignore_cmd);
  1568. install_element (INTERFACE_NODE, &no_ipv6_ospf6_mtu_ignore_cmd);
  1569. install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
  1570. install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
  1571. install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
  1572. install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
  1573. /* reference bandwidth commands */
  1574. install_element (OSPF6_NODE, &auto_cost_reference_bandwidth_cmd);
  1575. install_element (OSPF6_NODE, &no_auto_cost_reference_bandwidth_cmd);
  1576. }
  1577. /* Clear the specified interface structure */
  1578. static void
  1579. ospf6_interface_clear (struct vty *vty, struct interface *ifp)
  1580. {
  1581. struct ospf6_interface *oi;
  1582. if (!if_is_operative (ifp))
  1583. return;
  1584. if (ifp->info == NULL)
  1585. return;
  1586. oi = (struct ospf6_interface *) ifp->info;
  1587. if (IS_OSPF6_DEBUG_INTERFACE)
  1588. zlog_debug ("Interface %s: clear by reset", ifp->name);
  1589. /* Reset the interface */
  1590. thread_add_event (master, interface_down, oi, 0);
  1591. thread_add_event (master, interface_up, oi, 0);
  1592. }
  1593. /* Clear interface */
  1594. DEFUN (clear_ipv6_ospf6_interface,
  1595. clear_ipv6_ospf6_interface_cmd,
  1596. "clear ipv6 ospf6 interface [IFNAME]",
  1597. CLEAR_STR
  1598. IP6_STR
  1599. OSPF6_STR
  1600. INTERFACE_STR
  1601. IFNAME_STR
  1602. )
  1603. {
  1604. struct interface *ifp;
  1605. struct listnode *node;
  1606. if (argc == 0) /* Clear all the ospfv3 interfaces. */
  1607. {
  1608. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  1609. ospf6_interface_clear (vty, ifp);
  1610. }
  1611. else /* Interface name is specified. */
  1612. {
  1613. if ((ifp = if_lookup_by_name (argv[0])) == NULL)
  1614. {
  1615. vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
  1616. return CMD_WARNING;
  1617. }
  1618. ospf6_interface_clear (vty, ifp);
  1619. }
  1620. return CMD_SUCCESS;
  1621. }
  1622. void
  1623. install_element_ospf6_clear_interface (void)
  1624. {
  1625. install_element (ENABLE_NODE, &clear_ipv6_ospf6_interface_cmd);
  1626. }
  1627. DEFUN (debug_ospf6_interface,
  1628. debug_ospf6_interface_cmd,
  1629. "debug ospf6 interface",
  1630. DEBUG_STR
  1631. OSPF6_STR
  1632. "Debug OSPFv3 Interface\n"
  1633. )
  1634. {
  1635. OSPF6_DEBUG_INTERFACE_ON ();
  1636. return CMD_SUCCESS;
  1637. }
  1638. DEFUN (no_debug_ospf6_interface,
  1639. no_debug_ospf6_interface_cmd,
  1640. "no debug ospf6 interface",
  1641. NO_STR
  1642. DEBUG_STR
  1643. OSPF6_STR
  1644. "Debug OSPFv3 Interface\n"
  1645. )
  1646. {
  1647. OSPF6_DEBUG_INTERFACE_OFF ();
  1648. return CMD_SUCCESS;
  1649. }
  1650. int
  1651. config_write_ospf6_debug_interface (struct vty *vty)
  1652. {
  1653. if (IS_OSPF6_DEBUG_INTERFACE)
  1654. vty_out (vty, "debug ospf6 interface%s", VNL);
  1655. return 0;
  1656. }
  1657. void
  1658. install_element_ospf6_debug_interface (void)
  1659. {
  1660. install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
  1661. install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
  1662. install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
  1663. install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
  1664. }