ospf6_interface.c 44 KB

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