ospf6_asbr.c 37 KB

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