ospf6_asbr.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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",
  932. NO_STR
  933. SET_STR
  934. "Metric value for destination routing protocol\n")
  935. {
  936. int ret = 0;
  937. if (argc == 0)
  938. ret = route_map_delete_set ((struct route_map_index *) vty->index,
  939. "metric", NULL);
  940. else
  941. ret = route_map_delete_set ((struct route_map_index *) vty->index,
  942. "metric", argv[0]);
  943. return route_map_command_status (vty, ret);
  944. }
  945. ALIAS (no_set_metric,
  946. no_set_metric_val_cmd,
  947. "no set metric <0-4294967295>",
  948. NO_STR
  949. SET_STR
  950. "Metric value for destination routing protocol\n"
  951. "Metric value\n")
  952. /* add "set forwarding-address" */
  953. DEFUN (ospf6_routemap_set_forwarding,
  954. ospf6_routemap_set_forwarding_cmd,
  955. "set forwarding-address X:X::X:X",
  956. "Set value\n"
  957. "Forwarding Address\n"
  958. "IPv6 Address\n")
  959. {
  960. int ret = route_map_add_set ((struct route_map_index *) vty->index,
  961. "forwarding-address", argv[0]);
  962. return route_map_command_status (vty, ret);
  963. }
  964. /* delete "set forwarding-address" */
  965. DEFUN (ospf6_routemap_no_set_forwarding,
  966. ospf6_routemap_no_set_forwarding_cmd,
  967. "no set forwarding-address X:X::X:X",
  968. NO_STR
  969. "Set value\n"
  970. "Forwarding Address\n"
  971. "IPv6 Address\n")
  972. {
  973. int ret = route_map_delete_set ((struct route_map_index *) vty->index,
  974. "forwarding-address", argv[0]);
  975. return route_map_command_status (vty, ret);
  976. }
  977. static void
  978. ospf6_routemap_init (void)
  979. {
  980. route_map_init ();
  981. route_map_init_vty ();
  982. route_map_add_hook (ospf6_asbr_routemap_update);
  983. route_map_delete_hook (ospf6_asbr_routemap_update);
  984. route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
  985. route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
  986. route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
  987. route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
  988. route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
  989. /* Match address prefix-list */
  990. install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
  991. install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
  992. /* Match interface */
  993. install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
  994. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
  995. install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd);
  996. /* ASE Metric Type (e.g. Type-1/Type-2) */
  997. install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
  998. install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
  999. /* ASE Metric */
  1000. install_element (RMAP_NODE, &set_metric_cmd);
  1001. install_element (RMAP_NODE, &no_set_metric_cmd);
  1002. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  1003. /* ASE Metric */
  1004. install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
  1005. install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
  1006. }
  1007. /* Display functions */
  1008. static char *
  1009. ospf6_as_external_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
  1010. int buflen, int pos)
  1011. {
  1012. struct ospf6_as_external_lsa *external;
  1013. struct in6_addr in6;
  1014. int prefix_length = 0;
  1015. if (lsa)
  1016. {
  1017. external = (struct ospf6_as_external_lsa *)
  1018. OSPF6_LSA_HEADER_END (lsa->header);
  1019. if (pos == 0)
  1020. {
  1021. ospf6_prefix_in6_addr (&in6, &external->prefix);
  1022. prefix_length = external->prefix.prefix_length;
  1023. }
  1024. else {
  1025. in6 = *((struct in6_addr *)
  1026. ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
  1027. OSPF6_PREFIX_SPACE (external->prefix.prefix_length)));
  1028. }
  1029. if (buf)
  1030. {
  1031. inet_ntop (AF_INET6, &in6, buf, buflen);
  1032. if (prefix_length)
  1033. sprintf (&buf[strlen(buf)], "/%d", prefix_length);
  1034. }
  1035. }
  1036. return (buf);
  1037. }
  1038. static int
  1039. ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  1040. {
  1041. struct ospf6_as_external_lsa *external;
  1042. char buf[64];
  1043. assert (lsa->header);
  1044. external = (struct ospf6_as_external_lsa *)
  1045. OSPF6_LSA_HEADER_END (lsa->header);
  1046. /* bits */
  1047. snprintf (buf, sizeof (buf), "%c%c%c",
  1048. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
  1049. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
  1050. (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
  1051. vty_out (vty, " Bits: %s%s", buf, VNL);
  1052. vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
  1053. VNL);
  1054. ospf6_prefix_options_printbuf (external->prefix.prefix_options,
  1055. buf, sizeof (buf));
  1056. vty_out (vty, " Prefix Options: %s%s", buf,
  1057. VNL);
  1058. vty_out (vty, " Referenced LSType: %d%s",
  1059. ntohs (external->prefix.prefix_refer_lstype),
  1060. VNL);
  1061. vty_out (vty, " Prefix: %s%s",
  1062. ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 0), VNL);
  1063. /* Forwarding-Address */
  1064. if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
  1065. {
  1066. vty_out (vty, " Forwarding-Address: %s%s",
  1067. ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 1),
  1068. VNL);
  1069. }
  1070. return 0;
  1071. }
  1072. static void
  1073. ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
  1074. {
  1075. struct ospf6_external_info *info = route->route_option;
  1076. char prefix[64], id[16], forwarding[64];
  1077. u_int32_t tmp_id;
  1078. prefix2str (&route->prefix, prefix, sizeof (prefix));
  1079. tmp_id = ntohl (info->id);
  1080. inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
  1081. if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
  1082. inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
  1083. else
  1084. snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
  1085. route->nexthop[0].ifindex);
  1086. vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
  1087. zebra_route_char(info->type),
  1088. prefix, id, route->path.metric_type,
  1089. (u_long) (route->path.metric_type == 2 ?
  1090. route->path.cost_e2 : route->path.cost),
  1091. forwarding, VNL);
  1092. }
  1093. DEFUN (show_ipv6_ospf6_redistribute,
  1094. show_ipv6_ospf6_redistribute_cmd,
  1095. "show ipv6 ospf6 redistribute",
  1096. SHOW_STR
  1097. IP6_STR
  1098. OSPF6_STR
  1099. "redistributing External information\n"
  1100. )
  1101. {
  1102. struct ospf6_route *route;
  1103. ospf6_redistribute_show_config (vty);
  1104. for (route = ospf6_route_head (ospf6->external_table); route;
  1105. route = ospf6_route_next (route))
  1106. ospf6_asbr_external_route_show (vty, route);
  1107. return CMD_SUCCESS;
  1108. }
  1109. struct ospf6_lsa_handler as_external_handler =
  1110. {
  1111. OSPF6_LSTYPE_AS_EXTERNAL,
  1112. "AS-External",
  1113. "ASE",
  1114. ospf6_as_external_lsa_show,
  1115. ospf6_as_external_lsa_get_prefix_str
  1116. };
  1117. void
  1118. ospf6_asbr_init (void)
  1119. {
  1120. ospf6_routemap_init ();
  1121. ospf6_install_lsa_handler (&as_external_handler);
  1122. install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
  1123. install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
  1124. install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
  1125. install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
  1126. }
  1127. void
  1128. ospf6_asbr_redistribute_reset (void)
  1129. {
  1130. int type;
  1131. for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
  1132. {
  1133. if (type == ZEBRA_ROUTE_OSPF6)
  1134. continue;
  1135. if (ospf6_zebra_is_redistribute (type))
  1136. ospf6_asbr_redistribute_unset(type);
  1137. }
  1138. }
  1139. void
  1140. ospf6_asbr_terminate (void)
  1141. {
  1142. route_map_finish ();
  1143. }
  1144. DEFUN (debug_ospf6_asbr,
  1145. debug_ospf6_asbr_cmd,
  1146. "debug ospf6 asbr",
  1147. DEBUG_STR
  1148. OSPF6_STR
  1149. "Debug OSPFv3 ASBR function\n"
  1150. )
  1151. {
  1152. OSPF6_DEBUG_ASBR_ON ();
  1153. return CMD_SUCCESS;
  1154. }
  1155. DEFUN (no_debug_ospf6_asbr,
  1156. no_debug_ospf6_asbr_cmd,
  1157. "no debug ospf6 asbr",
  1158. NO_STR
  1159. DEBUG_STR
  1160. OSPF6_STR
  1161. "Debug OSPFv3 ASBR function\n"
  1162. )
  1163. {
  1164. OSPF6_DEBUG_ASBR_OFF ();
  1165. return CMD_SUCCESS;
  1166. }
  1167. int
  1168. config_write_ospf6_debug_asbr (struct vty *vty)
  1169. {
  1170. if (IS_OSPF6_DEBUG_ASBR)
  1171. vty_out (vty, "debug ospf6 asbr%s", VNL);
  1172. return 0;
  1173. }
  1174. void
  1175. install_element_ospf6_debug_asbr ()
  1176. {
  1177. install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
  1178. install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
  1179. install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
  1180. install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
  1181. }