ospf6_intra.c 56 KB

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