ospf6_asbr.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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, ifindex_t 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, ifindex_t ifindex,
  473. struct prefix *prefix)
  474. {
  475. struct ospf6_route *match;
  476. struct ospf6_external_info *info = NULL;
  477. struct route_node *node;
  478. struct ospf6_lsa *lsa;
  479. struct prefix prefix_id;
  480. char pbuf[64], ibuf[16];
  481. struct listnode *lnode, *lnnode;
  482. struct ospf6_area *oa;
  483. match = ospf6_route_lookup (prefix, ospf6->external_table);
  484. if (match == NULL)
  485. {
  486. if (IS_OSPF6_DEBUG_ASBR)
  487. {
  488. prefix2str (prefix, pbuf, sizeof (pbuf));
  489. zlog_debug ("No such route %s to withdraw", pbuf);
  490. }
  491. return;
  492. }
  493. info = match->route_option;
  494. assert (info);
  495. if (info->type != type)
  496. {
  497. if (IS_OSPF6_DEBUG_ASBR)
  498. {
  499. prefix2str (prefix, pbuf, sizeof (pbuf));
  500. zlog_debug ("Original protocol mismatch: %s", pbuf);
  501. }
  502. return;
  503. }
  504. if (IS_OSPF6_DEBUG_ASBR)
  505. {
  506. prefix2str (prefix, pbuf, sizeof (pbuf));
  507. inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
  508. zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
  509. }
  510. lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
  511. htonl (info->id), ospf6->router_id, ospf6->lsdb);
  512. if (lsa)
  513. ospf6_lsa_purge (lsa);
  514. /* remove binding in external_id_table */
  515. prefix_id.family = AF_INET;
  516. prefix_id.prefixlen = 32;
  517. prefix_id.u.prefix4.s_addr = htonl (info->id);
  518. node = route_node_lookup (ospf6->external_id_table, &prefix_id);
  519. assert (node);
  520. node->info = NULL;
  521. route_unlock_node (node);
  522. ospf6_route_remove (match, ospf6->external_table);
  523. XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
  524. /* Router-Bit (ASBR Flag) may have to be updated */
  525. for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
  526. OSPF6_ROUTER_LSA_SCHEDULE (oa);
  527. }
  528. DEFUN (ospf6_redistribute,
  529. ospf6_redistribute_cmd,
  530. "redistribute " QUAGGA_REDIST_STR_OSPF6D,
  531. "Redistribute\n"
  532. QUAGGA_REDIST_HELP_STR_OSPF6D
  533. )
  534. {
  535. int type;
  536. type = proto_redistnum(AFI_IP6, argv[0]);
  537. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  538. return CMD_WARNING;
  539. ospf6_asbr_redistribute_unset (type);
  540. ospf6_asbr_redistribute_set (type);
  541. return CMD_SUCCESS;
  542. }
  543. DEFUN (ospf6_redistribute_routemap,
  544. ospf6_redistribute_routemap_cmd,
  545. "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
  546. "Redistribute\n"
  547. QUAGGA_REDIST_HELP_STR_OSPF6D
  548. "Route map reference\n"
  549. "Route map name\n"
  550. )
  551. {
  552. int type;
  553. type = proto_redistnum(AFI_IP6, argv[0]);
  554. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  555. return CMD_WARNING;
  556. ospf6_asbr_redistribute_unset (type);
  557. ospf6_asbr_routemap_set (type, argv[1]);
  558. ospf6_asbr_redistribute_set (type);
  559. return CMD_SUCCESS;
  560. }
  561. DEFUN (no_ospf6_redistribute,
  562. no_ospf6_redistribute_cmd,
  563. "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
  564. NO_STR
  565. "Redistribute\n"
  566. QUAGGA_REDIST_HELP_STR_OSPF6D
  567. )
  568. {
  569. int type;
  570. type = proto_redistnum(AFI_IP6, argv[0]);
  571. if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
  572. return CMD_WARNING;
  573. ospf6_asbr_redistribute_unset (type);
  574. return CMD_SUCCESS;
  575. }
  576. int
  577. ospf6_redistribute_config_write (struct vty *vty)
  578. {
  579. int type;
  580. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  581. {
  582. if (type == ZEBRA_ROUTE_OSPF6)
  583. continue;
  584. if (! ospf6_zebra_is_redistribute (type))
  585. continue;
  586. if (ospf6->rmap[type].name)
  587. vty_out (vty, " redistribute %s route-map %s%s",
  588. ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
  589. else
  590. vty_out (vty, " redistribute %s%s",
  591. ZROUTE_NAME (type), VNL);
  592. }
  593. return 0;
  594. }
  595. static void
  596. ospf6_redistribute_show_config (struct vty *vty)
  597. {
  598. int type;
  599. int nroute[ZEBRA_ROUTE_MAX];
  600. int total;
  601. struct ospf6_route *route;
  602. struct ospf6_external_info *info;
  603. total = 0;
  604. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  605. nroute[type] = 0;
  606. for (route = ospf6_route_head (ospf6->external_table); route;
  607. route = ospf6_route_next (route))
  608. {
  609. info = route->route_option;
  610. nroute[info->type]++;
  611. total++;
  612. }
  613. vty_out (vty, "Redistributing External Routes from:%s", VNL);
  614. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  615. {
  616. if (type == ZEBRA_ROUTE_OSPF6)
  617. continue;
  618. if (! ospf6_zebra_is_redistribute (type))
  619. continue;
  620. if (ospf6->rmap[type].name)
  621. vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
  622. ZROUTE_NAME (type), ospf6->rmap[type].name,
  623. (ospf6->rmap[type].map ? "" : " (not found !)"),
  624. VNL);
  625. else
  626. vty_out (vty, " %d: %s%s", nroute[type],
  627. ZROUTE_NAME (type), VNL);
  628. }
  629. vty_out (vty, "Total %d routes%s", total, VNL);
  630. }
  631. /* Routemap Functions */
  632. static route_map_result_t
  633. ospf6_routemap_rule_match_address_prefixlist (void *rule,
  634. struct prefix *prefix,
  635. route_map_object_t type,
  636. void *object)
  637. {
  638. struct prefix_list *plist;
  639. if (type != RMAP_OSPF6)
  640. return RMAP_NOMATCH;
  641. plist = prefix_list_lookup (AFI_IP6, (char *) rule);
  642. if (plist == NULL)
  643. return RMAP_NOMATCH;
  644. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  645. RMAP_NOMATCH : RMAP_MATCH);
  646. }
  647. static void *
  648. ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
  649. {
  650. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  651. }
  652. static void
  653. ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
  654. {
  655. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  656. }
  657. struct route_map_rule_cmd
  658. ospf6_routemap_rule_match_address_prefixlist_cmd =
  659. {
  660. "ipv6 address prefix-list",
  661. ospf6_routemap_rule_match_address_prefixlist,
  662. ospf6_routemap_rule_match_address_prefixlist_compile,
  663. ospf6_routemap_rule_match_address_prefixlist_free,
  664. };
  665. /* `match interface IFNAME' */
  666. /* Match function should return 1 if match is success else return
  667. zero. */
  668. static route_map_result_t
  669. ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix,
  670. route_map_object_t type, void *object)
  671. {
  672. struct interface *ifp;
  673. struct ospf6_external_info *ei;
  674. if (type == RMAP_OSPF6)
  675. {
  676. ei = ((struct ospf6_route *) object)->route_option;
  677. ifp = if_lookup_by_name ((char *)rule);
  678. if (ifp != NULL
  679. && ei->ifindex == ifp->ifindex)
  680. return RMAP_MATCH;
  681. }
  682. return RMAP_NOMATCH;
  683. }
  684. /* Route map `interface' match statement. `arg' should be
  685. interface name. */
  686. static void *
  687. ospf6_routemap_rule_match_interface_compile (const char *arg)
  688. {
  689. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  690. }
  691. /* Free route map's compiled `interface' value. */
  692. static void
  693. ospf6_routemap_rule_match_interface_free (void *rule)
  694. {
  695. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  696. }
  697. /* Route map commands for interface matching. */
  698. struct route_map_rule_cmd
  699. ospf6_routemap_rule_match_interface_cmd =
  700. {
  701. "interface",
  702. ospf6_routemap_rule_match_interface,
  703. ospf6_routemap_rule_match_interface_compile,
  704. ospf6_routemap_rule_match_interface_free
  705. };
  706. static route_map_result_t
  707. ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
  708. route_map_object_t type, void *object)
  709. {
  710. char *metric_type = rule;
  711. struct ospf6_route *route = object;
  712. if (type != RMAP_OSPF6)
  713. return RMAP_OKAY;
  714. if (strcmp (metric_type, "type-2") == 0)
  715. route->path.metric_type = 2;
  716. else
  717. route->path.metric_type = 1;
  718. return RMAP_OKAY;
  719. }
  720. static void *
  721. ospf6_routemap_rule_set_metric_type_compile (const char *arg)
  722. {
  723. if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
  724. return NULL;
  725. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  726. }
  727. static void
  728. ospf6_routemap_rule_set_metric_type_free (void *rule)
  729. {
  730. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  731. }
  732. struct route_map_rule_cmd
  733. ospf6_routemap_rule_set_metric_type_cmd =
  734. {
  735. "metric-type",
  736. ospf6_routemap_rule_set_metric_type,
  737. ospf6_routemap_rule_set_metric_type_compile,
  738. ospf6_routemap_rule_set_metric_type_free,
  739. };
  740. static route_map_result_t
  741. ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
  742. route_map_object_t type, void *object)
  743. {
  744. char *metric = rule;
  745. struct ospf6_route *route = object;
  746. if (type != RMAP_OSPF6)
  747. return RMAP_OKAY;
  748. route->path.cost = atoi (metric);
  749. return RMAP_OKAY;
  750. }
  751. static void *
  752. ospf6_routemap_rule_set_metric_compile (const char *arg)
  753. {
  754. u_int32_t metric;
  755. char *endp;
  756. metric = strtoul (arg, &endp, 0);
  757. if (metric > OSPF_LS_INFINITY || *endp != '\0')
  758. return NULL;
  759. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  760. }
  761. static void
  762. ospf6_routemap_rule_set_metric_free (void *rule)
  763. {
  764. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  765. }
  766. struct route_map_rule_cmd
  767. ospf6_routemap_rule_set_metric_cmd =
  768. {
  769. "metric",
  770. ospf6_routemap_rule_set_metric,
  771. ospf6_routemap_rule_set_metric_compile,
  772. ospf6_routemap_rule_set_metric_free,
  773. };
  774. static route_map_result_t
  775. ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
  776. route_map_object_t type, void *object)
  777. {
  778. char *forwarding = rule;
  779. struct ospf6_route *route = object;
  780. struct ospf6_external_info *info = route->route_option;
  781. if (type != RMAP_OSPF6)
  782. return RMAP_OKAY;
  783. if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
  784. {
  785. memset (&info->forwarding, 0, sizeof (struct in6_addr));
  786. return RMAP_ERROR;
  787. }
  788. return RMAP_OKAY;
  789. }
  790. static void *
  791. ospf6_routemap_rule_set_forwarding_compile (const char *arg)
  792. {
  793. struct in6_addr a;
  794. if (inet_pton (AF_INET6, arg, &a) != 1)
  795. return NULL;
  796. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  797. }
  798. static void
  799. ospf6_routemap_rule_set_forwarding_free (void *rule)
  800. {
  801. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  802. }
  803. struct route_map_rule_cmd
  804. ospf6_routemap_rule_set_forwarding_cmd =
  805. {
  806. "forwarding-address",
  807. ospf6_routemap_rule_set_forwarding,
  808. ospf6_routemap_rule_set_forwarding_compile,
  809. ospf6_routemap_rule_set_forwarding_free,
  810. };
  811. static int
  812. route_map_command_status (struct vty *vty, int ret)
  813. {
  814. if (! ret)
  815. return CMD_SUCCESS;
  816. switch (ret)
  817. {
  818. case RMAP_RULE_MISSING:
  819. vty_out (vty, "Can't find rule.%s", VNL);
  820. break;
  821. case RMAP_COMPILE_ERROR:
  822. vty_out (vty, "Argument is malformed.%s", VNL);
  823. break;
  824. default:
  825. vty_out (vty, "route-map add set failed.%s", VNL);
  826. break;
  827. }
  828. return CMD_WARNING;
  829. }
  830. /* add "match address" */
  831. DEFUN (ospf6_routemap_match_address_prefixlist,
  832. ospf6_routemap_match_address_prefixlist_cmd,
  833. "match ipv6 address prefix-list WORD",
  834. "Match values\n"
  835. IPV6_STR
  836. "Match address of route\n"
  837. "Match entries of prefix-lists\n"
  838. "IPv6 prefix-list name\n")
  839. {
  840. int ret = route_map_add_match ((struct route_map_index *) vty->index,
  841. "ipv6 address prefix-list", argv[0]);
  842. return route_map_command_status (vty, ret);
  843. }
  844. /* delete "match address" */
  845. DEFUN (ospf6_routemap_no_match_address_prefixlist,
  846. ospf6_routemap_no_match_address_prefixlist_cmd,
  847. "no match ipv6 address prefix-list WORD",
  848. NO_STR
  849. "Match values\n"
  850. IPV6_STR
  851. "Match address of route\n"
  852. "Match entries of prefix-lists\n"
  853. "IPv6 prefix-list name\n")
  854. {
  855. int ret = route_map_delete_match ((struct route_map_index *) vty->index,
  856. "ipv6 address prefix-list", argv[0]);
  857. return route_map_command_status (vty, ret);
  858. }
  859. /* "match interface" */
  860. DEFUN (ospf6_routemap_match_interface,
  861. ospf6_routemap_match_interface_cmd,
  862. "match interface WORD",
  863. MATCH_STR
  864. "Match first hop interface of route\n"
  865. "Interface name\n")
  866. {
  867. return route_map_add_match ((struct route_map_index *) vty->index,
  868. "interface", argv[0]);
  869. }
  870. /* "no match interface WORD" */
  871. DEFUN (ospf6_routemap_no_match_interface,
  872. ospf6_routemap_no_match_interface_cmd,
  873. "no match interface",
  874. MATCH_STR
  875. NO_STR
  876. "Match first hop interface of route\n")
  877. {
  878. int ret = route_map_delete_match ((struct route_map_index *) vty->index,
  879. "interface", (argc == 0) ? NULL : argv[0]);
  880. return route_map_command_status (vty, ret);
  881. }
  882. ALIAS (ospf6_routemap_no_match_interface,
  883. ospf6_routemap_no_match_interface_val_cmd,
  884. "no match interface WORD",
  885. MATCH_STR
  886. NO_STR
  887. "Match first hop interface of route\n"
  888. "Interface name\n")
  889. /* add "set metric-type" */
  890. DEFUN (ospf6_routemap_set_metric_type,
  891. ospf6_routemap_set_metric_type_cmd,
  892. "set metric-type (type-1|type-2)",
  893. "Set value\n"
  894. "Type of metric\n"
  895. "OSPF6 external type 1 metric\n"
  896. "OSPF6 external type 2 metric\n")
  897. {
  898. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  899. "metric-type", argv[0]);
  900. return route_map_command_status (vty, ret);
  901. }
  902. /* delete "set metric-type" */
  903. DEFUN (ospf6_routemap_no_set_metric_type,
  904. ospf6_routemap_no_set_metric_type_cmd,
  905. "no set metric-type (type-1|type-2)",
  906. NO_STR
  907. "Set value\n"
  908. "Type of metric\n"
  909. "OSPF6 external type 1 metric\n"
  910. "OSPF6 external type 2 metric\n")
  911. {
  912. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  913. "metric-type", argv[0]);
  914. return route_map_command_status (vty, ret);
  915. }
  916. /* add "set metric" */
  917. DEFUN (set_metric,
  918. set_metric_cmd,
  919. "set metric <0-4294967295>",
  920. "Set value\n"
  921. "Metric value\n"
  922. "Metric value\n")
  923. {
  924. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  925. "metric", argv[0]);
  926. return route_map_command_status (vty, ret);
  927. }
  928. /* delete "set metric" */
  929. DEFUN (no_set_metric,
  930. no_set_metric_cmd,
  931. "no set metric <0-4294967295>",
  932. NO_STR
  933. "Set value\n"
  934. "Metric\n"
  935. "METRIC value\n")
  936. {
  937. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  938. "metric", argv[0]);
  939. return route_map_command_status (vty, ret);
  940. }
  941. /* add "set forwarding-address" */
  942. DEFUN (ospf6_routemap_set_forwarding,
  943. ospf6_routemap_set_forwarding_cmd,
  944. "set forwarding-address X:X::X:X",
  945. "Set value\n"
  946. "Forwarding Address\n"
  947. "IPv6 Address\n")
  948. {
  949. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  950. "forwarding-address", argv[0]);
  951. return route_map_command_status (vty, ret);
  952. }
  953. /* delete "set forwarding-address" */
  954. DEFUN (ospf6_routemap_no_set_forwarding,
  955. ospf6_routemap_no_set_forwarding_cmd,
  956. "no set forwarding-address X:X::X:X",
  957. NO_STR
  958. "Set value\n"
  959. "Forwarding Address\n"
  960. "IPv6 Address\n")
  961. {
  962. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  963. "forwarding-address", argv[0]);
  964. return route_map_command_status (vty, ret);
  965. }
  966. static void
  967. ospf6_routemap_init (void)
  968. {
  969. route_map_init ();
  970. route_map_init_vty ();
  971. route_map_add_hook (ospf6_asbr_routemap_update);
  972. route_map_delete_hook (ospf6_asbr_routemap_update);
  973. route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
  974. route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
  975. route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
  976. route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
  977. route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
  978. /* Match address prefix-list */
  979. install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
  980. install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
  981. /* Match interface */
  982. install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
  983. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
  984. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd);
  985. /* ASE Metric Type (e.g. Type-1/Type-2) */
  986. install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
  987. install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
  988. /* ASE Metric */
  989. install_element (RMAP_NODE, &set_metric_cmd);
  990. install_element (RMAP_NODE, &no_set_metric_cmd);
  991. /* ASE Metric */
  992. install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
  993. install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
  994. }
  995. /* Display functions */
  996. static char *
  997. ospf6_as_external_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
  998. int buflen, int pos)
  999. {
  1000. struct ospf6_as_external_lsa *external;
  1001. struct in6_addr in6;
  1002. int prefix_length = 0;
  1003. if (lsa)
  1004. {
  1005. external = (struct ospf6_as_external_lsa *)
  1006. OSPF6_LSA_HEADER_END (lsa->header);
  1007. if (pos == 0)
  1008. {
  1009. ospf6_prefix_in6_addr (&in6, &external->prefix);
  1010. prefix_length = external->prefix.prefix_length;
  1011. }
  1012. else {
  1013. in6 = *((struct in6_addr *)
  1014. ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
  1015. OSPF6_PREFIX_SPACE (external->prefix.prefix_length)));
  1016. }
  1017. if (buf)
  1018. {
  1019. inet_ntop (AF_INET6, &in6, buf, buflen);
  1020. if (prefix_length)
  1021. sprintf (&buf[strlen(buf)], "/%d", prefix_length);
  1022. }
  1023. }
  1024. return (buf);
  1025. }
  1026. static int
  1027. ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  1028. {
  1029. struct ospf6_as_external_lsa *external;
  1030. char buf[64];
  1031. assert (lsa->header);
  1032. external = (struct ospf6_as_external_lsa *)
  1033. OSPF6_LSA_HEADER_END (lsa->header);
  1034. /* bits */
  1035. snprintf (buf, sizeof (buf), "%c%c%c",
  1036. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
  1037. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
  1038. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
  1039. vty_out (vty, " Bits: %s%s", buf, VNL);
  1040. vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
  1041. VNL);
  1042. ospf6_prefix_options_printbuf (external->prefix.prefix_options,
  1043. buf, sizeof (buf));
  1044. vty_out (vty, " Prefix Options: %s%s", buf,
  1045. VNL);
  1046. vty_out (vty, " Referenced LSType: %d%s",
  1047. ntohs (external->prefix.prefix_refer_lstype),
  1048. VNL);
  1049. vty_out (vty, " Prefix: %s%s",
  1050. ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 0), VNL);
  1051. /* Forwarding-Address */
  1052. if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
  1053. {
  1054. vty_out (vty, " Forwarding-Address: %s%s",
  1055. ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 1),
  1056. VNL);
  1057. }
  1058. return 0;
  1059. }
  1060. static void
  1061. ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
  1062. {
  1063. struct ospf6_external_info *info = route->route_option;
  1064. char prefix[64], id[16], forwarding[64];
  1065. u_int32_t tmp_id;
  1066. prefix2str (&route->prefix, prefix, sizeof (prefix));
  1067. tmp_id = ntohl (info->id);
  1068. inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
  1069. if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
  1070. inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
  1071. else
  1072. snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
  1073. route->nexthop[0].ifindex);
  1074. vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
  1075. zebra_route_char(info->type),
  1076. prefix, id, route->path.metric_type,
  1077. (u_long) (route->path.metric_type == 2 ?
  1078. route->path.cost_e2 : route->path.cost),
  1079. forwarding, VNL);
  1080. }
  1081. DEFUN (show_ipv6_ospf6_redistribute,
  1082. show_ipv6_ospf6_redistribute_cmd,
  1083. "show ipv6 ospf6 redistribute",
  1084. SHOW_STR
  1085. IP6_STR
  1086. OSPF6_STR
  1087. "redistributing External information\n"
  1088. )
  1089. {
  1090. struct ospf6_route *route;
  1091. ospf6_redistribute_show_config (vty);
  1092. for (route = ospf6_route_head (ospf6->external_table); route;
  1093. route = ospf6_route_next (route))
  1094. ospf6_asbr_external_route_show (vty, route);
  1095. return CMD_SUCCESS;
  1096. }
  1097. struct ospf6_lsa_handler as_external_handler =
  1098. {
  1099. OSPF6_LSTYPE_AS_EXTERNAL,
  1100. "AS-External",
  1101. "ASE",
  1102. ospf6_as_external_lsa_show,
  1103. ospf6_as_external_lsa_get_prefix_str
  1104. };
  1105. void
  1106. ospf6_asbr_init (void)
  1107. {
  1108. ospf6_routemap_init ();
  1109. ospf6_install_lsa_handler (&as_external_handler);
  1110. install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
  1111. install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);
  1112. install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
  1113. install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
  1114. install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
  1115. }
  1116. void
  1117. ospf6_asbr_redistribute_reset (void)
  1118. {
  1119. int type;
  1120. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  1121. {
  1122. if (type == ZEBRA_ROUTE_OSPF6)
  1123. continue;
  1124. if (ospf6_zebra_is_redistribute (type))
  1125. ospf6_asbr_redistribute_unset(type);
  1126. }
  1127. }
  1128. void
  1129. ospf6_asbr_terminate (void)
  1130. {
  1131. route_map_finish ();
  1132. }
  1133. DEFUN (debug_ospf6_asbr,
  1134. debug_ospf6_asbr_cmd,
  1135. "debug ospf6 asbr",
  1136. DEBUG_STR
  1137. OSPF6_STR
  1138. "Debug OSPFv3 ASBR function\n"
  1139. )
  1140. {
  1141. OSPF6_DEBUG_ASBR_ON ();
  1142. return CMD_SUCCESS;
  1143. }
  1144. DEFUN (no_debug_ospf6_asbr,
  1145. no_debug_ospf6_asbr_cmd,
  1146. "no debug ospf6 asbr",
  1147. NO_STR
  1148. DEBUG_STR
  1149. OSPF6_STR
  1150. "Debug OSPFv3 ASBR function\n"
  1151. )
  1152. {
  1153. OSPF6_DEBUG_ASBR_OFF ();
  1154. return CMD_SUCCESS;
  1155. }
  1156. int
  1157. config_write_ospf6_debug_asbr (struct vty *vty)
  1158. {
  1159. if (IS_OSPF6_DEBUG_ASBR)
  1160. vty_out (vty, "debug ospf6 asbr%s", VNL);
  1161. return 0;
  1162. }
  1163. void
  1164. install_element_ospf6_debug_asbr ()
  1165. {
  1166. install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
  1167. install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
  1168. install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
  1169. install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
  1170. }