ospf6_abr.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * Area Border Router function.
  3. * Copyright (C) 2004 Yasuhiro Ohara
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "log.h"
  24. #include "prefix.h"
  25. #include "table.h"
  26. #include "vty.h"
  27. #include "linklist.h"
  28. #include "command.h"
  29. #include "ospf6_proto.h"
  30. #include "ospf6_route.h"
  31. #include "ospf6_lsa.h"
  32. #include "ospf6_route.h"
  33. #include "ospf6_lsdb.h"
  34. #include "ospf6_top.h"
  35. #include "ospf6_area.h"
  36. #include "ospf6_interface.h"
  37. #include "ospf6_abr.h"
  38. #include "ospf6d.h"
  39. unsigned char conf_debug_ospf6_abr;
  40. /* RFC 2328 12.4.3. Summary-LSAs */
  41. void
  42. ospf6_abr_originate_prefix_to_area (struct ospf6_route *route,
  43. struct ospf6_area *area)
  44. {
  45. struct ospf6_lsa *lsa, *old = NULL;
  46. struct ospf6_interface *oi;
  47. struct ospf6_route *summary, *range = NULL;
  48. struct ospf6_area *route_area;
  49. char buffer[OSPF6_MAX_LSASIZE];
  50. struct ospf6_lsa_header *lsa_header;
  51. caddr_t p;
  52. struct ospf6_inter_prefix_lsa *prefix_lsa;
  53. summary = ospf6_route_lookup (&route->prefix, area->summary_table);
  54. if (summary)
  55. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTER_PREFIX),
  56. summary->path.origin.id,
  57. area->ospf6->router_id, area->lsdb);
  58. /* if this route has just removed, remove corresponding LSA */
  59. if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
  60. {
  61. if (old)
  62. ospf6_lsa_premature_aging (old);
  63. return;
  64. }
  65. /* Only destination type network and address range are considered */
  66. if (route->type != OSPF6_DEST_TYPE_NETWORK)
  67. {
  68. if (old)
  69. ospf6_lsa_premature_aging (old);
  70. return;
  71. }
  72. /* AS External routes are never considered */
  73. if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
  74. route->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
  75. {
  76. if (old)
  77. ospf6_lsa_premature_aging (old);
  78. return;
  79. }
  80. /* do not generate if the route cost is greater or equal to LSInfinity */
  81. if (route->path.cost >= LS_INFINITY)
  82. {
  83. if (old)
  84. ospf6_lsa_premature_aging (old);
  85. return;
  86. }
  87. /* if this is an inter-area route */
  88. if (route->path.type == OSPF6_PATH_TYPE_INTRA)
  89. {
  90. /* search for configured address range for the route's area */
  91. route_area = ospf6_area_lookup (route->path.area_id, area->ospf6);
  92. assert (route_area);
  93. range = ospf6_route_lookup_bestmatch (&route->prefix,
  94. route_area->summary_table);
  95. }
  96. /* ranges are ignored when originate backbone routes to transit area.
  97. Otherwise, if ranges are configured, the route is suppressed. */
  98. if (range && (route->path.area_id != htonl (0) || ! area->transit_capability))
  99. {
  100. if (old)
  101. ospf6_lsa_premature_aging (old);
  102. if (range->path.cost < route->path.cost)
  103. range->path.cost = route->path.cost;
  104. SET_FLAG (range->flag, OSPF6_ROUTE_HAVE_LONGER);
  105. return;
  106. }
  107. /* do not generate if the path's area is the same as target area */
  108. if (route->path.area_id == area->area_id)
  109. {
  110. if (old)
  111. ospf6_lsa_premature_aging (old);
  112. return;
  113. }
  114. /* do not generate if the nexthops belongs to the target area */
  115. oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex);
  116. if (oi && oi->area && oi->area->area_id == area->area_id)
  117. {
  118. if (old)
  119. ospf6_lsa_premature_aging (old);
  120. return;
  121. }
  122. /* the route is going to be originated. store it in area's summary_table */
  123. if (summary == NULL)
  124. {
  125. summary = ospf6_route_copy (route);
  126. summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
  127. summary->path.origin.adv_router = area->ospf6->router_id;
  128. summary->path.origin.id =
  129. ospf6_new_ls_id (summary->path.origin.type,
  130. summary->path.origin.adv_router, area->lsdb);
  131. ospf6_route_add (summary, area->summary_table);
  132. }
  133. /* prepare buffer */
  134. memset (buffer, 0, sizeof (buffer));
  135. lsa_header = (struct ospf6_lsa_header *) buffer;
  136. prefix_lsa = (struct ospf6_inter_prefix_lsa *)
  137. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  138. p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);
  139. /* Fill Inter-Area-Prefix-LSA */
  140. OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
  141. /* prefixlen */
  142. prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
  143. /* PrefixOptions */
  144. prefix_lsa->prefix.prefix_options = route->path.prefix_options;
  145. /* set Prefix */
  146. memcpy (p, &route->prefix.u.prefix6,
  147. OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
  148. ospf6_prefix_apply_mask (&prefix_lsa->prefix);
  149. p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
  150. /* Fill LSA Header */
  151. lsa_header->age = 0;
  152. lsa_header->type = htons (OSPF6_LSTYPE_INTER_PREFIX);
  153. lsa_header->id = summary->path.origin.id;
  154. lsa_header->adv_router = area->ospf6->router_id;
  155. lsa_header->seqnum =
  156. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  157. lsa_header->adv_router, area->lsdb);
  158. lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
  159. /* LSA checksum */
  160. ospf6_lsa_checksum (lsa_header);
  161. /* create LSA */
  162. lsa = ospf6_lsa_create (lsa_header);
  163. lsa->scope = area;
  164. SET_FLAG (lsa->flag, OSPF6_LSA_REFRESH); /* XXX */
  165. /* Originate */
  166. ospf6_lsa_originate (lsa);
  167. }
  168. void
  169. ospf6_abr_originate_prefix (struct ospf6_route *route, struct ospf6 *o)
  170. {
  171. listnode node;
  172. struct ospf6_area *oa;
  173. for (node = listhead (o->area_list); node; nextnode (node))
  174. {
  175. oa = (struct ospf6_area *) getdata (node);
  176. ospf6_abr_originate_prefix_to_area (route, oa);
  177. }
  178. }
  179. /* RFC 2328 16.2. Calculating the inter-area routes */
  180. void
  181. ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa)
  182. {
  183. struct prefix prefix, abr_prefix;
  184. struct ospf6_route_table *table = NULL;
  185. struct ospf6_route *range, *route, *old = NULL;
  186. struct ospf6_route *abr_entry;
  187. u_char type;
  188. char options[3] = {0, 0, 0};
  189. u_int8_t prefix_options = 0;
  190. u_int32_t cost = 0;
  191. int i;
  192. if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
  193. {
  194. struct ospf6_inter_prefix_lsa *prefix_lsa;
  195. prefix_lsa = (struct ospf6_inter_prefix_lsa *)
  196. OSPF6_LSA_HEADER_END (lsa->header);
  197. prefix.family = AF_INET6;
  198. prefix.prefixlen = prefix_lsa->prefix.prefix_length;
  199. ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
  200. table = oa->ospf6->route_table;
  201. type = OSPF6_DEST_TYPE_NETWORK;
  202. prefix_options = prefix_lsa->prefix.prefix_options;
  203. cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
  204. }
  205. else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
  206. {
  207. struct ospf6_inter_router_lsa *router_lsa;
  208. router_lsa = (struct ospf6_inter_router_lsa *)
  209. OSPF6_LSA_HEADER_END (lsa->header);
  210. ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
  211. table = oa->ospf6->brouter_table;
  212. type = OSPF6_DEST_TYPE_ROUTER;
  213. options[0] = router_lsa->options[0];
  214. options[1] = router_lsa->options[1];
  215. options[2] = router_lsa->options[2];
  216. cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
  217. }
  218. else
  219. assert (0);
  220. for (route = ospf6_route_lookup (&prefix, table);
  221. route && ospf6_route_is_prefix (&prefix, route);
  222. route = ospf6_route_next (route))
  223. {
  224. if (route->path.area_id == oa->area_id &&
  225. route->path.origin.type == lsa->header->type &&
  226. route->path.origin.id == lsa->header->id &&
  227. route->path.origin.adv_router == lsa->header->adv_router)
  228. old = route;
  229. }
  230. /* (1) if cost == LSInfinity or if the LSA is MaxAge */
  231. if (cost == LS_INFINITY || OSPF6_LSA_IS_MAXAGE (lsa))
  232. {
  233. if (old)
  234. ospf6_route_remove (old, oa->ospf6->route_table);
  235. return;
  236. }
  237. /* (2) if the LSA is self-originated, ignore */
  238. if (lsa->header->adv_router == oa->ospf6->router_id)
  239. {
  240. if (old)
  241. ospf6_route_remove (old, oa->ospf6->route_table);
  242. return;
  243. }
  244. /* (3) if the prefix is equal to an active configured address range */
  245. range = ospf6_route_lookup (&prefix, oa->summary_table);
  246. if (range && CHECK_FLAG (range->flag, OSPF6_ROUTE_HAVE_LONGER))
  247. {
  248. if (old)
  249. ospf6_route_remove (old, oa->ospf6->route_table);
  250. return;
  251. }
  252. /* (4) if the routing table entry for the ABR does not exist */
  253. ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
  254. abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
  255. if (abr_entry == NULL)
  256. {
  257. if (old)
  258. ospf6_route_remove (old, oa->ospf6->route_table);
  259. return;
  260. }
  261. /* (5),(6),(7) the path preference is handled by the sorting
  262. in the routing table. Always install the path by substituting
  263. old route (if any). */
  264. if (old)
  265. route = old;
  266. else
  267. route = ospf6_route_create ();
  268. route->type = type;
  269. route->prefix = prefix;
  270. route->path.origin.type = lsa->header->type;
  271. route->path.origin.id = lsa->header->id;
  272. route->path.origin.adv_router = lsa->header->adv_router;
  273. route->path.options[0] = options[0];
  274. route->path.options[1] = options[1];
  275. route->path.options[2] = options[2];
  276. route->path.prefix_options = prefix_options;
  277. route->path.area_id = oa->area_id;
  278. route->path.type = OSPF6_PATH_TYPE_INTER;
  279. route->path.cost = abr_entry->path.cost + cost;
  280. for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
  281. route->nexthop[i] = abr_entry->nexthop[i];
  282. ospf6_route_add (route, table);
  283. }
  284. int
  285. dummy (struct ospf6_lsa *lsa)
  286. {
  287. }
  288. /* Display functions */
  289. int
  290. ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  291. {
  292. struct ospf6_inter_prefix_lsa *prefix_lsa;
  293. struct in6_addr in6;
  294. char buf[64];
  295. prefix_lsa = (struct ospf6_inter_prefix_lsa *)
  296. OSPF6_LSA_HEADER_END (lsa->header);
  297. vty_out (vty, " Metric: %lu%s",
  298. (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
  299. ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
  300. buf, sizeof (buf));
  301. vty_out (vty, " Prefix Options: %s%s", buf, VNL);
  302. ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
  303. inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
  304. vty_out (vty, " Prefix: %s/%d%s", buf,
  305. prefix_lsa->prefix.prefix_length, VNL);
  306. return 0;
  307. }
  308. int
  309. ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  310. {
  311. struct ospf6_inter_router_lsa *router_lsa;
  312. char buf[64];
  313. router_lsa = (struct ospf6_inter_router_lsa *)
  314. OSPF6_LSA_HEADER_END (lsa->header);
  315. ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
  316. vty_out (vty, " Options: %s%s", buf, VNL);
  317. vty_out (vty, " Metric: %lu%s",
  318. (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
  319. inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
  320. vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
  321. return 0;
  322. }
  323. /* Debug commands */
  324. DEFUN (debug_ospf6_abr,
  325. debug_ospf6_abr_cmd,
  326. "debug ospf6 abr",
  327. DEBUG_STR
  328. OSPF6_STR
  329. "Debug OSPFv3 ABR function\n"
  330. )
  331. {
  332. OSPF6_DEBUG_ABR_ON ();
  333. return CMD_SUCCESS;
  334. }
  335. DEFUN (no_debug_ospf6_abr,
  336. no_debug_ospf6_abr_cmd,
  337. "no debug ospf6 abr",
  338. NO_STR
  339. DEBUG_STR
  340. OSPF6_STR
  341. "Debug OSPFv3 ABR function\n"
  342. )
  343. {
  344. OSPF6_DEBUG_ABR_OFF ();
  345. return CMD_SUCCESS;
  346. }
  347. int
  348. config_write_ospf6_debug_abr (struct vty *vty)
  349. {
  350. if (IS_OSPF6_DEBUG_ABR)
  351. vty_out (vty, "debug ospf6 abr%s", VNL);
  352. return 0;
  353. }
  354. void
  355. install_element_ospf6_debug_abr ()
  356. {
  357. install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
  358. install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
  359. install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
  360. install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
  361. }
  362. void
  363. ospf6_abr_init ()
  364. {
  365. ospf6_lstype[3].name = "Inter-Area-Prefix-LSA";
  366. ospf6_lstype[3].reoriginate = dummy;
  367. ospf6_lstype[3].show = ospf6_inter_area_prefix_lsa_show;
  368. ospf6_lstype[4].name = "Inter-Area-Router-LSA";
  369. ospf6_lstype[4].reoriginate = dummy;
  370. ospf6_lstype[4].show = ospf6_inter_area_router_lsa_show;
  371. }