ospf6_asbr.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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 "log.h"
  23. #include "memory.h"
  24. #include "prefix.h"
  25. #include "command.h"
  26. #include "vty.h"
  27. #include "routemap.h"
  28. #include "table.h"
  29. #include "plist.h"
  30. #include "thread.h"
  31. #include "linklist.h"
  32. #include "ospf6_proto.h"
  33. #include "ospf6_lsa.h"
  34. #include "ospf6_lsdb.h"
  35. #include "ospf6_route.h"
  36. #include "ospf6_zebra.h"
  37. #include "ospf6_message.h"
  38. #include "ospf6_top.h"
  39. #include "ospf6_area.h"
  40. #include "ospf6_interface.h"
  41. #include "ospf6_neighbor.h"
  42. #include "ospf6_asbr.h"
  43. #include "ospf6_intra.h"
  44. #include "ospf6_flood.h"
  45. #include "ospf6d.h"
  46. unsigned char conf_debug_ospf6_asbr = 0;
  47. #define ZROUTE_NAME(x) zebra_route_string(x)
  48. /* AS External LSA origination */
  49. static void
  50. ospf6_as_external_lsa_originate (struct ospf6_route *route)
  51. {
  52. char buffer[OSPF6_MAX_LSASIZE];
  53. struct ospf6_lsa_header *lsa_header;
  54. struct ospf6_lsa *old, *lsa;
  55. struct ospf6_external_info *info = route->route_option;
  56. struct ospf6_as_external_lsa *as_external_lsa;
  57. char buf[64];
  58. caddr_t p;
  59. /* find previous LSA */
  60. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
  61. route->path.origin.id, ospf6->router_id,
  62. ospf6->lsdb);
  63. if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
  64. {
  65. prefix2str (&route->prefix, buf, sizeof (buf));
  66. zlog_debug ("Originate AS-External-LSA for %s", buf);
  67. }
  68. /* prepare buffer */
  69. memset (buffer, 0, sizeof (buffer));
  70. lsa_header = (struct ospf6_lsa_header *) buffer;
  71. as_external_lsa = (struct ospf6_as_external_lsa *)
  72. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  73. p = (caddr_t)
  74. ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa));
  75. /* Fill AS-External-LSA */
  76. /* Metric type */
  77. if (route->path.metric_type == 2)
  78. SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
  79. else
  80. UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
  81. /* forwarding address */
  82. if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
  83. SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
  84. else
  85. UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
  86. /* external route tag */
  87. UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
  88. /* Set metric */
  89. OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost);
  90. /* prefixlen */
  91. as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
  92. /* PrefixOptions */
  93. as_external_lsa->prefix.prefix_options = route->path.prefix_options;
  94. /* don't use refer LS-type */
  95. as_external_lsa->prefix.prefix_refer_lstype = htons (0);
  96. /* set Prefix */
  97. memcpy (p, &route->prefix.u.prefix6,
  98. OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
  99. ospf6_prefix_apply_mask (&as_external_lsa->prefix);
  100. p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
  101. /* Forwarding address */
  102. if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
  103. {
  104. memcpy (p, &info->forwarding, sizeof (struct in6_addr));
  105. p += sizeof (struct in6_addr);
  106. }
  107. /* External Route Tag */
  108. if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
  109. {
  110. /* xxx */
  111. }
  112. /* Fill LSA Header */
  113. lsa_header->age = 0;
  114. lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
  115. lsa_header->id = route->path.origin.id;
  116. lsa_header->adv_router = ospf6->router_id;
  117. lsa_header->seqnum =
  118. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  119. lsa_header->adv_router, ospf6->lsdb);
  120. lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
  121. /* LSA checksum */
  122. ospf6_lsa_checksum (lsa_header);
  123. /* create LSA */
  124. lsa = ospf6_lsa_create (lsa_header);
  125. /* Originate */
  126. ospf6_lsa_originate_process (lsa, ospf6);
  127. }
  128. void
  129. ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
  130. {
  131. struct ospf6_as_external_lsa *external;
  132. struct prefix asbr_id;
  133. struct ospf6_route *asbr_entry, *route;
  134. char buf[64];
  135. int i;
  136. external = (struct ospf6_as_external_lsa *)
  137. OSPF6_LSA_HEADER_END (lsa->header);
  138. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  139. zlog_debug ("Calculate AS-External route for %s", lsa->name);
  140. if (lsa->header->adv_router == ospf6->router_id)
  141. {
  142. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  143. zlog_debug ("Ignore self-originated AS-External-LSA");
  144. return;
  145. }
  146. if (OSPF6_ASBR_METRIC (external) == LS_INFINITY)
  147. {
  148. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  149. zlog_debug ("Ignore LSA with LSInfinity Metric");
  150. return;
  151. }
  152. ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
  153. asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
  154. if (asbr_entry == NULL ||
  155. ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
  156. {
  157. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  158. {
  159. prefix2str (&asbr_id, buf, sizeof (buf));
  160. zlog_debug ("ASBR entry not found: %s", buf);
  161. }
  162. return;
  163. }
  164. route = ospf6_route_create ();
  165. route->type = OSPF6_DEST_TYPE_NETWORK;
  166. route->prefix.family = AF_INET6;
  167. route->prefix.prefixlen = external->prefix.prefix_length;
  168. ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
  169. route->path.area_id = asbr_entry->path.area_id;
  170. route->path.origin.type = lsa->header->type;
  171. route->path.origin.id = lsa->header->id;
  172. route->path.origin.adv_router = lsa->header->adv_router;
  173. route->path.prefix_options = external->prefix.prefix_options;
  174. if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
  175. {
  176. route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
  177. route->path.metric_type = 2;
  178. route->path.cost = asbr_entry->path.cost;
  179. route->path.cost_e2 = OSPF6_ASBR_METRIC (external);
  180. }
  181. else
  182. {
  183. route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
  184. route->path.metric_type = 1;
  185. route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
  186. route->path.cost_e2 = 0;
  187. }
  188. for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
  189. ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]);
  190. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  191. {
  192. prefix2str (&route->prefix, buf, sizeof (buf));
  193. zlog_debug ("AS-External route add: %s", buf);
  194. }
  195. ospf6_route_add (route, ospf6->route_table);
  196. }
  197. void
  198. ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
  199. {
  200. struct ospf6_as_external_lsa *external;
  201. struct prefix prefix;
  202. struct ospf6_route *route;
  203. char buf[64];
  204. external = (struct ospf6_as_external_lsa *)
  205. OSPF6_LSA_HEADER_END (lsa->header);
  206. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  207. zlog_debug ("Withdraw AS-External route for %s", lsa->name);
  208. if (lsa->header->adv_router == ospf6->router_id)
  209. {
  210. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  211. zlog_debug ("Ignore self-originated AS-External-LSA");
  212. return;
  213. }
  214. memset (&prefix, 0, sizeof (struct prefix));
  215. prefix.family = AF_INET6;
  216. prefix.prefixlen = external->prefix.prefix_length;
  217. ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
  218. route = ospf6_route_lookup (&prefix, ospf6->route_table);
  219. if (route == NULL)
  220. {
  221. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  222. {
  223. prefix2str (&prefix, buf, sizeof (buf));
  224. zlog_debug ("AS-External route %s not found", buf);
  225. }
  226. return;
  227. }
  228. for (ospf6_route_lock (route);
  229. route && ospf6_route_is_prefix (&prefix, route);
  230. route = ospf6_route_next (route))
  231. {
  232. if (route->type != OSPF6_DEST_TYPE_NETWORK)
  233. continue;
  234. if (route->path.origin.type != lsa->header->type)
  235. continue;
  236. if (route->path.origin.id != lsa->header->id)
  237. continue;
  238. if (route->path.origin.adv_router != lsa->header->adv_router)
  239. continue;
  240. if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
  241. {
  242. prefix2str (&route->prefix, buf, sizeof (buf));
  243. zlog_debug ("AS-External route remove: %s", buf);
  244. }
  245. ospf6_route_remove (route, ospf6->route_table);
  246. }
  247. }
  248. void
  249. ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
  250. {
  251. struct ospf6_lsa *lsa;
  252. u_int16_t type;
  253. u_int32_t router;
  254. if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
  255. {
  256. char buf[16];
  257. inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
  258. buf, sizeof (buf));
  259. zlog_info ("ignore non-best path: lsentry %s add", buf);
  260. return;
  261. }
  262. type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
  263. router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
  264. for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
  265. lsa = ospf6_lsdb_type_router_next (type, router, lsa))
  266. {
  267. if (! OSPF6_LSA_IS_MAXAGE (lsa))
  268. ospf6_asbr_lsa_add (lsa);
  269. }
  270. }
  271. void
  272. ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
  273. {
  274. struct ospf6_lsa *lsa;
  275. u_int16_t type;
  276. u_int32_t router;
  277. type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
  278. router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
  279. for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
  280. lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
  281. ospf6_asbr_lsa_remove (lsa);
  282. }
  283. /* redistribute function */
  284. static void
  285. ospf6_asbr_routemap_set (int type, const char *mapname)
  286. {
  287. if (ospf6->rmap[type].name)
  288. free (ospf6->rmap[type].name);
  289. ospf6->rmap[type].name = strdup (mapname);
  290. ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
  291. }
  292. static void
  293. ospf6_asbr_routemap_unset (int type)
  294. {
  295. if (ospf6->rmap[type].name)
  296. free (ospf6->rmap[type].name);
  297. ospf6->rmap[type].name = NULL;
  298. ospf6->rmap[type].map = NULL;
  299. }
  300. static void
  301. ospf6_asbr_routemap_update (const char *mapname)
  302. {
  303. int type;
  304. if (ospf6 == NULL)
  305. return;
  306. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  307. {
  308. if (ospf6->rmap[type].name)
  309. ospf6->rmap[type].map =
  310. route_map_lookup_by_name (ospf6->rmap[type].name);
  311. else
  312. ospf6->rmap[type].map = NULL;
  313. }
  314. }
  315. int
  316. ospf6_asbr_is_asbr (struct ospf6 *o)
  317. {
  318. return o->external_table->count;
  319. }
  320. static void
  321. ospf6_asbr_redistribute_set (int type)
  322. {
  323. ospf6_zebra_redistribute (type);
  324. }
  325. static void
  326. ospf6_asbr_redistribute_unset (int type)
  327. {
  328. struct ospf6_route *route;
  329. struct ospf6_external_info *info;
  330. ospf6_zebra_no_redistribute (type);
  331. for (route = ospf6_route_head (ospf6->external_table); route;
  332. route = ospf6_route_next (route))
  333. {
  334. info = route->route_option;
  335. if (info->type != type)
  336. continue;
  337. ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex,
  338. &route->prefix);
  339. }
  340. }
  341. void
  342. ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix,
  343. u_int nexthop_num, struct in6_addr *nexthop)
  344. {
  345. int ret;
  346. struct ospf6_route troute;
  347. struct ospf6_external_info tinfo;
  348. struct ospf6_route *route, *match;
  349. struct ospf6_external_info *info;
  350. struct prefix prefix_id;
  351. struct route_node *node;
  352. char pbuf[64], ibuf[16];
  353. struct listnode *lnode, *lnnode;
  354. struct ospf6_area *oa;
  355. if (! ospf6_zebra_is_redistribute (type))
  356. return;
  357. if (IS_OSPF6_DEBUG_ASBR)
  358. {
  359. prefix2str (prefix, pbuf, sizeof (pbuf));
  360. zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
  361. }
  362. /* if route-map was specified but not found, do not advertise */
  363. if (ospf6->rmap[type].name)
  364. {
  365. if (ospf6->rmap[type].map == NULL)
  366. ospf6_asbr_routemap_update (NULL);
  367. if (ospf6->rmap[type].map == NULL)
  368. {
  369. zlog_warn ("route-map \"%s\" not found, suppress redistributing",
  370. ospf6->rmap[type].name);
  371. return;
  372. }
  373. }
  374. /* apply route-map */
  375. if (ospf6->rmap[type].map)
  376. {
  377. memset (&troute, 0, sizeof (troute));
  378. memset (&tinfo, 0, sizeof (tinfo));
  379. troute.route_option = &tinfo;
  380. tinfo.ifindex = ifindex;
  381. ret = route_map_apply (ospf6->rmap[type].map, prefix,
  382. RMAP_OSPF6, &troute);
  383. if (ret == RMAP_DENYMATCH)
  384. {
  385. if (IS_OSPF6_DEBUG_ASBR)
  386. zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
  387. return;
  388. }
  389. }
  390. match = ospf6_route_lookup (prefix, ospf6->external_table);
  391. if (match)
  392. {
  393. info = match->route_option;
  394. /* copy result of route-map */
  395. if (ospf6->rmap[type].map)
  396. {
  397. if (troute.path.metric_type)
  398. match->path.metric_type = troute.path.metric_type;
  399. if (troute.path.cost)
  400. match->path.cost = troute.path.cost;
  401. if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
  402. memcpy (&info->forwarding, &tinfo.forwarding,
  403. sizeof (struct in6_addr));
  404. }
  405. info->type = type;
  406. match->nexthop[0].ifindex = ifindex;
  407. if (nexthop_num && nexthop)
  408. memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr));
  409. /* create/update binding in external_id_table */
  410. prefix_id.family = AF_INET;
  411. prefix_id.prefixlen = 32;
  412. prefix_id.u.prefix4.s_addr = htonl (info->id);
  413. node = route_node_get (ospf6->external_id_table, &prefix_id);
  414. node->info = match;
  415. if (IS_OSPF6_DEBUG_ASBR)
  416. {
  417. inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
  418. zlog_debug ("Advertise as AS-External Id:%s", ibuf);
  419. }
  420. match->path.origin.id = htonl (info->id);
  421. ospf6_as_external_lsa_originate (match);
  422. return;
  423. }
  424. /* create new entry */
  425. route = ospf6_route_create ();
  426. route->type = OSPF6_DEST_TYPE_NETWORK;
  427. memcpy (&route->prefix, prefix, sizeof (struct prefix));
  428. info = (struct ospf6_external_info *)
  429. XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
  430. route->route_option = info;
  431. info->id = ospf6->external_id++;
  432. /* copy result of route-map */
  433. if (ospf6->rmap[type].map)
  434. {
  435. if (troute.path.metric_type)
  436. route->path.metric_type = troute.path.metric_type;
  437. if (troute.path.cost)
  438. route->path.cost = troute.path.cost;
  439. if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
  440. memcpy (&info->forwarding, &tinfo.forwarding,
  441. sizeof (struct in6_addr));
  442. }
  443. info->type = type;
  444. route->nexthop[0].ifindex = ifindex;
  445. if (nexthop_num && nexthop)
  446. memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr));
  447. /* create/update binding in external_id_table */
  448. prefix_id.family = AF_INET;
  449. prefix_id.prefixlen = 32;
  450. prefix_id.u.prefix4.s_addr = htonl (info->id);
  451. node = route_node_get (ospf6->external_id_table, &prefix_id);
  452. node->info = route;
  453. route = ospf6_route_add (route, ospf6->external_table);
  454. route->route_option = info;
  455. if (IS_OSPF6_DEBUG_ASBR)
  456. {
  457. inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
  458. zlog_debug ("Advertise as AS-External Id:%s", ibuf);
  459. }
  460. route->path.origin.id = htonl (info->id);
  461. ospf6_as_external_lsa_originate (route);
  462. /* Router-Bit (ASBR Flag) may have to be updated */
  463. for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
  464. OSPF6_ROUTER_LSA_SCHEDULE (oa);
  465. }
  466. void
  467. ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix)
  468. {
  469. struct ospf6_route *match;
  470. struct ospf6_external_info *info = NULL;
  471. struct route_node *node;
  472. struct ospf6_lsa *lsa;
  473. struct prefix prefix_id;
  474. char pbuf[64], ibuf[16];
  475. struct listnode *lnode, *lnnode;
  476. struct ospf6_area *oa;
  477. match = ospf6_route_lookup (prefix, ospf6->external_table);
  478. if (match == NULL)
  479. {
  480. if (IS_OSPF6_DEBUG_ASBR)
  481. {
  482. prefix2str (prefix, pbuf, sizeof (pbuf));
  483. zlog_debug ("No such route %s to withdraw", pbuf);
  484. }
  485. return;
  486. }
  487. info = match->route_option;
  488. assert (info);
  489. if (info->type != type)
  490. {
  491. if (IS_OSPF6_DEBUG_ASBR)
  492. {
  493. prefix2str (prefix, pbuf, sizeof (pbuf));
  494. zlog_debug ("Original protocol mismatch: %s", pbuf);
  495. }
  496. return;
  497. }
  498. if (IS_OSPF6_DEBUG_ASBR)
  499. {
  500. prefix2str (prefix, pbuf, sizeof (pbuf));
  501. inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
  502. zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
  503. }
  504. lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
  505. htonl (info->id), ospf6->router_id, ospf6->lsdb);
  506. if (lsa)
  507. ospf6_lsa_purge (lsa);
  508. /* remove binding in external_id_table */
  509. prefix_id.family = AF_INET;
  510. prefix_id.prefixlen = 32;
  511. prefix_id.u.prefix4.s_addr = htonl (info->id);
  512. node = route_node_lookup (ospf6->external_id_table, &prefix_id);
  513. assert (node);
  514. node->info = NULL;
  515. route_unlock_node (node);
  516. ospf6_route_remove (match, ospf6->external_table);
  517. XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
  518. /* Router-Bit (ASBR Flag) may have to be updated */
  519. for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
  520. OSPF6_ROUTER_LSA_SCHEDULE (oa);
  521. }
  522. DEFUN (ospf6_redistribute,
  523. ospf6_redistribute_cmd,
  524. "redistribute " QUAGGA_REDIST_STR_OSPF6D,
  525. "Redistribute\n"
  526. QUAGGA_REDIST_HELP_STR_OSPF6D
  527. )
  528. {
  529. int type;
  530. type = proto_redistnum(AFI_IP6, argv[0]);
  531. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  532. return CMD_WARNING;
  533. ospf6_asbr_redistribute_unset (type);
  534. ospf6_asbr_routemap_unset (type);
  535. ospf6_asbr_redistribute_set (type);
  536. return CMD_SUCCESS;
  537. }
  538. DEFUN (ospf6_redistribute_routemap,
  539. ospf6_redistribute_routemap_cmd,
  540. "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
  541. "Redistribute\n"
  542. QUAGGA_REDIST_HELP_STR_OSPF6D
  543. "Route map reference\n"
  544. "Route map name\n"
  545. )
  546. {
  547. int type;
  548. type = proto_redistnum(AFI_IP6, argv[0]);
  549. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  550. return CMD_WARNING;
  551. ospf6_asbr_redistribute_unset (type);
  552. ospf6_asbr_routemap_set (type, argv[1]);
  553. ospf6_asbr_redistribute_set (type);
  554. return CMD_SUCCESS;
  555. }
  556. DEFUN (no_ospf6_redistribute,
  557. no_ospf6_redistribute_cmd,
  558. "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
  559. NO_STR
  560. "Redistribute\n"
  561. QUAGGA_REDIST_HELP_STR_OSPF6D
  562. )
  563. {
  564. int type;
  565. type = proto_redistnum(AFI_IP6, argv[0]);
  566. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  567. return CMD_WARNING;
  568. ospf6_asbr_redistribute_unset (type);
  569. ospf6_asbr_routemap_unset (type);
  570. return CMD_SUCCESS;
  571. }
  572. int
  573. ospf6_redistribute_config_write (struct vty *vty)
  574. {
  575. int type;
  576. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  577. {
  578. if (type == ZEBRA_ROUTE_OSPF6)
  579. continue;
  580. if (! ospf6_zebra_is_redistribute (type))
  581. continue;
  582. if (ospf6->rmap[type].name)
  583. vty_out (vty, " redistribute %s route-map %s%s",
  584. ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
  585. else
  586. vty_out (vty, " redistribute %s%s",
  587. ZROUTE_NAME (type), VNL);
  588. }
  589. return 0;
  590. }
  591. static void
  592. ospf6_redistribute_show_config (struct vty *vty)
  593. {
  594. int type;
  595. int nroute[ZEBRA_ROUTE_MAX];
  596. int total;
  597. struct ospf6_route *route;
  598. struct ospf6_external_info *info;
  599. total = 0;
  600. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  601. nroute[type] = 0;
  602. for (route = ospf6_route_head (ospf6->external_table); route;
  603. route = ospf6_route_next (route))
  604. {
  605. info = route->route_option;
  606. nroute[info->type]++;
  607. total++;
  608. }
  609. vty_out (vty, "Redistributing External Routes from:%s", VNL);
  610. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  611. {
  612. if (type == ZEBRA_ROUTE_OSPF6)
  613. continue;
  614. if (! ospf6_zebra_is_redistribute (type))
  615. continue;
  616. if (ospf6->rmap[type].name)
  617. vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
  618. ZROUTE_NAME (type), ospf6->rmap[type].name,
  619. (ospf6->rmap[type].map ? "" : " (not found !)"),
  620. VNL);
  621. else
  622. vty_out (vty, " %d: %s%s", nroute[type],
  623. ZROUTE_NAME (type), VNL);
  624. }
  625. vty_out (vty, "Total %d routes%s", total, VNL);
  626. }
  627. /* Routemap Functions */
  628. static route_map_result_t
  629. ospf6_routemap_rule_match_address_prefixlist (void *rule,
  630. struct prefix *prefix,
  631. route_map_object_t type,
  632. void *object)
  633. {
  634. struct prefix_list *plist;
  635. if (type != RMAP_OSPF6)
  636. return RMAP_NOMATCH;
  637. plist = prefix_list_lookup (AFI_IP6, (char *) rule);
  638. if (plist == NULL)
  639. return RMAP_NOMATCH;
  640. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  641. RMAP_NOMATCH : RMAP_MATCH);
  642. }
  643. static void *
  644. ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
  645. {
  646. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  647. }
  648. static void
  649. ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
  650. {
  651. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  652. }
  653. struct route_map_rule_cmd
  654. ospf6_routemap_rule_match_address_prefixlist_cmd =
  655. {
  656. "ipv6 address prefix-list",
  657. ospf6_routemap_rule_match_address_prefixlist,
  658. ospf6_routemap_rule_match_address_prefixlist_compile,
  659. ospf6_routemap_rule_match_address_prefixlist_free,
  660. };
  661. /* `match interface IFNAME' */
  662. /* Match function should return 1 if match is success else return
  663. zero. */
  664. static route_map_result_t
  665. ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix,
  666. route_map_object_t type, void *object)
  667. {
  668. struct interface *ifp;
  669. struct ospf6_external_info *ei;
  670. if (type == RMAP_OSPF6)
  671. {
  672. ei = ((struct ospf6_route *) object)->route_option;
  673. ifp = if_lookup_by_name ((char *)rule);
  674. if (ifp != NULL
  675. && ei->ifindex == ifp->ifindex)
  676. return RMAP_MATCH;
  677. }
  678. return RMAP_NOMATCH;
  679. }
  680. /* Route map `interface' match statement. `arg' should be
  681. interface name. */
  682. static void *
  683. ospf6_routemap_rule_match_interface_compile (const char *arg)
  684. {
  685. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  686. }
  687. /* Free route map's compiled `interface' value. */
  688. static void
  689. ospf6_routemap_rule_match_interface_free (void *rule)
  690. {
  691. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  692. }
  693. /* Route map commands for interface matching. */
  694. struct route_map_rule_cmd
  695. ospf6_routemap_rule_match_interface_cmd =
  696. {
  697. "interface",
  698. ospf6_routemap_rule_match_interface,
  699. ospf6_routemap_rule_match_interface_compile,
  700. ospf6_routemap_rule_match_interface_free
  701. };
  702. static route_map_result_t
  703. ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
  704. route_map_object_t type, void *object)
  705. {
  706. char *metric_type = rule;
  707. struct ospf6_route *route = object;
  708. if (type != RMAP_OSPF6)
  709. return RMAP_OKAY;
  710. if (strcmp (metric_type, "type-2") == 0)
  711. route->path.metric_type = 2;
  712. else
  713. route->path.metric_type = 1;
  714. return RMAP_OKAY;
  715. }
  716. static void *
  717. ospf6_routemap_rule_set_metric_type_compile (const char *arg)
  718. {
  719. if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
  720. return NULL;
  721. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  722. }
  723. static void
  724. ospf6_routemap_rule_set_metric_type_free (void *rule)
  725. {
  726. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  727. }
  728. struct route_map_rule_cmd
  729. ospf6_routemap_rule_set_metric_type_cmd =
  730. {
  731. "metric-type",
  732. ospf6_routemap_rule_set_metric_type,
  733. ospf6_routemap_rule_set_metric_type_compile,
  734. ospf6_routemap_rule_set_metric_type_free,
  735. };
  736. static route_map_result_t
  737. ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
  738. route_map_object_t type, void *object)
  739. {
  740. char *metric = rule;
  741. struct ospf6_route *route = object;
  742. if (type != RMAP_OSPF6)
  743. return RMAP_OKAY;
  744. route->path.cost = atoi (metric);
  745. return RMAP_OKAY;
  746. }
  747. static void *
  748. ospf6_routemap_rule_set_metric_compile (const char *arg)
  749. {
  750. u_int32_t metric;
  751. char *endp;
  752. metric = strtoul (arg, &endp, 0);
  753. if (metric > LS_INFINITY || *endp != '\0')
  754. return NULL;
  755. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  756. }
  757. static void
  758. ospf6_routemap_rule_set_metric_free (void *rule)
  759. {
  760. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  761. }
  762. struct route_map_rule_cmd
  763. ospf6_routemap_rule_set_metric_cmd =
  764. {
  765. "metric",
  766. ospf6_routemap_rule_set_metric,
  767. ospf6_routemap_rule_set_metric_compile,
  768. ospf6_routemap_rule_set_metric_free,
  769. };
  770. static route_map_result_t
  771. ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
  772. route_map_object_t type, void *object)
  773. {
  774. char *forwarding = rule;
  775. struct ospf6_route *route = object;
  776. struct ospf6_external_info *info = route->route_option;
  777. if (type != RMAP_OSPF6)
  778. return RMAP_OKAY;
  779. if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
  780. {
  781. memset (&info->forwarding, 0, sizeof (struct in6_addr));
  782. return RMAP_ERROR;
  783. }
  784. return RMAP_OKAY;
  785. }
  786. static void *
  787. ospf6_routemap_rule_set_forwarding_compile (const char *arg)
  788. {
  789. struct in6_addr a;
  790. if (inet_pton (AF_INET6, arg, &a) != 1)
  791. return NULL;
  792. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  793. }
  794. static void
  795. ospf6_routemap_rule_set_forwarding_free (void *rule)
  796. {
  797. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  798. }
  799. struct route_map_rule_cmd
  800. ospf6_routemap_rule_set_forwarding_cmd =
  801. {
  802. "forwarding-address",
  803. ospf6_routemap_rule_set_forwarding,
  804. ospf6_routemap_rule_set_forwarding_compile,
  805. ospf6_routemap_rule_set_forwarding_free,
  806. };
  807. static int
  808. route_map_command_status (struct vty *vty, int ret)
  809. {
  810. if (! ret)
  811. return CMD_SUCCESS;
  812. switch (ret)
  813. {
  814. case RMAP_RULE_MISSING:
  815. vty_out (vty, "Can't find rule.%s", VNL);
  816. break;
  817. case RMAP_COMPILE_ERROR:
  818. vty_out (vty, "Argument is malformed.%s", VNL);
  819. break;
  820. default:
  821. vty_out (vty, "route-map add set failed.%s", VNL);
  822. break;
  823. }
  824. return CMD_WARNING;
  825. }
  826. /* add "match address" */
  827. DEFUN (ospf6_routemap_match_address_prefixlist,
  828. ospf6_routemap_match_address_prefixlist_cmd,
  829. "match ipv6 address prefix-list WORD",
  830. "Match values\n"
  831. IPV6_STR
  832. "Match address of route\n"
  833. "Match entries of prefix-lists\n"
  834. "IPv6 prefix-list name\n")
  835. {
  836. int ret = route_map_add_match ((struct route_map_index *) vty->index,
  837. "ipv6 address prefix-list", argv[0]);
  838. return route_map_command_status (vty, ret);
  839. }
  840. /* delete "match address" */
  841. DEFUN (ospf6_routemap_no_match_address_prefixlist,
  842. ospf6_routemap_no_match_address_prefixlist_cmd,
  843. "no match ipv6 address prefix-list WORD",
  844. NO_STR
  845. "Match values\n"
  846. IPV6_STR
  847. "Match address of route\n"
  848. "Match entries of prefix-lists\n"
  849. "IPv6 prefix-list name\n")
  850. {
  851. int ret = route_map_delete_match ((struct route_map_index *) vty->index,
  852. "ipv6 address prefix-list", argv[0]);
  853. return route_map_command_status (vty, ret);
  854. }
  855. /* "match interface" */
  856. DEFUN (ospf6_routemap_match_interface,
  857. ospf6_routemap_match_interface_cmd,
  858. "match interface WORD",
  859. MATCH_STR
  860. "Match first hop interface of route\n"
  861. "Interface name\n")
  862. {
  863. return route_map_add_match ((struct route_map_index *) vty->index,
  864. "interface", argv[0]);
  865. }
  866. /* "no match interface WORD" */
  867. DEFUN (ospf6_routemap_no_match_interface,
  868. ospf6_routemap_no_match_interface_cmd,
  869. "no match interface",
  870. MATCH_STR
  871. NO_STR
  872. "Match first hop interface of route\n")
  873. {
  874. int ret = route_map_delete_match ((struct route_map_index *) vty->index,
  875. "interface", (argc == 0) ? NULL : argv[0]);
  876. return route_map_command_status (vty, ret);
  877. }
  878. ALIAS (ospf6_routemap_no_match_interface,
  879. ospf6_routemap_no_match_interface_val_cmd,
  880. "no match interface WORD",
  881. MATCH_STR
  882. NO_STR
  883. "Match first hop interface of route\n"
  884. "Interface name\n")
  885. /* add "set metric-type" */
  886. DEFUN (ospf6_routemap_set_metric_type,
  887. ospf6_routemap_set_metric_type_cmd,
  888. "set metric-type (type-1|type-2)",
  889. "Set value\n"
  890. "Type of metric\n"
  891. "OSPF6 external type 1 metric\n"
  892. "OSPF6 external type 2 metric\n")
  893. {
  894. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  895. "metric-type", argv[0]);
  896. return route_map_command_status (vty, ret);
  897. }
  898. /* delete "set metric-type" */
  899. DEFUN (ospf6_routemap_no_set_metric_type,
  900. ospf6_routemap_no_set_metric_type_cmd,
  901. "no set metric-type (type-1|type-2)",
  902. NO_STR
  903. "Set value\n"
  904. "Type of metric\n"
  905. "OSPF6 external type 1 metric\n"
  906. "OSPF6 external type 2 metric\n")
  907. {
  908. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  909. "metric-type", argv[0]);
  910. return route_map_command_status (vty, ret);
  911. }
  912. /* add "set metric" */
  913. DEFUN (set_metric,
  914. set_metric_cmd,
  915. "set metric <0-4294967295>",
  916. "Set value\n"
  917. "Metric value\n"
  918. "Metric value\n")
  919. {
  920. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  921. "metric", argv[0]);
  922. return route_map_command_status (vty, ret);
  923. }
  924. /* delete "set metric" */
  925. DEFUN (no_set_metric,
  926. no_set_metric_cmd,
  927. "no set metric <0-4294967295>",
  928. NO_STR
  929. "Set value\n"
  930. "Metric\n"
  931. "METRIC value\n")
  932. {
  933. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  934. "metric", argv[0]);
  935. return route_map_command_status (vty, ret);
  936. }
  937. /* add "set forwarding-address" */
  938. DEFUN (ospf6_routemap_set_forwarding,
  939. ospf6_routemap_set_forwarding_cmd,
  940. "set forwarding-address X:X::X:X",
  941. "Set value\n"
  942. "Forwarding Address\n"
  943. "IPv6 Address\n")
  944. {
  945. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  946. "forwarding-address", argv[0]);
  947. return route_map_command_status (vty, ret);
  948. }
  949. /* delete "set forwarding-address" */
  950. DEFUN (ospf6_routemap_no_set_forwarding,
  951. ospf6_routemap_no_set_forwarding_cmd,
  952. "no set forwarding-address X:X::X:X",
  953. NO_STR
  954. "Set value\n"
  955. "Forwarding Address\n"
  956. "IPv6 Address\n")
  957. {
  958. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  959. "forwarding-address", argv[0]);
  960. return route_map_command_status (vty, ret);
  961. }
  962. static void
  963. ospf6_routemap_init (void)
  964. {
  965. route_map_init ();
  966. route_map_init_vty ();
  967. route_map_add_hook (ospf6_asbr_routemap_update);
  968. route_map_delete_hook (ospf6_asbr_routemap_update);
  969. route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
  970. route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
  971. route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
  972. route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
  973. route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
  974. /* Match address prefix-list */
  975. install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
  976. install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
  977. /* Match interface */
  978. install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
  979. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
  980. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd);
  981. /* ASE Metric Type (e.g. Type-1/Type-2) */
  982. install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
  983. install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
  984. /* ASE Metric */
  985. install_element (RMAP_NODE, &set_metric_cmd);
  986. install_element (RMAP_NODE, &no_set_metric_cmd);
  987. /* ASE Metric */
  988. install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
  989. install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
  990. }
  991. /* Display functions */
  992. static int
  993. ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  994. {
  995. struct ospf6_as_external_lsa *external;
  996. char buf[64];
  997. struct in6_addr in6, *forwarding;
  998. assert (lsa->header);
  999. external = (struct ospf6_as_external_lsa *)
  1000. OSPF6_LSA_HEADER_END (lsa->header);
  1001. /* bits */
  1002. snprintf (buf, sizeof (buf), "%c%c%c",
  1003. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
  1004. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
  1005. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
  1006. vty_out (vty, " Bits: %s%s", buf, VNL);
  1007. vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
  1008. VNL);
  1009. ospf6_prefix_options_printbuf (external->prefix.prefix_options,
  1010. buf, sizeof (buf));
  1011. vty_out (vty, " Prefix Options: %s%s", buf,
  1012. VNL);
  1013. vty_out (vty, " Referenced LSType: %d%s",
  1014. ntohs (external->prefix.prefix_refer_lstype),
  1015. VNL);
  1016. ospf6_prefix_in6_addr (&in6, &external->prefix);
  1017. inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
  1018. vty_out (vty, " Prefix: %s/%d%s", buf,
  1019. external->prefix.prefix_length, VNL);
  1020. /* Forwarding-Address */
  1021. if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
  1022. {
  1023. forwarding = (struct in6_addr *)
  1024. ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
  1025. OSPF6_PREFIX_SPACE (external->prefix.prefix_length));
  1026. inet_ntop (AF_INET6, forwarding, buf, sizeof (buf));
  1027. vty_out (vty, " Forwarding-Address: %s%s", buf, VNL);
  1028. }
  1029. return 0;
  1030. }
  1031. static void
  1032. ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
  1033. {
  1034. struct ospf6_external_info *info = route->route_option;
  1035. char prefix[64], id[16], forwarding[64];
  1036. u_int32_t tmp_id;
  1037. prefix2str (&route->prefix, prefix, sizeof (prefix));
  1038. tmp_id = ntohl (info->id);
  1039. inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
  1040. if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
  1041. inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
  1042. else
  1043. snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
  1044. route->nexthop[0].ifindex);
  1045. vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
  1046. zebra_route_char(info->type),
  1047. prefix, id, route->path.metric_type,
  1048. (u_long) (route->path.metric_type == 2 ?
  1049. route->path.cost_e2 : route->path.cost),
  1050. forwarding, VNL);
  1051. }
  1052. DEFUN (show_ipv6_ospf6_redistribute,
  1053. show_ipv6_ospf6_redistribute_cmd,
  1054. "show ipv6 ospf6 redistribute",
  1055. SHOW_STR
  1056. IP6_STR
  1057. OSPF6_STR
  1058. "redistributing External information\n"
  1059. )
  1060. {
  1061. struct ospf6_route *route;
  1062. ospf6_redistribute_show_config (vty);
  1063. for (route = ospf6_route_head (ospf6->external_table); route;
  1064. route = ospf6_route_next (route))
  1065. ospf6_asbr_external_route_show (vty, route);
  1066. return CMD_SUCCESS;
  1067. }
  1068. struct ospf6_lsa_handler as_external_handler =
  1069. {
  1070. OSPF6_LSTYPE_AS_EXTERNAL,
  1071. "AS-External",
  1072. ospf6_as_external_lsa_show
  1073. };
  1074. void
  1075. ospf6_asbr_init (void)
  1076. {
  1077. ospf6_routemap_init ();
  1078. ospf6_install_lsa_handler (&as_external_handler);
  1079. install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
  1080. install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);
  1081. install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
  1082. install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
  1083. install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
  1084. }
  1085. void
  1086. ospf6_asbr_terminate (void)
  1087. {
  1088. route_map_finish ();
  1089. }
  1090. DEFUN (debug_ospf6_asbr,
  1091. debug_ospf6_asbr_cmd,
  1092. "debug ospf6 asbr",
  1093. DEBUG_STR
  1094. OSPF6_STR
  1095. "Debug OSPFv3 ASBR function\n"
  1096. )
  1097. {
  1098. OSPF6_DEBUG_ASBR_ON ();
  1099. return CMD_SUCCESS;
  1100. }
  1101. DEFUN (no_debug_ospf6_asbr,
  1102. no_debug_ospf6_asbr_cmd,
  1103. "no debug ospf6 asbr",
  1104. NO_STR
  1105. DEBUG_STR
  1106. OSPF6_STR
  1107. "Debug OSPFv3 ASBR function\n"
  1108. )
  1109. {
  1110. OSPF6_DEBUG_ASBR_OFF ();
  1111. return CMD_SUCCESS;
  1112. }
  1113. int
  1114. config_write_ospf6_debug_asbr (struct vty *vty)
  1115. {
  1116. if (IS_OSPF6_DEBUG_ASBR)
  1117. vty_out (vty, "debug ospf6 asbr%s", VNL);
  1118. return 0;
  1119. }
  1120. void
  1121. install_element_ospf6_debug_asbr ()
  1122. {
  1123. install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
  1124. install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
  1125. install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
  1126. install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
  1127. }