ospf6_intra.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  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 "linklist.h"
  24. #include "thread.h"
  25. #include "memory.h"
  26. #include "if.h"
  27. #include "prefix.h"
  28. #include "table.h"
  29. #include "vty.h"
  30. #include "command.h"
  31. #include "ospf6_proto.h"
  32. #include "ospf6_message.h"
  33. #include "ospf6_route.h"
  34. #include "ospf6_lsa.h"
  35. #include "ospf6_lsdb.h"
  36. #include "ospf6_top.h"
  37. #include "ospf6_area.h"
  38. #include "ospf6_interface.h"
  39. #include "ospf6_neighbor.h"
  40. #include "ospf6_intra.h"
  41. #include "ospf6_asbr.h"
  42. #include "ospf6_abr.h"
  43. #include "ospf6_flood.h"
  44. #include "ospf6d.h"
  45. #include "ospf6_spf.h"
  46. unsigned char conf_debug_ospf6_brouter = 0;
  47. u_int32_t conf_debug_ospf6_brouter_specific_router_id;
  48. u_int32_t conf_debug_ospf6_brouter_specific_area_id;
  49. /******************************/
  50. /* RFC2740 3.4.3.1 Router-LSA */
  51. /******************************/
  52. static char *
  53. ospf6_router_lsa_get_nbr_id (struct ospf6_lsa *lsa, char *buf, int buflen,
  54. int pos)
  55. {
  56. struct ospf6_router_lsa *router_lsa;
  57. struct ospf6_router_lsdesc *lsdesc;
  58. char *start, *end;
  59. char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
  60. if (lsa)
  61. {
  62. router_lsa = (struct ospf6_router_lsa *)
  63. ((char *) lsa->header + sizeof (struct ospf6_lsa_header));
  64. start = (char *) router_lsa + sizeof (struct ospf6_router_lsa);
  65. end = (char *) lsa->header + ntohs (lsa->header->length);
  66. lsdesc = (struct ospf6_router_lsdesc *)
  67. (start + pos*(sizeof (struct ospf6_router_lsdesc)));
  68. if ((char *)lsdesc < end)
  69. {
  70. if (buf && (buflen > INET_ADDRSTRLEN*2))
  71. {
  72. inet_ntop (AF_INET, &lsdesc->neighbor_interface_id,
  73. buf1, sizeof(buf1));
  74. inet_ntop (AF_INET, &lsdesc->neighbor_router_id,
  75. buf2, sizeof(buf2));
  76. sprintf (buf, "%s/%s", buf2, buf1);
  77. }
  78. }
  79. else
  80. return NULL;
  81. }
  82. return buf;
  83. }
  84. static int
  85. ospf6_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  86. {
  87. char *start, *end, *current;
  88. char buf[32], name[32], bits[16], options[32];
  89. struct ospf6_router_lsa *router_lsa;
  90. struct ospf6_router_lsdesc *lsdesc;
  91. router_lsa = (struct ospf6_router_lsa *)
  92. ((char *) lsa->header + sizeof (struct ospf6_lsa_header));
  93. ospf6_capability_printbuf (router_lsa->bits, bits, sizeof (bits));
  94. ospf6_options_printbuf (router_lsa->options, options, sizeof (options));
  95. vty_out (vty, " Bits: %s Options: %s%s", bits, options, VNL);
  96. start = (char *) router_lsa + sizeof (struct ospf6_router_lsa);
  97. end = (char *) lsa->header + ntohs (lsa->header->length);
  98. for (current = start; current + sizeof (struct ospf6_router_lsdesc) <= end;
  99. current += sizeof (struct ospf6_router_lsdesc))
  100. {
  101. lsdesc = (struct ospf6_router_lsdesc *) current;
  102. if (lsdesc->type == OSPF6_ROUTER_LSDESC_POINTTOPOINT)
  103. snprintf (name, sizeof (name), "Point-To-Point");
  104. else if (lsdesc->type == OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK)
  105. snprintf (name, sizeof (name), "Transit-Network");
  106. else if (lsdesc->type == OSPF6_ROUTER_LSDESC_STUB_NETWORK)
  107. snprintf (name, sizeof (name), "Stub-Network");
  108. else if (lsdesc->type == OSPF6_ROUTER_LSDESC_VIRTUAL_LINK)
  109. snprintf (name, sizeof (name), "Virtual-Link");
  110. else
  111. snprintf (name, sizeof (name), "Unknown (%#x)", lsdesc->type);
  112. vty_out (vty, " Type: %s Metric: %d%s",
  113. name, ntohs (lsdesc->metric), VNL);
  114. vty_out (vty, " Interface ID: %s%s",
  115. inet_ntop (AF_INET, &lsdesc->interface_id,
  116. buf, sizeof (buf)), VNL);
  117. vty_out (vty, " Neighbor Interface ID: %s%s",
  118. inet_ntop (AF_INET, &lsdesc->neighbor_interface_id,
  119. buf, sizeof (buf)), VNL);
  120. vty_out (vty, " Neighbor Router ID: %s%s",
  121. inet_ntop (AF_INET, &lsdesc->neighbor_router_id,
  122. buf, sizeof (buf)), VNL);
  123. }
  124. return 0;
  125. }
  126. int
  127. ospf6_router_is_stub_router (struct ospf6_lsa *lsa)
  128. {
  129. struct ospf6_router_lsa *rtr_lsa;
  130. if (lsa != NULL && OSPF6_LSA_IS_TYPE (ROUTER, lsa))
  131. {
  132. rtr_lsa = (struct ospf6_router_lsa *)
  133. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  134. if (!OSPF6_OPT_ISSET (rtr_lsa->options, OSPF6_OPT_R))
  135. {
  136. return (OSPF6_IS_STUB_ROUTER);
  137. }
  138. else if (!OSPF6_OPT_ISSET (rtr_lsa->options, OSPF6_OPT_V6))
  139. {
  140. return (OSPF6_IS_STUB_ROUTER_V6);
  141. }
  142. }
  143. return (OSPF6_NOT_STUB_ROUTER);
  144. }
  145. int
  146. ospf6_router_lsa_originate (struct thread *thread)
  147. {
  148. struct ospf6_area *oa;
  149. char buffer [OSPF6_MAX_LSASIZE];
  150. struct ospf6_lsa_header *lsa_header;
  151. struct ospf6_lsa *lsa;
  152. u_int32_t link_state_id = 0;
  153. struct listnode *node, *nnode;
  154. struct listnode *j;
  155. struct ospf6_interface *oi;
  156. struct ospf6_neighbor *on, *drouter = NULL;
  157. struct ospf6_router_lsa *router_lsa;
  158. struct ospf6_router_lsdesc *lsdesc;
  159. u_int16_t type;
  160. u_int32_t router;
  161. int count;
  162. oa = (struct ospf6_area *) THREAD_ARG (thread);
  163. oa->thread_router_lsa = NULL;
  164. if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
  165. zlog_debug ("Originate Router-LSA for Area %s", oa->name);
  166. memset (buffer, 0, sizeof (buffer));
  167. lsa_header = (struct ospf6_lsa_header *) buffer;
  168. router_lsa = (struct ospf6_router_lsa *)
  169. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  170. OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_V6);
  171. OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_E);
  172. OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_MC);
  173. OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_N);
  174. OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_R);
  175. OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_DC);
  176. if (ospf6_is_router_abr (ospf6))
  177. SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
  178. else
  179. UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
  180. if (ospf6_asbr_is_asbr (ospf6))
  181. SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
  182. else
  183. UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
  184. UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_V);
  185. UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_W);
  186. /* describe links for each interfaces */
  187. lsdesc = (struct ospf6_router_lsdesc *)
  188. ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
  189. for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
  190. {
  191. /* Interfaces in state Down or Loopback are not described */
  192. if (oi->state == OSPF6_INTERFACE_DOWN ||
  193. oi->state == OSPF6_INTERFACE_LOOPBACK)
  194. continue;
  195. /* Nor are interfaces without any full adjacencies described */
  196. count = 0;
  197. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
  198. if (on->state == OSPF6_NEIGHBOR_FULL)
  199. count++;
  200. if (count == 0)
  201. continue;
  202. /* Multiple Router-LSA instance according to size limit setting */
  203. if ( (oa->router_lsa_size_limit != 0)
  204. && ((size_t)((char *)lsdesc - buffer)
  205. + sizeof (struct ospf6_router_lsdesc)
  206. > oa->router_lsa_size_limit))
  207. {
  208. if ((caddr_t) lsdesc == (caddr_t) router_lsa +
  209. sizeof (struct ospf6_router_lsa))
  210. {
  211. if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
  212. zlog_debug ("Size limit setting for Router-LSA too short");
  213. return 0;
  214. }
  215. link_state_id ++;
  216. }
  217. /* Point-to-Point interfaces */
  218. if (oi->type == OSPF_IFTYPE_POINTOPOINT)
  219. {
  220. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
  221. {
  222. if (on->state != OSPF6_NEIGHBOR_FULL)
  223. continue;
  224. lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT;
  225. lsdesc->metric = htons (oi->cost);
  226. lsdesc->interface_id = htonl (oi->interface->ifindex);
  227. lsdesc->neighbor_interface_id = htonl (on->ifindex);
  228. lsdesc->neighbor_router_id = on->router_id;
  229. lsdesc++;
  230. }
  231. }
  232. /* Broadcast and NBMA interfaces */
  233. else if (oi->type == OSPF_IFTYPE_BROADCAST)
  234. {
  235. /* If this router is not DR,
  236. and If this router not fully adjacent with DR,
  237. this interface is not transit yet: ignore. */
  238. if (oi->state != OSPF6_INTERFACE_DR)
  239. {
  240. drouter = ospf6_neighbor_lookup (oi->drouter, oi);
  241. if (drouter == NULL || drouter->state != OSPF6_NEIGHBOR_FULL)
  242. continue;
  243. }
  244. lsdesc->type = OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK;
  245. lsdesc->metric = htons (oi->cost);
  246. lsdesc->interface_id = htonl (oi->interface->ifindex);
  247. if (oi->state != OSPF6_INTERFACE_DR)
  248. {
  249. lsdesc->neighbor_interface_id = htonl (drouter->ifindex);
  250. lsdesc->neighbor_router_id = drouter->router_id;
  251. }
  252. else
  253. {
  254. lsdesc->neighbor_interface_id = htonl (oi->interface->ifindex);
  255. lsdesc->neighbor_router_id = oi->area->ospf6->router_id;
  256. }
  257. lsdesc++;
  258. }
  259. else
  260. {
  261. assert (0); /* Unknown interface type */
  262. }
  263. /* Virtual links */
  264. /* xxx */
  265. /* Point-to-Multipoint interfaces */
  266. /* xxx */
  267. }
  268. /* Fill LSA Header */
  269. lsa_header->age = 0;
  270. lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
  271. lsa_header->id = htonl (link_state_id);
  272. lsa_header->adv_router = oa->ospf6->router_id;
  273. lsa_header->seqnum =
  274. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  275. lsa_header->adv_router, oa->lsdb);
  276. lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
  277. /* LSA checksum */
  278. ospf6_lsa_checksum (lsa_header);
  279. /* create LSA */
  280. lsa = ospf6_lsa_create (lsa_header);
  281. /* Originate */
  282. ospf6_lsa_originate_area (lsa, oa);
  283. link_state_id ++;
  284. /* Do premature-aging of rest, undesired Router-LSAs */
  285. type = ntohs (OSPF6_LSTYPE_ROUTER);
  286. router = oa->ospf6->router_id;
  287. for (lsa = ospf6_lsdb_type_router_head (type, router, oa->lsdb); lsa;
  288. lsa = ospf6_lsdb_type_router_next (type, router, lsa))
  289. {
  290. if (ntohl (lsa->header->id) < link_state_id)
  291. continue;
  292. ospf6_lsa_purge (lsa);
  293. }
  294. return 0;
  295. }
  296. /*******************************/
  297. /* RFC2740 3.4.3.2 Network-LSA */
  298. /*******************************/
  299. static char *
  300. ospf6_network_lsa_get_ar_id (struct ospf6_lsa *lsa, char *buf, int buflen,
  301. int pos)
  302. {
  303. char *start, *end, *current;
  304. struct ospf6_network_lsa *network_lsa;
  305. struct ospf6_network_lsdesc *lsdesc;
  306. if (lsa)
  307. {
  308. network_lsa = (struct ospf6_network_lsa *)
  309. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  310. start = (char *) network_lsa + sizeof (struct ospf6_network_lsa);
  311. end = (char *) lsa->header + ntohs (lsa->header->length);
  312. current = start + pos*(sizeof (struct ospf6_network_lsdesc));
  313. if ((current + sizeof(struct ospf6_network_lsdesc)) <= end)
  314. {
  315. lsdesc = (struct ospf6_network_lsdesc *)current;
  316. if (buf)
  317. inet_ntop (AF_INET, &lsdesc->router_id, buf, buflen);
  318. }
  319. else
  320. return NULL;
  321. }
  322. return (buf);
  323. }
  324. static int
  325. ospf6_network_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  326. {
  327. char *start, *end, *current;
  328. struct ospf6_network_lsa *network_lsa;
  329. struct ospf6_network_lsdesc *lsdesc;
  330. char buf[128], options[32];
  331. network_lsa = (struct ospf6_network_lsa *)
  332. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  333. ospf6_options_printbuf (network_lsa->options, options, sizeof (options));
  334. vty_out (vty, " Options: %s%s", options, VNL);
  335. start = (char *) network_lsa + sizeof (struct ospf6_network_lsa);
  336. end = (char *) lsa->header + ntohs (lsa->header->length);
  337. for (current = start; current + sizeof (struct ospf6_network_lsdesc) <= end;
  338. current += sizeof (struct ospf6_network_lsdesc))
  339. {
  340. lsdesc = (struct ospf6_network_lsdesc *) current;
  341. inet_ntop (AF_INET, &lsdesc->router_id, buf, sizeof (buf));
  342. vty_out (vty, " Attached Router: %s%s", buf, VNL);
  343. }
  344. return 0;
  345. }
  346. int
  347. ospf6_network_lsa_originate (struct thread *thread)
  348. {
  349. struct ospf6_interface *oi;
  350. char buffer [OSPF6_MAX_LSASIZE];
  351. struct ospf6_lsa_header *lsa_header;
  352. int count;
  353. struct ospf6_lsa *old, *lsa;
  354. struct ospf6_network_lsa *network_lsa;
  355. struct ospf6_network_lsdesc *lsdesc;
  356. struct ospf6_neighbor *on;
  357. struct ospf6_link_lsa *link_lsa;
  358. struct listnode *i;
  359. u_int16_t type;
  360. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  361. oi->thread_network_lsa = NULL;
  362. /* The interface must be enabled until here. A Network-LSA of a
  363. disabled interface (but was once enabled) should be flushed
  364. by ospf6_lsa_refresh (), and does not come here. */
  365. assert (oi->area);
  366. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK),
  367. htonl (oi->interface->ifindex),
  368. oi->area->ospf6->router_id, oi->area->lsdb);
  369. /* Do not originate Network-LSA if not DR */
  370. if (oi->state != OSPF6_INTERFACE_DR)
  371. {
  372. if (old)
  373. ospf6_lsa_purge (old);
  374. return 0;
  375. }
  376. if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
  377. zlog_debug ("Originate Network-LSA for Interface %s", oi->interface->name);
  378. /* If none of neighbor is adjacent to us */
  379. count = 0;
  380. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
  381. if (on->state == OSPF6_NEIGHBOR_FULL)
  382. count++;
  383. if (count == 0)
  384. {
  385. if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
  386. zlog_debug ("Interface stub, ignore");
  387. if (old)
  388. ospf6_lsa_purge (old);
  389. return 0;
  390. }
  391. /* prepare buffer */
  392. memset (buffer, 0, sizeof (buffer));
  393. lsa_header = (struct ospf6_lsa_header *) buffer;
  394. network_lsa = (struct ospf6_network_lsa *)
  395. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  396. /* Collect the interface's Link-LSAs to describe
  397. network's optional capabilities */
  398. type = htons (OSPF6_LSTYPE_LINK);
  399. for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
  400. lsa = ospf6_lsdb_type_next (type, lsa))
  401. {
  402. link_lsa = (struct ospf6_link_lsa *)
  403. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  404. network_lsa->options[0] |= link_lsa->options[0];
  405. network_lsa->options[1] |= link_lsa->options[1];
  406. network_lsa->options[2] |= link_lsa->options[2];
  407. }
  408. lsdesc = (struct ospf6_network_lsdesc *)
  409. ((caddr_t) network_lsa + sizeof (struct ospf6_network_lsa));
  410. /* set Link Description to the router itself */
  411. lsdesc->router_id = oi->area->ospf6->router_id;
  412. lsdesc++;
  413. /* Walk through the neighbors */
  414. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
  415. {
  416. if (on->state != OSPF6_NEIGHBOR_FULL)
  417. continue;
  418. /* set this neighbor's Router-ID to LSA */
  419. lsdesc->router_id = on->router_id;
  420. lsdesc++;
  421. }
  422. /* Fill LSA Header */
  423. lsa_header->age = 0;
  424. lsa_header->type = htons (OSPF6_LSTYPE_NETWORK);
  425. lsa_header->id = htonl (oi->interface->ifindex);
  426. lsa_header->adv_router = oi->area->ospf6->router_id;
  427. lsa_header->seqnum =
  428. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  429. lsa_header->adv_router, oi->area->lsdb);
  430. lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
  431. /* LSA checksum */
  432. ospf6_lsa_checksum (lsa_header);
  433. /* create LSA */
  434. lsa = ospf6_lsa_create (lsa_header);
  435. /* Originate */
  436. ospf6_lsa_originate_area (lsa, oi->area);
  437. return 0;
  438. }
  439. /****************************/
  440. /* RFC2740 3.4.3.6 Link-LSA */
  441. /****************************/
  442. static char *
  443. ospf6_link_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf, int buflen,
  444. int pos)
  445. {
  446. char *start, *end, *current;
  447. struct ospf6_link_lsa *link_lsa;
  448. struct in6_addr in6;
  449. struct ospf6_prefix *prefix;
  450. int cnt = 0, prefixnum;
  451. if (lsa)
  452. {
  453. link_lsa = (struct ospf6_link_lsa *)
  454. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  455. if (pos == 0) {
  456. inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, buflen);
  457. return (buf);
  458. }
  459. prefixnum = ntohl (link_lsa->prefix_num);
  460. if (pos > prefixnum)
  461. return (NULL);
  462. start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
  463. end = (char *) lsa->header + ntohs (lsa->header->length);
  464. current = start;
  465. do
  466. {
  467. prefix = (struct ospf6_prefix *) current;
  468. if (prefix->prefix_length == 0 ||
  469. current + OSPF6_PREFIX_SIZE (prefix) > end)
  470. {
  471. return (NULL);
  472. }
  473. if (cnt < pos)
  474. {
  475. current = start + pos*OSPF6_PREFIX_SIZE(prefix);
  476. cnt++;
  477. }
  478. else
  479. {
  480. memset (&in6, 0, sizeof (in6));
  481. memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
  482. OSPF6_PREFIX_SPACE (prefix->prefix_length));
  483. inet_ntop (AF_INET6, &in6, buf, buflen);
  484. return (buf);
  485. }
  486. } while (current <= end);
  487. }
  488. return (NULL);
  489. }
  490. static int
  491. ospf6_link_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  492. {
  493. char *start, *end, *current;
  494. struct ospf6_link_lsa *link_lsa;
  495. int prefixnum;
  496. char buf[128], options[32];
  497. struct ospf6_prefix *prefix;
  498. const char *p, *mc, *la, *nu;
  499. struct in6_addr in6;
  500. link_lsa = (struct ospf6_link_lsa *)
  501. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  502. ospf6_options_printbuf (link_lsa->options, options, sizeof (options));
  503. inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf));
  504. prefixnum = ntohl (link_lsa->prefix_num);
  505. vty_out (vty, " Priority: %d Options: %s%s",
  506. link_lsa->priority, options, VNL);
  507. vty_out (vty, " LinkLocal Address: %s%s", buf, VNL);
  508. vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
  509. start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
  510. end = (char *) lsa->header + ntohs (lsa->header->length);
  511. for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
  512. {
  513. prefix = (struct ospf6_prefix *) current;
  514. if (prefix->prefix_length == 0 ||
  515. current + OSPF6_PREFIX_SIZE (prefix) > end)
  516. break;
  517. p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
  518. "P" : "--");
  519. mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
  520. "MC" : "--");
  521. la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
  522. "LA" : "--");
  523. nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
  524. "NU" : "--");
  525. vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
  526. p, mc, la, nu, VNL);
  527. memset (&in6, 0, sizeof (in6));
  528. memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
  529. OSPF6_PREFIX_SPACE (prefix->prefix_length));
  530. inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
  531. vty_out (vty, " Prefix: %s/%d%s",
  532. buf, prefix->prefix_length, VNL);
  533. }
  534. return 0;
  535. }
  536. int
  537. ospf6_link_lsa_originate (struct thread *thread)
  538. {
  539. struct ospf6_interface *oi;
  540. char buffer[OSPF6_MAX_LSASIZE];
  541. struct ospf6_lsa_header *lsa_header;
  542. struct ospf6_lsa *old, *lsa;
  543. struct ospf6_link_lsa *link_lsa;
  544. struct ospf6_route *route;
  545. struct ospf6_prefix *op;
  546. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  547. oi->thread_link_lsa = NULL;
  548. assert (oi->area);
  549. /* find previous LSA */
  550. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK),
  551. htonl (oi->interface->ifindex),
  552. oi->area->ospf6->router_id, oi->lsdb);
  553. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
  554. {
  555. if (old)
  556. ospf6_lsa_purge (old);
  557. return 0;
  558. }
  559. if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
  560. zlog_debug ("Originate Link-LSA for Interface %s", oi->interface->name);
  561. /* can't make Link-LSA if linklocal address not set */
  562. if (oi->linklocal_addr == NULL)
  563. {
  564. if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
  565. zlog_debug ("No Linklocal address on %s, defer originating",
  566. oi->interface->name);
  567. if (old)
  568. ospf6_lsa_purge (old);
  569. return 0;
  570. }
  571. /* prepare buffer */
  572. memset (buffer, 0, sizeof (buffer));
  573. lsa_header = (struct ospf6_lsa_header *) buffer;
  574. link_lsa = (struct ospf6_link_lsa *)
  575. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  576. /* Fill Link-LSA */
  577. link_lsa->priority = oi->priority;
  578. memcpy (link_lsa->options, oi->area->options, 3);
  579. memcpy (&link_lsa->linklocal_addr, oi->linklocal_addr,
  580. sizeof (struct in6_addr));
  581. link_lsa->prefix_num = htonl (oi->route_connected->count);
  582. op = (struct ospf6_prefix *)
  583. ((caddr_t) link_lsa + sizeof (struct ospf6_link_lsa));
  584. /* connected prefix to advertise */
  585. for (route = ospf6_route_head (oi->route_connected); route;
  586. route = ospf6_route_next (route))
  587. {
  588. op->prefix_length = route->prefix.prefixlen;
  589. op->prefix_options = route->path.prefix_options;
  590. op->prefix_metric = htons (0);
  591. memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
  592. OSPF6_PREFIX_SPACE (op->prefix_length));
  593. op = OSPF6_PREFIX_NEXT (op);
  594. }
  595. /* Fill LSA Header */
  596. lsa_header->age = 0;
  597. lsa_header->type = htons (OSPF6_LSTYPE_LINK);
  598. lsa_header->id = htonl (oi->interface->ifindex);
  599. lsa_header->adv_router = oi->area->ospf6->router_id;
  600. lsa_header->seqnum =
  601. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  602. lsa_header->adv_router, oi->lsdb);
  603. lsa_header->length = htons ((caddr_t) op - (caddr_t) buffer);
  604. /* LSA checksum */
  605. ospf6_lsa_checksum (lsa_header);
  606. /* create LSA */
  607. lsa = ospf6_lsa_create (lsa_header);
  608. /* Originate */
  609. ospf6_lsa_originate_interface (lsa, oi);
  610. return 0;
  611. }
  612. /*****************************************/
  613. /* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
  614. /*****************************************/
  615. static char *
  616. ospf6_intra_prefix_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
  617. int buflen, int pos)
  618. {
  619. char *start, *end, *current;
  620. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  621. struct in6_addr in6;
  622. int prefixnum, cnt = 0;
  623. struct ospf6_prefix *prefix;
  624. if (lsa)
  625. {
  626. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  627. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  628. prefixnum = ntohs (intra_prefix_lsa->prefix_num);
  629. if (pos > prefixnum)
  630. return (NULL);
  631. start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa);
  632. end = (char *) lsa->header + ntohs (lsa->header->length);
  633. current = start;
  634. do
  635. {
  636. prefix = (struct ospf6_prefix *) current;
  637. if (prefix->prefix_length == 0 ||
  638. current + OSPF6_PREFIX_SIZE (prefix) > end)
  639. {
  640. return NULL;
  641. }
  642. if (cnt < pos)
  643. {
  644. current = start + pos*OSPF6_PREFIX_SIZE(prefix);
  645. cnt++;
  646. }
  647. else
  648. {
  649. memset (&in6, 0, sizeof (in6));
  650. memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
  651. OSPF6_PREFIX_SPACE (prefix->prefix_length));
  652. inet_ntop (AF_INET6, &in6, buf, buflen);
  653. sprintf(&buf[strlen(buf)], "/%d", prefix->prefix_length);
  654. return (buf);
  655. }
  656. } while (current <= end);
  657. }
  658. return (buf);
  659. }
  660. static int
  661. ospf6_intra_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
  662. {
  663. char *start, *end, *current;
  664. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  665. int prefixnum;
  666. char buf[128];
  667. struct ospf6_prefix *prefix;
  668. char id[16], adv_router[16];
  669. const char *p, *mc, *la, *nu;
  670. struct in6_addr in6;
  671. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  672. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  673. prefixnum = ntohs (intra_prefix_lsa->prefix_num);
  674. vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
  675. inet_ntop (AF_INET, &intra_prefix_lsa->ref_id, id, sizeof (id));
  676. inet_ntop (AF_INET, &intra_prefix_lsa->ref_adv_router,
  677. adv_router, sizeof (adv_router));
  678. vty_out (vty, " Reference: %s Id: %s Adv: %s%s",
  679. ospf6_lstype_name (intra_prefix_lsa->ref_type), id, adv_router,
  680. VNL);
  681. start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa);
  682. end = (char *) lsa->header + ntohs (lsa->header->length);
  683. for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
  684. {
  685. prefix = (struct ospf6_prefix *) current;
  686. if (prefix->prefix_length == 0 ||
  687. current + OSPF6_PREFIX_SIZE (prefix) > end)
  688. break;
  689. p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
  690. "P" : "--");
  691. mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
  692. "MC" : "--");
  693. la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
  694. "LA" : "--");
  695. nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
  696. "NU" : "--");
  697. vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
  698. p, mc, la, nu, VNL);
  699. memset (&in6, 0, sizeof (in6));
  700. memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
  701. OSPF6_PREFIX_SPACE (prefix->prefix_length));
  702. inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
  703. vty_out (vty, " Prefix: %s/%d%s",
  704. buf, prefix->prefix_length, VNL);
  705. }
  706. return 0;
  707. }
  708. int
  709. ospf6_intra_prefix_lsa_originate_stub (struct thread *thread)
  710. {
  711. struct ospf6_area *oa;
  712. char buffer[OSPF6_MAX_LSASIZE];
  713. struct ospf6_lsa_header *lsa_header;
  714. struct ospf6_lsa *old, *lsa;
  715. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  716. struct ospf6_interface *oi;
  717. struct ospf6_neighbor *on;
  718. struct ospf6_route *route;
  719. struct ospf6_prefix *op;
  720. struct listnode *i, *j;
  721. int full_count = 0;
  722. unsigned short prefix_num = 0;
  723. char buf[BUFSIZ];
  724. struct ospf6_route_table *route_advertise;
  725. oa = (struct ospf6_area *) THREAD_ARG (thread);
  726. oa->thread_intra_prefix_lsa = NULL;
  727. /* find previous LSA */
  728. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
  729. htonl (0), oa->ospf6->router_id, oa->lsdb);
  730. if (! IS_AREA_ENABLED (oa))
  731. {
  732. if (old)
  733. ospf6_lsa_purge (old);
  734. return 0;
  735. }
  736. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  737. zlog_debug ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
  738. oa->name);
  739. /* prepare buffer */
  740. memset (buffer, 0, sizeof (buffer));
  741. lsa_header = (struct ospf6_lsa_header *) buffer;
  742. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  743. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  744. /* Fill Intra-Area-Prefix-LSA */
  745. intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_ROUTER);
  746. intra_prefix_lsa->ref_id = htonl (0);
  747. intra_prefix_lsa->ref_adv_router = oa->ospf6->router_id;
  748. route_advertise = ospf6_route_table_create (0, 0);
  749. for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi))
  750. {
  751. if (oi->state == OSPF6_INTERFACE_DOWN)
  752. {
  753. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  754. zlog_debug (" Interface %s is down, ignore", oi->interface->name);
  755. continue;
  756. }
  757. full_count = 0;
  758. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
  759. if (on->state == OSPF6_NEIGHBOR_FULL)
  760. full_count++;
  761. if (oi->state != OSPF6_INTERFACE_LOOPBACK &&
  762. oi->state != OSPF6_INTERFACE_POINTTOPOINT &&
  763. full_count != 0)
  764. {
  765. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  766. zlog_debug (" Interface %s is not stub, ignore",
  767. oi->interface->name);
  768. continue;
  769. }
  770. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  771. zlog_debug (" Interface %s:", oi->interface->name);
  772. /* connected prefix to advertise */
  773. for (route = ospf6_route_head (oi->route_connected); route;
  774. route = ospf6_route_best_next (route))
  775. {
  776. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  777. {
  778. prefix2str (&route->prefix, buf, sizeof (buf));
  779. zlog_debug (" include %s", buf);
  780. }
  781. ospf6_route_add (ospf6_route_copy (route), route_advertise);
  782. }
  783. }
  784. if (route_advertise->count == 0)
  785. {
  786. if (old)
  787. ospf6_lsa_purge (old);
  788. ospf6_route_table_delete (route_advertise);
  789. return 0;
  790. }
  791. /* put prefixes to advertise */
  792. prefix_num = 0;
  793. op = (struct ospf6_prefix *)
  794. ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
  795. for (route = ospf6_route_head (route_advertise); route;
  796. route = ospf6_route_best_next (route))
  797. {
  798. op->prefix_length = route->prefix.prefixlen;
  799. op->prefix_options = route->path.prefix_options;
  800. op->prefix_metric = htons (route->path.cost);
  801. memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
  802. OSPF6_PREFIX_SPACE (op->prefix_length));
  803. op = OSPF6_PREFIX_NEXT (op);
  804. prefix_num++;
  805. }
  806. ospf6_route_table_delete (route_advertise);
  807. if (prefix_num == 0)
  808. {
  809. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  810. zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
  811. return 0;
  812. }
  813. intra_prefix_lsa->prefix_num = htons (prefix_num);
  814. /* Fill LSA Header */
  815. lsa_header->age = 0;
  816. lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
  817. lsa_header->id = htonl (0);
  818. lsa_header->adv_router = oa->ospf6->router_id;
  819. lsa_header->seqnum =
  820. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  821. lsa_header->adv_router, oa->lsdb);
  822. lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
  823. /* LSA checksum */
  824. ospf6_lsa_checksum (lsa_header);
  825. /* create LSA */
  826. lsa = ospf6_lsa_create (lsa_header);
  827. /* Originate */
  828. ospf6_lsa_originate_area (lsa, oa);
  829. return 0;
  830. }
  831. int
  832. ospf6_intra_prefix_lsa_originate_transit (struct thread *thread)
  833. {
  834. struct ospf6_interface *oi;
  835. char buffer[OSPF6_MAX_LSASIZE];
  836. struct ospf6_lsa_header *lsa_header;
  837. struct ospf6_lsa *old, *lsa;
  838. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  839. struct ospf6_neighbor *on;
  840. struct ospf6_route *route;
  841. struct ospf6_prefix *op;
  842. struct listnode *i;
  843. int full_count = 0;
  844. unsigned short prefix_num = 0;
  845. struct ospf6_route_table *route_advertise;
  846. struct ospf6_link_lsa *link_lsa;
  847. char *start, *end, *current;
  848. u_int16_t type;
  849. char buf[BUFSIZ];
  850. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  851. oi->thread_intra_prefix_lsa = NULL;
  852. assert (oi->area);
  853. /* find previous LSA */
  854. old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
  855. htonl (oi->interface->ifindex),
  856. oi->area->ospf6->router_id, oi->area->lsdb);
  857. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
  858. {
  859. if (old)
  860. ospf6_lsa_purge (old);
  861. return 0;
  862. }
  863. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  864. zlog_debug ("Originate Intra-Area-Prefix-LSA for interface %s's prefix",
  865. oi->interface->name);
  866. /* prepare buffer */
  867. memset (buffer, 0, sizeof (buffer));
  868. lsa_header = (struct ospf6_lsa_header *) buffer;
  869. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  870. ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
  871. /* Fill Intra-Area-Prefix-LSA */
  872. intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_NETWORK);
  873. intra_prefix_lsa->ref_id = htonl (oi->interface->ifindex);
  874. intra_prefix_lsa->ref_adv_router = oi->area->ospf6->router_id;
  875. if (oi->state != OSPF6_INTERFACE_DR)
  876. {
  877. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  878. zlog_debug (" Interface is not DR");
  879. if (old)
  880. ospf6_lsa_purge (old);
  881. return 0;
  882. }
  883. full_count = 0;
  884. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
  885. if (on->state == OSPF6_NEIGHBOR_FULL)
  886. full_count++;
  887. if (full_count == 0)
  888. {
  889. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  890. zlog_debug (" Interface is stub");
  891. if (old)
  892. ospf6_lsa_purge (old);
  893. return 0;
  894. }
  895. /* connected prefix to advertise */
  896. route_advertise = ospf6_route_table_create (0, 0);
  897. type = ntohs (OSPF6_LSTYPE_LINK);
  898. for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
  899. lsa = ospf6_lsdb_type_next (type, lsa))
  900. {
  901. if (OSPF6_LSA_IS_MAXAGE (lsa))
  902. continue;
  903. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  904. zlog_debug (" include prefix from %s", lsa->name);
  905. if (lsa->header->adv_router != oi->area->ospf6->router_id)
  906. {
  907. on = ospf6_neighbor_lookup (lsa->header->adv_router, oi);
  908. if (on == NULL || on->state != OSPF6_NEIGHBOR_FULL)
  909. {
  910. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  911. zlog_debug (" Neighbor not found or not Full, ignore");
  912. continue;
  913. }
  914. }
  915. link_lsa = (struct ospf6_link_lsa *)
  916. ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
  917. prefix_num = (unsigned short) ntohl (link_lsa->prefix_num);
  918. start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
  919. end = (char *) lsa->header + ntohs (lsa->header->length);
  920. for (current = start; current < end && prefix_num;
  921. current += OSPF6_PREFIX_SIZE (op))
  922. {
  923. op = (struct ospf6_prefix *) current;
  924. if (op->prefix_length == 0 ||
  925. current + OSPF6_PREFIX_SIZE (op) > end)
  926. break;
  927. route = ospf6_route_create ();
  928. route->type = OSPF6_DEST_TYPE_NETWORK;
  929. route->prefix.family = AF_INET6;
  930. route->prefix.prefixlen = op->prefix_length;
  931. memset (&route->prefix.u.prefix6, 0, sizeof (struct in6_addr));
  932. memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op),
  933. OSPF6_PREFIX_SPACE (op->prefix_length));
  934. route->path.origin.type = lsa->header->type;
  935. route->path.origin.id = lsa->header->id;
  936. route->path.origin.adv_router = lsa->header->adv_router;
  937. route->path.options[0] = link_lsa->options[0];
  938. route->path.options[1] = link_lsa->options[1];
  939. route->path.options[2] = link_lsa->options[2];
  940. route->path.prefix_options = op->prefix_options;
  941. route->path.area_id = oi->area->area_id;
  942. route->path.type = OSPF6_PATH_TYPE_INTRA;
  943. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  944. {
  945. prefix2str (&route->prefix, buf, sizeof (buf));
  946. zlog_debug (" include %s", buf);
  947. }
  948. ospf6_route_add (route, route_advertise);
  949. prefix_num--;
  950. }
  951. if (current != end && IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  952. zlog_debug ("Trailing garbage in %s", lsa->name);
  953. }
  954. op = (struct ospf6_prefix *)
  955. ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
  956. prefix_num = 0;
  957. for (route = ospf6_route_head (route_advertise); route;
  958. route = ospf6_route_best_next (route))
  959. {
  960. op->prefix_length = route->prefix.prefixlen;
  961. op->prefix_options = route->path.prefix_options;
  962. op->prefix_metric = htons (0);
  963. memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
  964. OSPF6_PREFIX_SPACE (op->prefix_length));
  965. op = OSPF6_PREFIX_NEXT (op);
  966. prefix_num++;
  967. }
  968. ospf6_route_table_delete (route_advertise);
  969. if (prefix_num == 0)
  970. {
  971. if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
  972. zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
  973. return 0;
  974. }
  975. intra_prefix_lsa->prefix_num = htons (prefix_num);
  976. /* Fill LSA Header */
  977. lsa_header->age = 0;
  978. lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
  979. lsa_header->id = htonl (oi->interface->ifindex);
  980. lsa_header->adv_router = oi->area->ospf6->router_id;
  981. lsa_header->seqnum =
  982. ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
  983. lsa_header->adv_router, oi->area->lsdb);
  984. lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
  985. /* LSA checksum */
  986. ospf6_lsa_checksum (lsa_header);
  987. /* create LSA */
  988. lsa = ospf6_lsa_create (lsa_header);
  989. /* Originate */
  990. ospf6_lsa_originate_area (lsa, oi->area);
  991. return 0;
  992. }
  993. void
  994. ospf6_intra_prefix_lsa_add (struct ospf6_lsa *lsa)
  995. {
  996. struct ospf6_area *oa;
  997. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  998. struct prefix ls_prefix;
  999. struct ospf6_route *route, *ls_entry;
  1000. int i, prefix_num;
  1001. struct ospf6_prefix *op;
  1002. char *start, *current, *end;
  1003. char buf[64];
  1004. struct interface *ifp;
  1005. int direct_connect = 0;
  1006. if (OSPF6_LSA_IS_MAXAGE (lsa))
  1007. return;
  1008. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1009. zlog_debug ("%s found", lsa->name);
  1010. oa = OSPF6_AREA (lsa->lsdb->data);
  1011. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  1012. OSPF6_LSA_HEADER_END (lsa->header);
  1013. if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_ROUTER))
  1014. ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
  1015. htonl (0), &ls_prefix);
  1016. else if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_NETWORK))
  1017. ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
  1018. intra_prefix_lsa->ref_id, &ls_prefix);
  1019. else
  1020. {
  1021. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1022. zlog_debug ("Unknown reference LS-type: %#hx",
  1023. ntohs (intra_prefix_lsa->ref_type));
  1024. return;
  1025. }
  1026. ls_entry = ospf6_route_lookup (&ls_prefix, oa->spf_table);
  1027. if (ls_entry == NULL)
  1028. {
  1029. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1030. {
  1031. ospf6_linkstate_prefix2str (&ls_prefix, buf, sizeof (buf));
  1032. zlog_debug ("LS entry does not exist: %s", buf);
  1033. }
  1034. return;
  1035. }
  1036. if (intra_prefix_lsa->ref_adv_router == oa->ospf6->router_id)
  1037. {
  1038. /* the intra-prefix are directly connected */
  1039. direct_connect = 1;
  1040. }
  1041. prefix_num = ntohs (intra_prefix_lsa->prefix_num);
  1042. start = (caddr_t) intra_prefix_lsa +
  1043. sizeof (struct ospf6_intra_prefix_lsa);
  1044. end = OSPF6_LSA_END (lsa->header);
  1045. for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
  1046. {
  1047. op = (struct ospf6_prefix *) current;
  1048. if (prefix_num == 0)
  1049. break;
  1050. if (end < current + OSPF6_PREFIX_SIZE (op))
  1051. break;
  1052. /* Appendix A.4.1.1 */
  1053. if (CHECK_FLAG(op->prefix_options, OSPF6_PREFIX_OPTION_NU))
  1054. {
  1055. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1056. {
  1057. ospf6_linkstate_prefix2str ((struct prefix *)OSPF6_PREFIX_BODY(op),
  1058. buf, sizeof (buf));
  1059. zlog_debug ("%s: Skipping Prefix %s has NU option set",
  1060. __func__, buf);
  1061. }
  1062. continue;
  1063. }
  1064. route = ospf6_route_create ();
  1065. memset (&route->prefix, 0, sizeof (struct prefix));
  1066. route->prefix.family = AF_INET6;
  1067. route->prefix.prefixlen = op->prefix_length;
  1068. ospf6_prefix_in6_addr (&route->prefix.u.prefix6, op);
  1069. route->type = OSPF6_DEST_TYPE_NETWORK;
  1070. route->path.origin.type = lsa->header->type;
  1071. route->path.origin.id = lsa->header->id;
  1072. route->path.origin.adv_router = lsa->header->adv_router;
  1073. route->path.prefix_options = op->prefix_options;
  1074. route->path.area_id = oa->area_id;
  1075. route->path.type = OSPF6_PATH_TYPE_INTRA;
  1076. route->path.metric_type = 1;
  1077. route->path.cost = ls_entry->path.cost +
  1078. ntohs (op->prefix_metric);
  1079. if (direct_connect)
  1080. {
  1081. ifp = if_lookup_prefix(&route->prefix);
  1082. if (ifp)
  1083. route->nexthop[0].ifindex = ifp->ifindex;
  1084. }
  1085. else
  1086. {
  1087. for (i = 0; i < OSPF6_MULTI_PATH_LIMIT &&
  1088. ospf6_nexthop_is_set (&ls_entry->nexthop[i]); i++)
  1089. ospf6_nexthop_copy (&route->nexthop[i], &ls_entry->nexthop[i]);
  1090. }
  1091. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1092. {
  1093. prefix2str (&route->prefix, buf, sizeof (buf));
  1094. zlog_debug (" add %s", buf);
  1095. }
  1096. ospf6_route_add (route, oa->route_table);
  1097. prefix_num--;
  1098. }
  1099. if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1100. zlog_debug ("Trailing garbage ignored");
  1101. }
  1102. void
  1103. ospf6_intra_prefix_lsa_remove (struct ospf6_lsa *lsa)
  1104. {
  1105. struct ospf6_area *oa;
  1106. struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
  1107. struct prefix prefix;
  1108. struct ospf6_route *route, *nroute;
  1109. int prefix_num;
  1110. struct ospf6_prefix *op;
  1111. char *start, *current, *end;
  1112. char buf[64];
  1113. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1114. zlog_debug ("%s disappearing", lsa->name);
  1115. oa = OSPF6_AREA (lsa->lsdb->data);
  1116. intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
  1117. OSPF6_LSA_HEADER_END (lsa->header);
  1118. prefix_num = ntohs (intra_prefix_lsa->prefix_num);
  1119. start = (caddr_t) intra_prefix_lsa +
  1120. sizeof (struct ospf6_intra_prefix_lsa);
  1121. end = OSPF6_LSA_END (lsa->header);
  1122. for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
  1123. {
  1124. op = (struct ospf6_prefix *) current;
  1125. if (prefix_num == 0)
  1126. break;
  1127. if (end < current + OSPF6_PREFIX_SIZE (op))
  1128. break;
  1129. prefix_num--;
  1130. memset (&prefix, 0, sizeof (struct prefix));
  1131. prefix.family = AF_INET6;
  1132. prefix.prefixlen = op->prefix_length;
  1133. ospf6_prefix_in6_addr (&prefix.u.prefix6, op);
  1134. route = ospf6_route_lookup (&prefix, oa->route_table);
  1135. if (route == NULL)
  1136. continue;
  1137. for (ospf6_route_lock (route);
  1138. route && ospf6_route_is_prefix (&prefix, route);
  1139. route = nroute)
  1140. {
  1141. nroute = ospf6_route_next (route);
  1142. if (route->type != OSPF6_DEST_TYPE_NETWORK)
  1143. continue;
  1144. if (route->path.area_id != oa->area_id)
  1145. continue;
  1146. if (route->path.type != OSPF6_PATH_TYPE_INTRA)
  1147. continue;
  1148. if (route->path.origin.type != lsa->header->type ||
  1149. route->path.origin.id != lsa->header->id ||
  1150. route->path.origin.adv_router != lsa->header->adv_router)
  1151. continue;
  1152. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1153. {
  1154. prefix2str (&route->prefix, buf, sizeof (buf));
  1155. zlog_debug ("remove %s", buf);
  1156. }
  1157. ospf6_route_remove (route, oa->route_table);
  1158. }
  1159. if (route)
  1160. ospf6_route_unlock (route);
  1161. }
  1162. if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1163. zlog_debug ("Trailing garbage ignored");
  1164. }
  1165. void
  1166. ospf6_intra_route_calculation (struct ospf6_area *oa)
  1167. {
  1168. struct ospf6_route *route, *nroute;
  1169. u_int16_t type;
  1170. struct ospf6_lsa *lsa;
  1171. void (*hook_add) (struct ospf6_route *) = NULL;
  1172. void (*hook_remove) (struct ospf6_route *) = NULL;
  1173. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1174. zlog_debug ("Re-examin intra-routes for area %s", oa->name);
  1175. hook_add = oa->route_table->hook_add;
  1176. hook_remove = oa->route_table->hook_remove;
  1177. oa->route_table->hook_add = NULL;
  1178. oa->route_table->hook_remove = NULL;
  1179. for (route = ospf6_route_head (oa->route_table); route;
  1180. route = ospf6_route_next (route))
  1181. route->flag = OSPF6_ROUTE_REMOVE;
  1182. type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
  1183. for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
  1184. lsa = ospf6_lsdb_type_next (type, lsa))
  1185. ospf6_intra_prefix_lsa_add (lsa);
  1186. oa->route_table->hook_add = hook_add;
  1187. oa->route_table->hook_remove = hook_remove;
  1188. for (route = ospf6_route_head (oa->route_table); route;
  1189. route = nroute)
  1190. {
  1191. nroute = ospf6_route_next (route);
  1192. if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) &&
  1193. CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD))
  1194. {
  1195. UNSET_FLAG (route->flag, OSPF6_ROUTE_REMOVE);
  1196. UNSET_FLAG (route->flag, OSPF6_ROUTE_ADD);
  1197. }
  1198. if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
  1199. ospf6_route_remove (route, oa->route_table);
  1200. else if (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ||
  1201. CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE))
  1202. {
  1203. if (hook_add)
  1204. (*hook_add) (route);
  1205. }
  1206. route->flag = 0;
  1207. }
  1208. if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
  1209. zlog_debug ("Re-examin intra-routes for area %s: Done", oa->name);
  1210. }
  1211. static void
  1212. ospf6_brouter_debug_print (struct ospf6_route *brouter)
  1213. {
  1214. u_int32_t brouter_id;
  1215. char brouter_name[16];
  1216. char area_name[16];
  1217. char destination[64];
  1218. char installed[16], changed[16];
  1219. struct timeval now, res;
  1220. char id[16], adv_router[16];
  1221. char capa[16], options[16];
  1222. brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
  1223. inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
  1224. inet_ntop (AF_INET, &brouter->path.area_id, area_name, sizeof (area_name));
  1225. ospf6_linkstate_prefix2str (&brouter->prefix, destination,
  1226. sizeof (destination));
  1227. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  1228. timersub (&now, &brouter->installed, &res);
  1229. timerstring (&res, installed, sizeof (installed));
  1230. quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
  1231. timersub (&now, &brouter->changed, &res);
  1232. timerstring (&res, changed, sizeof (changed));
  1233. inet_ntop (AF_INET, &brouter->path.origin.id, id, sizeof (id));
  1234. inet_ntop (AF_INET, &brouter->path.origin.adv_router, adv_router,
  1235. sizeof (adv_router));
  1236. ospf6_options_printbuf (brouter->path.options, options, sizeof (options));
  1237. ospf6_capability_printbuf (brouter->path.router_bits, capa, sizeof (capa));
  1238. zlog_info ("Brouter: %s via area %s", brouter_name, area_name);
  1239. zlog_info (" memory: prev: %p this: %p next: %p parent rnode: %p",
  1240. (void *)brouter->prev, (void *)brouter, (void *)brouter->next,
  1241. (void *)brouter->rnode);
  1242. zlog_info (" type: %d prefix: %s installed: %s changed: %s",
  1243. brouter->type, destination, installed, changed);
  1244. zlog_info (" lock: %d flags: %s%s%s%s", brouter->lock,
  1245. (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_BEST) ? "B" : "-"),
  1246. (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD) ? "A" : "-"),
  1247. (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE) ? "R" : "-"),
  1248. (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-"));
  1249. zlog_info (" path type: %s ls-origin %s id: %s adv-router %s",
  1250. OSPF6_PATH_TYPE_NAME (brouter->path.type),
  1251. ospf6_lstype_name (brouter->path.origin.type),
  1252. id, adv_router);
  1253. zlog_info (" options: %s router-bits: %s metric-type: %d metric: %d/%d",
  1254. options, capa, brouter->path.metric_type,
  1255. brouter->path.cost, brouter->path.cost_e2);
  1256. }
  1257. void
  1258. ospf6_intra_brouter_calculation (struct ospf6_area *oa)
  1259. {
  1260. struct ospf6_route *brouter, *nbrouter, *copy;
  1261. void (*hook_add) (struct ospf6_route *) = NULL;
  1262. void (*hook_remove) (struct ospf6_route *) = NULL;
  1263. u_int32_t brouter_id;
  1264. char brouter_name[16];
  1265. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
  1266. zlog_info ("border-router calculation for area %s", oa->name);
  1267. hook_add = oa->ospf6->brouter_table->hook_add;
  1268. hook_remove = oa->ospf6->brouter_table->hook_remove;
  1269. oa->ospf6->brouter_table->hook_add = NULL;
  1270. oa->ospf6->brouter_table->hook_remove = NULL;
  1271. /* withdraw the previous router entries for the area */
  1272. for (brouter = ospf6_route_head (oa->ospf6->brouter_table); brouter;
  1273. brouter = ospf6_route_next (brouter))
  1274. {
  1275. brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
  1276. inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
  1277. if (brouter->path.area_id != oa->area_id)
  1278. continue;
  1279. brouter->flag = OSPF6_ROUTE_REMOVE;
  1280. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
  1281. IS_OSPF6_DEBUG_ROUTE (MEMORY))
  1282. {
  1283. zlog_info ("%p: mark as removing: area %s brouter %s",
  1284. (void *)brouter, oa->name, brouter_name);
  1285. ospf6_brouter_debug_print (brouter);
  1286. }
  1287. }
  1288. for (brouter = ospf6_route_head (oa->spf_table); brouter;
  1289. brouter = ospf6_route_next (brouter))
  1290. {
  1291. brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
  1292. inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
  1293. if (brouter->type != OSPF6_DEST_TYPE_LINKSTATE)
  1294. continue;
  1295. if (ospf6_linkstate_prefix_id (&brouter->prefix) != htonl (0))
  1296. continue;
  1297. if (! CHECK_FLAG (brouter->path.router_bits, OSPF6_ROUTER_BIT_E) &&
  1298. ! CHECK_FLAG (brouter->path.router_bits, OSPF6_ROUTER_BIT_B))
  1299. continue;
  1300. if (! OSPF6_OPT_ISSET (brouter->path.options, OSPF6_OPT_V6) ||
  1301. ! OSPF6_OPT_ISSET (brouter->path.options, OSPF6_OPT_R))
  1302. continue;
  1303. copy = ospf6_route_copy (brouter);
  1304. copy->type = OSPF6_DEST_TYPE_ROUTER;
  1305. copy->path.area_id = oa->area_id;
  1306. ospf6_route_add (copy, oa->ospf6->brouter_table);
  1307. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
  1308. IS_OSPF6_DEBUG_ROUTE (MEMORY))
  1309. {
  1310. zlog_info ("%p: transfer: area %s brouter %s",
  1311. (void *)brouter, oa->name, brouter_name);
  1312. ospf6_brouter_debug_print (brouter);
  1313. }
  1314. }
  1315. oa->ospf6->brouter_table->hook_add = hook_add;
  1316. oa->ospf6->brouter_table->hook_remove = hook_remove;
  1317. for (brouter = ospf6_route_head (oa->ospf6->brouter_table); brouter;
  1318. brouter = nbrouter)
  1319. {
  1320. nbrouter = ospf6_route_next (brouter);
  1321. brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
  1322. inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
  1323. if (brouter->path.area_id != oa->area_id)
  1324. continue;
  1325. if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_WAS_REMOVED))
  1326. continue;
  1327. if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE) &&
  1328. CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD))
  1329. {
  1330. UNSET_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE);
  1331. UNSET_FLAG (brouter->flag, OSPF6_ROUTE_ADD);
  1332. }
  1333. if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE))
  1334. {
  1335. if (IS_OSPF6_DEBUG_BROUTER ||
  1336. IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
  1337. IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
  1338. zlog_info ("brouter %s disappears via area %s",
  1339. brouter_name, oa->name);
  1340. ospf6_route_remove (brouter, oa->ospf6->brouter_table);
  1341. }
  1342. else if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD) ||
  1343. CHECK_FLAG (brouter->flag, OSPF6_ROUTE_CHANGE))
  1344. {
  1345. if (IS_OSPF6_DEBUG_BROUTER ||
  1346. IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
  1347. IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
  1348. zlog_info ("brouter %s appears via area %s",
  1349. brouter_name, oa->name);
  1350. /* newly added */
  1351. if (hook_add)
  1352. (*hook_add) (brouter);
  1353. }
  1354. else
  1355. {
  1356. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
  1357. IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
  1358. zlog_info ("brouter %s still exists via area %s",
  1359. brouter_name, oa->name);
  1360. }
  1361. brouter->flag = 0;
  1362. }
  1363. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
  1364. zlog_info ("border-router calculation for area %s: done", oa->name);
  1365. }
  1366. struct ospf6_lsa_handler router_handler =
  1367. {
  1368. OSPF6_LSTYPE_ROUTER,
  1369. "Router",
  1370. "Rtr",
  1371. ospf6_router_lsa_show,
  1372. ospf6_router_lsa_get_nbr_id
  1373. };
  1374. struct ospf6_lsa_handler network_handler =
  1375. {
  1376. OSPF6_LSTYPE_NETWORK,
  1377. "Network",
  1378. "Net",
  1379. ospf6_network_lsa_show,
  1380. ospf6_network_lsa_get_ar_id
  1381. };
  1382. struct ospf6_lsa_handler link_handler =
  1383. {
  1384. OSPF6_LSTYPE_LINK,
  1385. "Link",
  1386. "Lnk",
  1387. ospf6_link_lsa_show,
  1388. ospf6_link_lsa_get_prefix_str
  1389. };
  1390. struct ospf6_lsa_handler intra_prefix_handler =
  1391. {
  1392. OSPF6_LSTYPE_INTRA_PREFIX,
  1393. "Intra-Prefix",
  1394. "INP",
  1395. ospf6_intra_prefix_lsa_show,
  1396. ospf6_intra_prefix_lsa_get_prefix_str
  1397. };
  1398. void
  1399. ospf6_intra_init (void)
  1400. {
  1401. ospf6_install_lsa_handler (&router_handler);
  1402. ospf6_install_lsa_handler (&network_handler);
  1403. ospf6_install_lsa_handler (&link_handler);
  1404. ospf6_install_lsa_handler (&intra_prefix_handler);
  1405. }
  1406. DEFUN (debug_ospf6_brouter,
  1407. debug_ospf6_brouter_cmd,
  1408. "debug ospf6 border-routers",
  1409. DEBUG_STR
  1410. OSPF6_STR
  1411. "Debug border router\n"
  1412. )
  1413. {
  1414. OSPF6_DEBUG_BROUTER_ON ();
  1415. return CMD_SUCCESS;
  1416. }
  1417. DEFUN (no_debug_ospf6_brouter,
  1418. no_debug_ospf6_brouter_cmd,
  1419. "no debug ospf6 border-routers",
  1420. NO_STR
  1421. DEBUG_STR
  1422. OSPF6_STR
  1423. "Debug border router\n"
  1424. )
  1425. {
  1426. OSPF6_DEBUG_BROUTER_OFF ();
  1427. return CMD_SUCCESS;
  1428. }
  1429. DEFUN (debug_ospf6_brouter_router,
  1430. debug_ospf6_brouter_router_cmd,
  1431. "debug ospf6 border-routers router-id A.B.C.D",
  1432. DEBUG_STR
  1433. OSPF6_STR
  1434. "Debug border router\n"
  1435. "Debug specific border router\n"
  1436. "Specify border-router's router-id\n"
  1437. )
  1438. {
  1439. u_int32_t router_id;
  1440. inet_pton (AF_INET, argv[0], &router_id);
  1441. OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ON (router_id);
  1442. return CMD_SUCCESS;
  1443. }
  1444. DEFUN (no_debug_ospf6_brouter_router,
  1445. no_debug_ospf6_brouter_router_cmd,
  1446. "no debug ospf6 border-routers router-id",
  1447. NO_STR
  1448. DEBUG_STR
  1449. OSPF6_STR
  1450. "Debug border router\n"
  1451. "Debug specific border router\n"
  1452. )
  1453. {
  1454. OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
  1455. return CMD_SUCCESS;
  1456. }
  1457. DEFUN (debug_ospf6_brouter_area,
  1458. debug_ospf6_brouter_area_cmd,
  1459. "debug ospf6 border-routers area-id A.B.C.D",
  1460. DEBUG_STR
  1461. OSPF6_STR
  1462. "Debug border router\n"
  1463. "Debug border routers in specific Area\n"
  1464. "Specify Area-ID\n"
  1465. )
  1466. {
  1467. u_int32_t area_id;
  1468. inet_pton (AF_INET, argv[0], &area_id);
  1469. OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ON (area_id);
  1470. return CMD_SUCCESS;
  1471. }
  1472. DEFUN (no_debug_ospf6_brouter_area,
  1473. no_debug_ospf6_brouter_area_cmd,
  1474. "no debug ospf6 border-routers area-id",
  1475. NO_STR
  1476. DEBUG_STR
  1477. OSPF6_STR
  1478. "Debug border router\n"
  1479. "Debug border routers in specific Area\n"
  1480. )
  1481. {
  1482. OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
  1483. return CMD_SUCCESS;
  1484. }
  1485. int
  1486. config_write_ospf6_debug_brouter (struct vty *vty)
  1487. {
  1488. char buf[16];
  1489. if (IS_OSPF6_DEBUG_BROUTER)
  1490. vty_out (vty, "debug ospf6 border-routers%s", VNL);
  1491. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER)
  1492. {
  1493. inet_ntop (AF_INET, &conf_debug_ospf6_brouter_specific_router_id,
  1494. buf, sizeof (buf));
  1495. vty_out (vty, "debug ospf6 border-routers router-id %s%s", buf, VNL);
  1496. }
  1497. if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA)
  1498. {
  1499. inet_ntop (AF_INET, &conf_debug_ospf6_brouter_specific_area_id,
  1500. buf, sizeof (buf));
  1501. vty_out (vty, "debug ospf6 border-routers area-id %s%s", buf, VNL);
  1502. }
  1503. return 0;
  1504. }
  1505. void
  1506. install_element_ospf6_debug_brouter (void)
  1507. {
  1508. install_element (ENABLE_NODE, &debug_ospf6_brouter_cmd);
  1509. install_element (ENABLE_NODE, &debug_ospf6_brouter_router_cmd);
  1510. install_element (ENABLE_NODE, &debug_ospf6_brouter_area_cmd);
  1511. install_element (ENABLE_NODE, &no_debug_ospf6_brouter_cmd);
  1512. install_element (ENABLE_NODE, &no_debug_ospf6_brouter_router_cmd);
  1513. install_element (ENABLE_NODE, &no_debug_ospf6_brouter_area_cmd);
  1514. install_element (CONFIG_NODE, &debug_ospf6_brouter_cmd);
  1515. install_element (CONFIG_NODE, &debug_ospf6_brouter_router_cmd);
  1516. install_element (CONFIG_NODE, &debug_ospf6_brouter_area_cmd);
  1517. install_element (CONFIG_NODE, &no_debug_ospf6_brouter_cmd);
  1518. install_element (CONFIG_NODE, &no_debug_ospf6_brouter_router_cmd);
  1519. install_element (CONFIG_NODE, &no_debug_ospf6_brouter_area_cmd);
  1520. }