ospf6_message.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159
  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 "memory.h"
  23. #include "log.h"
  24. #include "vty.h"
  25. #include "command.h"
  26. #include "thread.h"
  27. #include "linklist.h"
  28. #include "ospf6_proto.h"
  29. #include "ospf6_lsa.h"
  30. #include "ospf6_lsdb.h"
  31. #include "ospf6_network.h"
  32. #include "ospf6_message.h"
  33. #include "ospf6_top.h"
  34. #include "ospf6_area.h"
  35. #include "ospf6_neighbor.h"
  36. #include "ospf6_interface.h"
  37. #include "ospf6_flood.h"
  38. #include "ospf6d.h"
  39. unsigned char conf_debug_ospf6_message[6] = {0x03, 0, 0, 0, 0, 0};
  40. char *ospf6_message_type_str[] =
  41. { "Unknown", "Hello", "DbDesc", "LSReq", "LSUpdate", "LSAck" };
  42. /* print functions */
  43. static void
  44. ospf6_header_print (struct ospf6_header *oh)
  45. {
  46. char router_id[16], area_id[16];
  47. inet_ntop (AF_INET, &oh->router_id, router_id, sizeof (router_id));
  48. inet_ntop (AF_INET, &oh->area_id, area_id, sizeof (area_id));
  49. zlog_info (" OSPFv%d Type:%d Len:%hu Router-ID:%s",
  50. oh->version, oh->type, ntohs (oh->length), router_id);
  51. zlog_info (" Area-ID:%s Cksum:%hx Instance-ID:%d",
  52. area_id, ntohs (oh->checksum), oh->instance_id);
  53. }
  54. void
  55. ospf6_hello_print (struct ospf6_header *oh)
  56. {
  57. struct ospf6_hello *hello;
  58. char options[16];
  59. char drouter[16], bdrouter[16], neighbor[16];
  60. char *p;
  61. ospf6_header_print (oh);
  62. assert (oh->type == OSPF6_MESSAGE_TYPE_HELLO);
  63. hello = (struct ospf6_hello *)
  64. ((caddr_t) oh + sizeof (struct ospf6_header));
  65. inet_ntop (AF_INET, &hello->drouter, drouter, sizeof (drouter));
  66. inet_ntop (AF_INET, &hello->bdrouter, bdrouter, sizeof (bdrouter));
  67. ospf6_options_printbuf (hello->options, options, sizeof (options));
  68. zlog_info (" I/F-Id:%ld Priority:%d Option:%s",
  69. (u_long) ntohl (hello->interface_id), hello->priority, options);
  70. zlog_info (" HelloInterval:%hu DeadInterval:%hu",
  71. ntohs (hello->hello_interval), ntohs (hello->dead_interval));
  72. zlog_info (" DR:%s BDR:%s", drouter, bdrouter);
  73. for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello));
  74. p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh);
  75. p += sizeof (u_int32_t))
  76. {
  77. inet_ntop (AF_INET, (void *) p, neighbor, sizeof (neighbor));
  78. zlog_info (" Neighbor: %s", neighbor);
  79. }
  80. if (p != OSPF6_MESSAGE_END (oh))
  81. zlog_info ("Trailing garbage exists");
  82. }
  83. void
  84. ospf6_dbdesc_print (struct ospf6_header *oh)
  85. {
  86. struct ospf6_dbdesc *dbdesc;
  87. char options[16];
  88. char *p;
  89. ospf6_header_print (oh);
  90. assert (oh->type == OSPF6_MESSAGE_TYPE_DBDESC);
  91. dbdesc = (struct ospf6_dbdesc *)
  92. ((caddr_t) oh + sizeof (struct ospf6_header));
  93. ospf6_options_printbuf (dbdesc->options, options, sizeof (options));
  94. zlog_info (" MBZ: %#x Option: %s IfMTU: %hu",
  95. dbdesc->reserved1, options, ntohs (dbdesc->ifmtu));
  96. zlog_info (" MBZ: %#x Bits: %s%s%s SeqNum: %#lx",
  97. dbdesc->reserved2,
  98. (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"),
  99. (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"),
  100. (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"),
  101. (u_long) ntohl (dbdesc->seqnum));
  102. for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  103. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  104. p += sizeof (struct ospf6_lsa_header))
  105. ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
  106. if (p != OSPF6_MESSAGE_END (oh))
  107. zlog_info ("Trailing garbage exists");
  108. }
  109. void
  110. ospf6_lsreq_print (struct ospf6_header *oh)
  111. {
  112. char id[16], adv_router[16];
  113. char *p;
  114. ospf6_header_print (oh);
  115. assert (oh->type == OSPF6_MESSAGE_TYPE_LSREQ);
  116. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  117. p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh);
  118. p += sizeof (struct ospf6_lsreq_entry))
  119. {
  120. struct ospf6_lsreq_entry *e = (struct ospf6_lsreq_entry *) p;
  121. inet_ntop (AF_INET, &e->adv_router, adv_router, sizeof (adv_router));
  122. inet_ntop (AF_INET, &e->id, id, sizeof (id));
  123. zlog_info (" [%s Id:%s Adv:%s]",
  124. OSPF6_LSTYPE_NAME (e->type), id, adv_router);
  125. }
  126. if (p != OSPF6_MESSAGE_END (oh))
  127. zlog_info ("Trailing garbage exists");
  128. }
  129. void
  130. ospf6_lsupdate_print (struct ospf6_header *oh)
  131. {
  132. struct ospf6_lsupdate *lsupdate;
  133. u_long num;
  134. char *p;
  135. ospf6_header_print (oh);
  136. assert (oh->type == OSPF6_MESSAGE_TYPE_LSUPDATE);
  137. lsupdate = (struct ospf6_lsupdate *)
  138. ((caddr_t) oh + sizeof (struct ospf6_header));
  139. num = ntohl (lsupdate->lsa_number);
  140. zlog_info (" Number of LSA: %ld", num);
  141. for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  142. p < OSPF6_MESSAGE_END (oh) &&
  143. p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh);
  144. p += OSPF6_LSA_SIZE (p))
  145. {
  146. ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
  147. if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header))
  148. {
  149. zlog_info (" Malformed LSA length, quit printing");
  150. break;
  151. }
  152. }
  153. if (p != OSPF6_MESSAGE_END (oh))
  154. {
  155. char buf[32];
  156. int num = 0;
  157. memset (buf, 0, sizeof (buf));
  158. zlog_info (" Trailing garbage exists");
  159. while (p < OSPF6_MESSAGE_END (oh))
  160. {
  161. snprintf (buf, sizeof (buf), "%s %2x", buf, *p++);
  162. num++;
  163. if (num == 8)
  164. {
  165. zlog_info (" %s", buf);
  166. memset (buf, 0, sizeof (buf));
  167. num = 0;
  168. }
  169. }
  170. if (num)
  171. zlog_info (" %s", buf);
  172. }
  173. }
  174. void
  175. ospf6_lsack_print (struct ospf6_header *oh)
  176. {
  177. char *p;
  178. ospf6_header_print (oh);
  179. assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK);
  180. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  181. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  182. p += sizeof (struct ospf6_lsa_header))
  183. ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
  184. if (p != OSPF6_MESSAGE_END (oh))
  185. zlog_info ("Trailing garbage exists");
  186. }
  187. /* Receive function */
  188. #define MSG_OK 0
  189. #define MSG_NG 1
  190. static int
  191. ospf6_header_examin (struct in6_addr *src, struct in6_addr *dst,
  192. struct ospf6_interface *oi, struct ospf6_header *oh)
  193. {
  194. u_char type;
  195. type = OSPF6_MESSAGE_TYPE_CANONICAL (oh->type);
  196. /* version check */
  197. if (oh->version != OSPFV3_VERSION)
  198. {
  199. if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
  200. zlog_info ("Message with unknown version");
  201. return MSG_NG;
  202. }
  203. /* Area-ID check */
  204. if (oh->area_id != oi->area->area_id)
  205. {
  206. if (oh->area_id == BACKBONE_AREA_ID)
  207. {
  208. if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
  209. zlog_info ("Message may be via Virtual Link: not supported");
  210. return MSG_NG;
  211. }
  212. if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
  213. zlog_info ("Area-ID mismatch");
  214. return MSG_NG;
  215. }
  216. /* Instance-ID check */
  217. if (oh->instance_id != oi->instance_id)
  218. {
  219. if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
  220. zlog_info ("Instance-ID mismatch");
  221. return MSG_NG;
  222. }
  223. /* Router-ID check */
  224. if (oh->router_id == oi->area->ospf6->router_id)
  225. zlog_warn ("Detect duplicate Router-ID");
  226. return MSG_OK;
  227. }
  228. void
  229. ospf6_hello_recv (struct in6_addr *src, struct in6_addr *dst,
  230. struct ospf6_interface *oi, struct ospf6_header *oh)
  231. {
  232. struct ospf6_hello *hello;
  233. struct ospf6_neighbor *on;
  234. char *p;
  235. int twoway = 0;
  236. int neighborchange = 0;
  237. int backupseen = 0;
  238. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  239. return;
  240. hello = (struct ospf6_hello *)
  241. ((caddr_t) oh + sizeof (struct ospf6_header));
  242. /* HelloInterval check */
  243. if (ntohs (hello->hello_interval) != oi->hello_interval)
  244. {
  245. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  246. zlog_info ("HelloInterval mismatch");
  247. return;
  248. }
  249. /* RouterDeadInterval check */
  250. if (ntohs (hello->dead_interval) != oi->dead_interval)
  251. {
  252. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  253. zlog_info ("RouterDeadInterval mismatch");
  254. return;
  255. }
  256. /* E-bit check */
  257. if (OSPF6_OPT_ISSET (hello->options, OSPF6_OPT_E) !=
  258. OSPF6_OPT_ISSET (oi->area->options, OSPF6_OPT_E))
  259. {
  260. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  261. zlog_info ("E-bit mismatch");
  262. return;
  263. }
  264. /* Find neighbor, create if not exist */
  265. on = ospf6_neighbor_lookup (oh->router_id, oi);
  266. if (on == NULL)
  267. {
  268. on = ospf6_neighbor_create (oh->router_id, oi);
  269. on->prev_drouter = on->drouter = hello->drouter;
  270. on->prev_bdrouter = on->bdrouter = hello->bdrouter;
  271. on->priority = hello->priority;
  272. on->ifindex = ntohl (hello->interface_id);
  273. memcpy (&on->linklocal_addr, src, sizeof (struct in6_addr));
  274. }
  275. /* TwoWay check */
  276. for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello));
  277. p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh);
  278. p += sizeof (u_int32_t))
  279. {
  280. u_int32_t *router_id = (u_int32_t *) p;
  281. if (*router_id == oi->area->ospf6->router_id)
  282. twoway++;
  283. }
  284. if (p != OSPF6_MESSAGE_END (oh))
  285. {
  286. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  287. zlog_info ("Trailing garbage ignored");
  288. }
  289. /* RouterPriority check */
  290. if (on->priority != hello->priority)
  291. {
  292. on->priority = hello->priority;
  293. neighborchange++;
  294. }
  295. /* DR check */
  296. if (on->drouter != hello->drouter)
  297. {
  298. on->prev_drouter = on->drouter;
  299. on->drouter = hello->drouter;
  300. if (on->prev_drouter == on->router_id || on->drouter == on->router_id)
  301. neighborchange++;
  302. }
  303. /* BDR check */
  304. if (on->bdrouter != hello->bdrouter)
  305. {
  306. on->prev_bdrouter = on->bdrouter;
  307. on->bdrouter = hello->bdrouter;
  308. if (on->prev_bdrouter == on->router_id || on->bdrouter == on->router_id)
  309. neighborchange++;
  310. }
  311. /* BackupSeen check */
  312. if (oi->state == OSPF6_INTERFACE_WAITING)
  313. {
  314. if (hello->bdrouter == on->router_id)
  315. backupseen++;
  316. else if (hello->drouter == on->router_id && hello->bdrouter == htonl (0))
  317. backupseen++;
  318. }
  319. /* Execute neighbor events */
  320. thread_execute (master, hello_received, on, 0);
  321. if (twoway)
  322. thread_execute (master, twoway_received, on, 0);
  323. else
  324. thread_execute (master, oneway_received, on, 0);
  325. /* Schedule interface events */
  326. if (backupseen)
  327. thread_add_event (master, backup_seen, oi, 0);
  328. if (neighborchange)
  329. thread_add_event (master, neighbor_change, oi, 0);
  330. }
  331. static void
  332. ospf6_dbdesc_recv_master (struct ospf6_header *oh,
  333. struct ospf6_neighbor *on)
  334. {
  335. struct ospf6_dbdesc *dbdesc;
  336. char *p;
  337. dbdesc = (struct ospf6_dbdesc *)
  338. ((caddr_t) oh + sizeof (struct ospf6_header));
  339. if (on->state < OSPF6_NEIGHBOR_INIT)
  340. {
  341. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  342. zlog_info ("Neighbor state less than Init, ignore");
  343. return;
  344. }
  345. switch (on->state)
  346. {
  347. case OSPF6_NEIGHBOR_TWOWAY:
  348. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  349. zlog_info ("Neighbor state is 2-Way, ignore");
  350. return;
  351. case OSPF6_NEIGHBOR_INIT:
  352. thread_execute (master, twoway_received, on, 0);
  353. if (on->state != OSPF6_NEIGHBOR_EXSTART)
  354. {
  355. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  356. zlog_info ("Neighbor state is not ExStart, ignore");
  357. return;
  358. }
  359. /* else fall through to ExStart */
  360. case OSPF6_NEIGHBOR_EXSTART:
  361. /* if neighbor obeys us as our slave, schedule negotiation_done
  362. and process LSA Headers. Otherwise, ignore this message */
  363. if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) &&
  364. ! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) &&
  365. ntohl (dbdesc->seqnum) == on->dbdesc_seqnum)
  366. {
  367. /* execute NegotiationDone */
  368. thread_execute (master, negotiation_done, on, 0);
  369. /* Record neighbor options */
  370. memcpy (on->options, dbdesc->options, sizeof (on->options));
  371. }
  372. else
  373. {
  374. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  375. zlog_info ("Negotiation failed");
  376. return;
  377. }
  378. /* fall through to exchange */
  379. case OSPF6_NEIGHBOR_EXCHANGE:
  380. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  381. {
  382. /* Duplicated DatabaseDescription is dropped by master */
  383. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  384. zlog_info ("Duplicated dbdesc discarded by Master, ignore");
  385. return;
  386. }
  387. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT))
  388. {
  389. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  390. zlog_info ("Master/Slave bit mismatch");
  391. thread_add_event (master, seqnumber_mismatch, on, 0);
  392. return;
  393. }
  394. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT))
  395. {
  396. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  397. zlog_info ("Initialize bit mismatch");
  398. thread_add_event (master, seqnumber_mismatch, on, 0);
  399. return;
  400. }
  401. if (memcmp (on->options, dbdesc->options, sizeof (on->options)))
  402. {
  403. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  404. zlog_info ("Option field mismatch");
  405. thread_add_event (master, seqnumber_mismatch, on, 0);
  406. return;
  407. }
  408. if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum)
  409. {
  410. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  411. zlog_info ("Sequence number mismatch (%#lx expected)",
  412. (u_long) on->dbdesc_seqnum);
  413. thread_add_event (master, seqnumber_mismatch, on, 0);
  414. return;
  415. }
  416. break;
  417. case OSPF6_NEIGHBOR_LOADING:
  418. case OSPF6_NEIGHBOR_FULL:
  419. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  420. {
  421. /* Duplicated DatabaseDescription is dropped by master */
  422. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  423. zlog_info ("Duplicated dbdesc discarded by Master, ignore");
  424. return;
  425. }
  426. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  427. zlog_info ("Not duplicate dbdesc in state %s",
  428. ospf6_neighbor_state_str[on->state]);
  429. thread_add_event (master, seqnumber_mismatch, on, 0);
  430. return;
  431. default:
  432. assert (0);
  433. break;
  434. }
  435. /* Process LSA headers */
  436. for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  437. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  438. p += sizeof (struct ospf6_lsa_header))
  439. {
  440. struct ospf6_lsa *his, *mine;
  441. struct ospf6_lsdb *lsdb = NULL;
  442. his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
  443. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  444. zlog_info ("%s", his->name);
  445. switch (OSPF6_LSA_SCOPE (his->header->type))
  446. {
  447. case OSPF6_SCOPE_LINKLOCAL:
  448. lsdb = on->ospf6_if->lsdb;
  449. break;
  450. case OSPF6_SCOPE_AREA:
  451. lsdb = on->ospf6_if->area->lsdb;
  452. break;
  453. case OSPF6_SCOPE_AS:
  454. lsdb = on->ospf6_if->area->ospf6->lsdb;
  455. break;
  456. case OSPF6_SCOPE_RESERVED:
  457. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  458. zlog_info ("Ignoring LSA of reserved scope");
  459. ospf6_lsa_delete (his);
  460. continue;
  461. break;
  462. }
  463. if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL &&
  464. IS_AREA_STUB (on->ospf6_if->area))
  465. {
  466. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  467. zlog_info ("SeqNumMismatch (E-bit mismatch), discard");
  468. ospf6_lsa_delete (his);
  469. thread_add_event (master, seqnumber_mismatch, on, 0);
  470. return;
  471. }
  472. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  473. his->header->adv_router, lsdb);
  474. if (mine == NULL)
  475. {
  476. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  477. zlog_info ("Add request (No database copy)");
  478. ospf6_lsdb_add (his, on->request_list);
  479. }
  480. else if (ospf6_lsa_compare (his, mine) < 0)
  481. {
  482. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  483. zlog_info ("Add request (Received MoreRecent)");
  484. ospf6_lsdb_add (his, on->request_list);
  485. }
  486. else
  487. {
  488. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  489. zlog_info ("Discard (Existing MoreRecent)");
  490. ospf6_lsa_delete (his);
  491. }
  492. }
  493. if (p != OSPF6_MESSAGE_END (oh))
  494. {
  495. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  496. zlog_info ("Trailing garbage ignored");
  497. }
  498. /* Increment sequence number */
  499. on->dbdesc_seqnum ++;
  500. /* schedule send lsreq */
  501. if (on->thread_send_lsreq == NULL)
  502. on->thread_send_lsreq =
  503. thread_add_event (master, ospf6_lsreq_send, on, 0);
  504. THREAD_OFF (on->thread_send_dbdesc);
  505. /* More bit check */
  506. if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
  507. ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
  508. thread_add_event (master, exchange_done, on, 0);
  509. else
  510. on->thread_send_dbdesc =
  511. thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
  512. /* save last received dbdesc */
  513. memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
  514. }
  515. static void
  516. ospf6_dbdesc_recv_slave (struct ospf6_header *oh,
  517. struct ospf6_neighbor *on)
  518. {
  519. struct ospf6_dbdesc *dbdesc;
  520. char *p;
  521. dbdesc = (struct ospf6_dbdesc *)
  522. ((caddr_t) oh + sizeof (struct ospf6_header));
  523. if (on->state < OSPF6_NEIGHBOR_INIT)
  524. {
  525. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  526. zlog_info ("Neighbor state less than Init, ignore");
  527. return;
  528. }
  529. switch (on->state)
  530. {
  531. case OSPF6_NEIGHBOR_TWOWAY:
  532. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  533. zlog_info ("Neighbor state is 2-Way, ignore");
  534. return;
  535. case OSPF6_NEIGHBOR_INIT:
  536. thread_execute (master, twoway_received, on, 0);
  537. if (on->state != OSPF6_NEIGHBOR_EXSTART)
  538. {
  539. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  540. zlog_info ("Neighbor state is not ExStart, ignore");
  541. return;
  542. }
  543. /* else fall through to ExStart */
  544. case OSPF6_NEIGHBOR_EXSTART:
  545. /* If the neighbor is Master, act as Slave. Schedule negotiation_done
  546. and process LSA Headers. Otherwise, ignore this message */
  547. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) &&
  548. CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
  549. CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) &&
  550. ntohs (oh->length) == sizeof (struct ospf6_header) +
  551. sizeof (struct ospf6_dbdesc))
  552. {
  553. /* set the master/slave bit to slave */
  554. UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  555. /* set the DD sequence number to one specified by master */
  556. on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
  557. /* schedule NegotiationDone */
  558. thread_execute (master, negotiation_done, on, 0);
  559. /* Record neighbor options */
  560. memcpy (on->options, dbdesc->options, sizeof (on->options));
  561. }
  562. else
  563. {
  564. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  565. zlog_info ("Negotiation failed");
  566. return;
  567. }
  568. break;
  569. case OSPF6_NEIGHBOR_EXCHANGE:
  570. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  571. {
  572. /* Duplicated DatabaseDescription causes slave to retransmit */
  573. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  574. zlog_info ("Duplicated dbdesc causes retransmit");
  575. THREAD_OFF (on->thread_send_dbdesc);
  576. on->thread_send_dbdesc =
  577. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  578. return;
  579. }
  580. if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT))
  581. {
  582. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  583. zlog_info ("Master/Slave bit mismatch");
  584. thread_add_event (master, seqnumber_mismatch, on, 0);
  585. return;
  586. }
  587. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT))
  588. {
  589. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  590. zlog_info ("Initialize bit mismatch");
  591. thread_add_event (master, seqnumber_mismatch, on, 0);
  592. return;
  593. }
  594. if (memcmp (on->options, dbdesc->options, sizeof (on->options)))
  595. {
  596. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  597. zlog_info ("Option field mismatch");
  598. thread_add_event (master, seqnumber_mismatch, on, 0);
  599. return;
  600. }
  601. if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum + 1)
  602. {
  603. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  604. zlog_info ("Sequence number mismatch (%#lx expected)",
  605. (u_long) on->dbdesc_seqnum + 1);
  606. thread_add_event (master, seqnumber_mismatch, on, 0);
  607. return;
  608. }
  609. break;
  610. case OSPF6_NEIGHBOR_LOADING:
  611. case OSPF6_NEIGHBOR_FULL:
  612. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  613. {
  614. /* Duplicated DatabaseDescription causes slave to retransmit */
  615. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  616. zlog_info ("Duplicated dbdesc causes retransmit");
  617. THREAD_OFF (on->thread_send_dbdesc);
  618. on->thread_send_dbdesc =
  619. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  620. return;
  621. }
  622. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  623. zlog_info ("Not duplicate dbdesc in state %s",
  624. ospf6_neighbor_state_str[on->state]);
  625. thread_add_event (master, seqnumber_mismatch, on, 0);
  626. return;
  627. default:
  628. assert (0);
  629. break;
  630. }
  631. /* Process LSA headers */
  632. for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  633. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  634. p += sizeof (struct ospf6_lsa_header))
  635. {
  636. struct ospf6_lsa *his, *mine;
  637. struct ospf6_lsdb *lsdb = NULL;
  638. his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
  639. switch (OSPF6_LSA_SCOPE (his->header->type))
  640. {
  641. case OSPF6_SCOPE_LINKLOCAL:
  642. lsdb = on->ospf6_if->lsdb;
  643. break;
  644. case OSPF6_SCOPE_AREA:
  645. lsdb = on->ospf6_if->area->lsdb;
  646. break;
  647. case OSPF6_SCOPE_AS:
  648. lsdb = on->ospf6_if->area->ospf6->lsdb;
  649. break;
  650. case OSPF6_SCOPE_RESERVED:
  651. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  652. zlog_info ("Ignoring LSA of reserved scope");
  653. ospf6_lsa_delete (his);
  654. continue;
  655. break;
  656. }
  657. if (OSPF6_LSA_SCOPE (his->header->type) == OSPF6_SCOPE_AS &&
  658. IS_AREA_STUB (on->ospf6_if->area))
  659. {
  660. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  661. zlog_info ("E-bit mismatch with LSA Headers");
  662. ospf6_lsa_delete (his);
  663. thread_add_event (master, seqnumber_mismatch, on, 0);
  664. return;
  665. }
  666. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  667. his->header->adv_router, lsdb);
  668. if (mine == NULL || ospf6_lsa_compare (his, mine) < 0)
  669. {
  670. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  671. zlog_info ("Add request-list: %s", his->name);
  672. ospf6_lsdb_add (his, on->request_list);
  673. }
  674. else
  675. ospf6_lsa_delete (his);
  676. }
  677. if (p != OSPF6_MESSAGE_END (oh))
  678. {
  679. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  680. zlog_info ("Trailing garbage ignored");
  681. }
  682. /* Set sequence number to Master's */
  683. on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
  684. /* schedule send lsreq */
  685. if (on->thread_send_lsreq == NULL)
  686. on->thread_send_lsreq =
  687. thread_add_event (master, ospf6_lsreq_send, on, 0);
  688. THREAD_OFF (on->thread_send_dbdesc);
  689. on->thread_send_dbdesc =
  690. thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
  691. /* save last received dbdesc */
  692. memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
  693. }
  694. void
  695. ospf6_dbdesc_recv (struct in6_addr *src, struct in6_addr *dst,
  696. struct ospf6_interface *oi, struct ospf6_header *oh)
  697. {
  698. struct ospf6_neighbor *on;
  699. struct ospf6_dbdesc *dbdesc;
  700. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  701. return;
  702. on = ospf6_neighbor_lookup (oh->router_id, oi);
  703. if (on == NULL)
  704. {
  705. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  706. zlog_info ("Neighbor not found, ignore");
  707. return;
  708. }
  709. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  710. {
  711. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  712. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  713. return;
  714. }
  715. dbdesc = (struct ospf6_dbdesc *)
  716. ((caddr_t) oh + sizeof (struct ospf6_header));
  717. /* Interface MTU check */
  718. if (ntohs (dbdesc->ifmtu) != oi->ifmtu)
  719. {
  720. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  721. zlog_info ("I/F MTU mismatch");
  722. return;
  723. }
  724. if (dbdesc->reserved1 || dbdesc->reserved2)
  725. {
  726. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  727. zlog_info ("Non-0 reserved field in %s's DbDesc, correct",
  728. on->name);
  729. dbdesc->reserved1 = 0;
  730. dbdesc->reserved2 = 0;
  731. }
  732. if (ntohl (oh->router_id) < ntohl (ospf6->router_id))
  733. ospf6_dbdesc_recv_master (oh, on);
  734. else if (ntohl (ospf6->router_id) < ntohl (oh->router_id))
  735. ospf6_dbdesc_recv_slave (oh, on);
  736. else
  737. {
  738. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  739. zlog_info ("Can't decide which is master, ignore");
  740. }
  741. }
  742. void
  743. ospf6_lsreq_recv (struct in6_addr *src, struct in6_addr *dst,
  744. struct ospf6_interface *oi, struct ospf6_header *oh)
  745. {
  746. struct ospf6_neighbor *on;
  747. char *p;
  748. struct ospf6_lsreq_entry *e;
  749. struct ospf6_lsdb *lsdb = NULL;
  750. struct ospf6_lsa *lsa;
  751. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  752. return;
  753. on = ospf6_neighbor_lookup (oh->router_id, oi);
  754. if (on == NULL)
  755. {
  756. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  757. zlog_info ("Neighbor not found, ignore");
  758. return;
  759. }
  760. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  761. {
  762. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  763. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  764. return;
  765. }
  766. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  767. on->state != OSPF6_NEIGHBOR_LOADING &&
  768. on->state != OSPF6_NEIGHBOR_FULL)
  769. {
  770. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  771. zlog_info ("Neighbor state less than Exchange, ignore");
  772. return;
  773. }
  774. /* Process each request */
  775. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  776. p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh);
  777. p += sizeof (struct ospf6_lsreq_entry))
  778. {
  779. e = (struct ospf6_lsreq_entry *) p;
  780. switch (OSPF6_LSA_SCOPE (e->type))
  781. {
  782. case OSPF6_SCOPE_LINKLOCAL:
  783. lsdb = on->ospf6_if->lsdb;
  784. break;
  785. case OSPF6_SCOPE_AREA:
  786. lsdb = on->ospf6_if->area->lsdb;
  787. break;
  788. case OSPF6_SCOPE_AS:
  789. lsdb = on->ospf6_if->area->ospf6->lsdb;
  790. break;
  791. default:
  792. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  793. zlog_info ("Ignoring LSA of reserved scope");
  794. continue;
  795. break;
  796. }
  797. /* Find database copy */
  798. lsa = ospf6_lsdb_lookup (e->type, e->id, e->adv_router, lsdb);
  799. if (lsa == NULL)
  800. {
  801. char id[16], adv_router[16];
  802. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  803. {
  804. inet_ntop (AF_INET, &e->id, id, sizeof (id));
  805. inet_ntop (AF_INET, &e->adv_router, adv_router,
  806. sizeof (adv_router));
  807. zlog_info ("Can't find requested [%s Id:%s Adv:%s]",
  808. OSPF6_LSTYPE_NAME (e->type), id, adv_router);
  809. }
  810. thread_add_event (master, bad_lsreq, on, 0);
  811. return;
  812. }
  813. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->lsupdate_list);
  814. }
  815. if (p != OSPF6_MESSAGE_END (oh))
  816. {
  817. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  818. zlog_info ("Trailing garbage ignored");
  819. }
  820. /* schedule send lsupdate */
  821. THREAD_OFF (on->thread_send_lsupdate);
  822. on->thread_send_lsupdate =
  823. thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
  824. }
  825. void
  826. ospf6_lsupdate_recv (struct in6_addr *src, struct in6_addr *dst,
  827. struct ospf6_interface *oi, struct ospf6_header *oh)
  828. {
  829. struct ospf6_neighbor *on;
  830. struct ospf6_lsupdate *lsupdate;
  831. unsigned long num;
  832. char *p;
  833. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  834. return;
  835. on = ospf6_neighbor_lookup (oh->router_id, oi);
  836. if (on == NULL)
  837. {
  838. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  839. zlog_info ("Neighbor not found, ignore");
  840. return;
  841. }
  842. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  843. {
  844. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  845. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  846. return;
  847. }
  848. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  849. on->state != OSPF6_NEIGHBOR_LOADING &&
  850. on->state != OSPF6_NEIGHBOR_FULL)
  851. {
  852. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  853. zlog_info ("Neighbor state less than Exchange, ignore");
  854. return;
  855. }
  856. lsupdate = (struct ospf6_lsupdate *)
  857. ((caddr_t) oh + sizeof (struct ospf6_header));
  858. num = ntohl (lsupdate->lsa_number);
  859. /* Process LSAs */
  860. for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  861. p < OSPF6_MESSAGE_END (oh) &&
  862. p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh);
  863. p += OSPF6_LSA_SIZE (p))
  864. {
  865. if (num == 0)
  866. break;
  867. if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header))
  868. {
  869. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  870. zlog_info ("Malformed LSA length, quit processing");
  871. break;
  872. }
  873. ospf6_receive_lsa (on, (struct ospf6_lsa_header *) p);
  874. num--;
  875. }
  876. if (num != 0)
  877. {
  878. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  879. zlog_info ("Malformed LSA number or LSA length");
  880. }
  881. if (p != OSPF6_MESSAGE_END (oh))
  882. {
  883. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  884. zlog_info ("Trailing garbage ignored");
  885. }
  886. /* RFC2328 Section 10.9: When the neighbor responds to these requests
  887. with the proper Link State Update packet(s), the Link state request
  888. list is truncated and a new Link State Request packet is sent. */
  889. /* send new Link State Request packet if this LS Update packet
  890. can be recognized as a response to our previous LS Request */
  891. if (! IN6_IS_ADDR_MULTICAST (dst) &&
  892. (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
  893. on->state == OSPF6_NEIGHBOR_LOADING))
  894. {
  895. THREAD_OFF (on->thread_send_lsreq);
  896. on->thread_send_lsreq =
  897. thread_add_event (master, ospf6_lsreq_send, on, 0);
  898. }
  899. }
  900. void
  901. ospf6_lsack_recv (struct in6_addr *src, struct in6_addr *dst,
  902. struct ospf6_interface *oi, struct ospf6_header *oh)
  903. {
  904. struct ospf6_neighbor *on;
  905. char *p;
  906. struct ospf6_lsa *his, *mine;
  907. struct ospf6_lsdb *lsdb = NULL;
  908. assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK);
  909. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  910. return;
  911. on = ospf6_neighbor_lookup (oh->router_id, oi);
  912. if (on == NULL)
  913. {
  914. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  915. zlog_info ("Neighbor not found, ignore");
  916. return;
  917. }
  918. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  919. {
  920. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  921. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  922. return;
  923. }
  924. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  925. on->state != OSPF6_NEIGHBOR_LOADING &&
  926. on->state != OSPF6_NEIGHBOR_FULL)
  927. {
  928. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  929. zlog_info ("Neighbor state less than Exchange, ignore");
  930. return;
  931. }
  932. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  933. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  934. p += sizeof (struct ospf6_lsa_header))
  935. {
  936. his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
  937. switch (OSPF6_LSA_SCOPE (his->header->type))
  938. {
  939. case OSPF6_SCOPE_LINKLOCAL:
  940. lsdb = on->ospf6_if->lsdb;
  941. break;
  942. case OSPF6_SCOPE_AREA:
  943. lsdb = on->ospf6_if->area->lsdb;
  944. break;
  945. case OSPF6_SCOPE_AS:
  946. lsdb = on->ospf6_if->area->ospf6->lsdb;
  947. break;
  948. case OSPF6_SCOPE_RESERVED:
  949. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  950. zlog_info ("Ignoring LSA of reserved scope");
  951. ospf6_lsa_delete (his);
  952. continue;
  953. break;
  954. }
  955. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  956. zlog_info ("%s acknowledged by %s", his->name, on->name);
  957. /* Find database copy */
  958. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  959. his->header->adv_router, lsdb);
  960. if (mine == NULL)
  961. {
  962. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  963. zlog_info ("No database copy");
  964. ospf6_lsa_delete (his);
  965. continue;
  966. }
  967. /* Check if the LSA is on his retrans-list */
  968. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  969. his->header->adv_router, on->retrans_list);
  970. if (mine == NULL)
  971. {
  972. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  973. zlog_info ("Not on %s's retrans-list", on->name);
  974. ospf6_lsa_delete (his);
  975. continue;
  976. }
  977. if (ospf6_lsa_compare (his, mine) != 0)
  978. {
  979. /* Log this questionable acknowledgement,
  980. and examine the next one. */
  981. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  982. zlog_info ("Questionable acknowledgement");
  983. ospf6_lsa_delete (his);
  984. continue;
  985. }
  986. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  987. zlog_info ("Acknowledged, remove from %s's retrans-list",
  988. on->name);
  989. if (OSPF6_LSA_IS_MAXAGE (mine))
  990. ospf6_maxage_remove (on->ospf6_if->area->ospf6);
  991. ospf6_decrement_retrans_count (mine);
  992. ospf6_lsdb_remove (mine, on->retrans_list);
  993. ospf6_lsa_delete (his);
  994. }
  995. if (p != OSPF6_MESSAGE_END (oh))
  996. {
  997. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  998. zlog_info ("Trailing garbage ignored");
  999. }
  1000. }
  1001. char *recvbuf = NULL;
  1002. char *sendbuf = NULL;
  1003. int iobuflen = 0;
  1004. int
  1005. ospf6_iobuf_size (int size)
  1006. {
  1007. char *recvnew, *sendnew;
  1008. if (size <= iobuflen)
  1009. return iobuflen;
  1010. recvnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
  1011. sendnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
  1012. if (recvnew == NULL || sendnew == NULL)
  1013. {
  1014. if (recvnew)
  1015. XFREE (MTYPE_OSPF6_MESSAGE, recvnew);
  1016. if (sendnew)
  1017. XFREE (MTYPE_OSPF6_MESSAGE, sendnew);
  1018. zlog_info ("Could not allocate I/O buffer of size %d.", size);
  1019. return iobuflen;
  1020. }
  1021. if (recvbuf)
  1022. XFREE (MTYPE_OSPF6_MESSAGE, recvbuf);
  1023. if (sendbuf)
  1024. XFREE (MTYPE_OSPF6_MESSAGE, sendbuf);
  1025. recvbuf = recvnew;
  1026. sendbuf = sendnew;
  1027. iobuflen = size;
  1028. return iobuflen;
  1029. }
  1030. int
  1031. ospf6_receive (struct thread *thread)
  1032. {
  1033. int sockfd, len;
  1034. char srcname[64], dstname[64];
  1035. struct in6_addr src, dst;
  1036. unsigned int ifindex;
  1037. struct iovec iovector[2];
  1038. struct ospf6_interface *oi;
  1039. struct ospf6_header *oh;
  1040. /* add next read thread */
  1041. sockfd = THREAD_FD (thread);
  1042. thread_add_read (master, ospf6_receive, NULL, sockfd);
  1043. /* initialize */
  1044. memset (recvbuf, 0, iobuflen);
  1045. iovector[0].iov_base = recvbuf;
  1046. iovector[0].iov_len = iobuflen;
  1047. iovector[1].iov_base = NULL;
  1048. iovector[1].iov_len = 0;
  1049. /* receive message */
  1050. len = ospf6_recvmsg (&src, &dst, &ifindex, iovector);
  1051. if (len > iobuflen)
  1052. {
  1053. zlog_err ("Excess message read");
  1054. return 0;
  1055. }
  1056. else if (len < sizeof (struct ospf6_header))
  1057. {
  1058. zlog_err ("Deficient message read");
  1059. return 0;
  1060. }
  1061. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  1062. if (oi == NULL || oi->area == NULL)
  1063. {
  1064. zlog_info ("Message received on disabled interface");
  1065. return 0;
  1066. }
  1067. oh = (struct ospf6_header *) recvbuf;
  1068. /* Log */
  1069. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  1070. {
  1071. inet_ntop (AF_INET6, &src, srcname, sizeof (srcname));
  1072. inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname));
  1073. zlog_info ("%s received on %s",
  1074. OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
  1075. zlog_info (" src: %s", srcname);
  1076. zlog_info (" dst: %s", dstname);
  1077. if (len != ntohs (oh->length))
  1078. zlog_info ("Message length does not match actually received: %d", len);
  1079. switch (oh->type)
  1080. {
  1081. case OSPF6_MESSAGE_TYPE_HELLO:
  1082. ospf6_hello_print (oh);
  1083. break;
  1084. case OSPF6_MESSAGE_TYPE_DBDESC:
  1085. ospf6_dbdesc_print (oh);
  1086. break;
  1087. case OSPF6_MESSAGE_TYPE_LSREQ:
  1088. ospf6_lsreq_print (oh);
  1089. break;
  1090. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1091. ospf6_lsupdate_print (oh);
  1092. break;
  1093. case OSPF6_MESSAGE_TYPE_LSACK:
  1094. ospf6_lsack_print (oh);
  1095. break;
  1096. default:
  1097. zlog_info ("Unknown message");
  1098. break;
  1099. }
  1100. }
  1101. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1102. {
  1103. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  1104. zlog_info ("Ignore message on passive interface %s",
  1105. oi->interface->name);
  1106. return 0;
  1107. }
  1108. switch (oh->type)
  1109. {
  1110. case OSPF6_MESSAGE_TYPE_HELLO:
  1111. ospf6_hello_recv (&src, &dst, oi, oh);
  1112. break;
  1113. case OSPF6_MESSAGE_TYPE_DBDESC:
  1114. ospf6_dbdesc_recv (&src, &dst, oi, oh);
  1115. break;
  1116. case OSPF6_MESSAGE_TYPE_LSREQ:
  1117. ospf6_lsreq_recv (&src, &dst, oi, oh);
  1118. break;
  1119. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1120. ospf6_lsupdate_recv (&src, &dst, oi, oh);
  1121. break;
  1122. case OSPF6_MESSAGE_TYPE_LSACK:
  1123. ospf6_lsack_recv (&src, &dst, oi, oh);
  1124. break;
  1125. default:
  1126. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1127. zlog_info ("Unknown message");
  1128. break;
  1129. }
  1130. return 0;
  1131. }
  1132. void
  1133. ospf6_send (struct in6_addr *src, struct in6_addr *dst,
  1134. struct ospf6_interface *oi, struct ospf6_header *oh)
  1135. {
  1136. int len;
  1137. char srcname[64], dstname[64];
  1138. struct iovec iovector[2];
  1139. /* initialize */
  1140. iovector[0].iov_base = (caddr_t) oh;
  1141. iovector[0].iov_len = ntohs (oh->length);
  1142. iovector[1].iov_base = NULL;
  1143. iovector[1].iov_len = 0;
  1144. /* fill OSPF header */
  1145. oh->version = OSPFV3_VERSION;
  1146. /* message type must be set before */
  1147. /* message length must be set before */
  1148. oh->router_id = oi->area->ospf6->router_id;
  1149. oh->area_id = oi->area->area_id;
  1150. /* checksum is calculated by kernel */
  1151. oh->instance_id = oi->instance_id;
  1152. oh->reserved = 0;
  1153. /* Log */
  1154. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, SEND))
  1155. {
  1156. inet_ntop (AF_INET6, dst, dstname, sizeof (dstname));
  1157. if (src)
  1158. inet_ntop (AF_INET6, src, srcname, sizeof (srcname));
  1159. else
  1160. memset (srcname, 0, sizeof (srcname));
  1161. zlog_info ("%s send on %s",
  1162. OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
  1163. zlog_info (" src: %s", srcname);
  1164. zlog_info (" dst: %s", dstname);
  1165. switch (oh->type)
  1166. {
  1167. case OSPF6_MESSAGE_TYPE_HELLO:
  1168. ospf6_hello_print (oh);
  1169. break;
  1170. case OSPF6_MESSAGE_TYPE_DBDESC:
  1171. ospf6_dbdesc_print (oh);
  1172. break;
  1173. case OSPF6_MESSAGE_TYPE_LSREQ:
  1174. ospf6_lsreq_print (oh);
  1175. break;
  1176. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1177. ospf6_lsupdate_print (oh);
  1178. break;
  1179. case OSPF6_MESSAGE_TYPE_LSACK:
  1180. ospf6_lsack_print (oh);
  1181. break;
  1182. default:
  1183. zlog_info ("Unknown message");
  1184. assert (0);
  1185. break;
  1186. }
  1187. }
  1188. /* send message */
  1189. len = ospf6_sendmsg (src, dst, &oi->interface->ifindex, iovector);
  1190. if (len != ntohs (oh->length))
  1191. zlog_err ("Could not send entire message");
  1192. }
  1193. int
  1194. ospf6_hello_send (struct thread *thread)
  1195. {
  1196. struct ospf6_interface *oi;
  1197. struct ospf6_header *oh;
  1198. struct ospf6_hello *hello;
  1199. char *p;
  1200. listnode node;
  1201. struct ospf6_neighbor *on;
  1202. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1203. oi->thread_send_hello = (struct thread *) NULL;
  1204. if (oi->state <= OSPF6_INTERFACE_DOWN)
  1205. {
  1206. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
  1207. zlog_info ("Unable to send Hello on down interface %s",
  1208. oi->interface->name);
  1209. return 0;
  1210. }
  1211. /* set next thread */
  1212. oi->thread_send_hello = thread_add_timer (master, ospf6_hello_send,
  1213. oi, oi->hello_interval);
  1214. memset (sendbuf, 0, iobuflen);
  1215. oh = (struct ospf6_header *) sendbuf;
  1216. hello = (struct ospf6_hello *)((caddr_t) oh + sizeof (struct ospf6_header));
  1217. hello->interface_id = htonl (oi->interface->ifindex);
  1218. hello->priority = oi->priority;
  1219. hello->options[0] = oi->area->options[0];
  1220. hello->options[1] = oi->area->options[1];
  1221. hello->options[2] = oi->area->options[2];
  1222. hello->hello_interval = htons (oi->hello_interval);
  1223. hello->dead_interval = htons (oi->dead_interval);
  1224. hello->drouter = oi->drouter;
  1225. hello->bdrouter = oi->bdrouter;
  1226. p = (char *)((caddr_t) hello + sizeof (struct ospf6_hello));
  1227. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  1228. {
  1229. on = (struct ospf6_neighbor *) getdata (node);
  1230. if (on->state < OSPF6_NEIGHBOR_INIT)
  1231. continue;
  1232. if (p - sendbuf + sizeof (u_int32_t) > oi->ifmtu)
  1233. {
  1234. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
  1235. zlog_info ("sending Hello message: exceeds I/F MTU");
  1236. break;
  1237. }
  1238. memcpy (p, &on->router_id, sizeof (u_int32_t));
  1239. p += sizeof (u_int32_t);
  1240. }
  1241. oh->type = OSPF6_MESSAGE_TYPE_HELLO;
  1242. oh->length = htons (p - sendbuf);
  1243. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1244. return 0;
  1245. }
  1246. int
  1247. ospf6_dbdesc_send (struct thread *thread)
  1248. {
  1249. struct ospf6_neighbor *on;
  1250. struct ospf6_header *oh;
  1251. struct ospf6_dbdesc *dbdesc;
  1252. char *p;
  1253. struct ospf6_lsa *lsa;
  1254. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1255. on->thread_send_dbdesc = (struct thread *) NULL;
  1256. if (on->state < OSPF6_NEIGHBOR_EXSTART)
  1257. {
  1258. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_DBDESC, SEND))
  1259. zlog_info ("Quit to send DbDesc to neighbor %s state %s",
  1260. on->name, ospf6_neighbor_state_str[on->state]);
  1261. return 0;
  1262. }
  1263. /* set next thread if master */
  1264. if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
  1265. on->thread_send_dbdesc =
  1266. thread_add_timer (master, ospf6_dbdesc_send, on,
  1267. on->ospf6_if->rxmt_interval);
  1268. memset (sendbuf, 0, iobuflen);
  1269. oh = (struct ospf6_header *) sendbuf;
  1270. dbdesc = (struct ospf6_dbdesc *)((caddr_t) oh +
  1271. sizeof (struct ospf6_header));
  1272. /* if this is initial one, initialize sequence number for DbDesc */
  1273. if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
  1274. {
  1275. struct timeval tv;
  1276. if (gettimeofday (&tv, (struct timezone *) NULL) < 0)
  1277. tv.tv_sec = 1;
  1278. on->dbdesc_seqnum = tv.tv_sec;
  1279. }
  1280. dbdesc->options[0] = on->ospf6_if->area->options[0];
  1281. dbdesc->options[1] = on->ospf6_if->area->options[1];
  1282. dbdesc->options[2] = on->ospf6_if->area->options[2];
  1283. dbdesc->ifmtu = htons (on->ospf6_if->ifmtu);
  1284. dbdesc->bits = on->dbdesc_bits;
  1285. dbdesc->seqnum = htonl (on->dbdesc_seqnum);
  1286. /* if this is not initial one, set LSA headers in dbdesc */
  1287. p = (char *)((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  1288. if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
  1289. {
  1290. for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
  1291. lsa = ospf6_lsdb_next (lsa))
  1292. {
  1293. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1294. /* MTU check */
  1295. if (p - sendbuf + sizeof (struct ospf6_lsa_header) >
  1296. on->ospf6_if->ifmtu)
  1297. {
  1298. ospf6_lsa_unlock (lsa);
  1299. break;
  1300. }
  1301. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1302. p += sizeof (struct ospf6_lsa_header);
  1303. }
  1304. }
  1305. oh->type = OSPF6_MESSAGE_TYPE_DBDESC;
  1306. oh->length = htons (p - sendbuf);
  1307. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1308. on->ospf6_if, oh);
  1309. return 0;
  1310. }
  1311. int
  1312. ospf6_dbdesc_send_newone (struct thread *thread)
  1313. {
  1314. struct ospf6_neighbor *on;
  1315. struct ospf6_lsa *lsa;
  1316. unsigned int size = 0;
  1317. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1318. ospf6_lsdb_remove_all (on->dbdesc_list);
  1319. /* move LSAs from summary_list to dbdesc_list (within neighbor structure)
  1320. so that ospf6_send_dbdesc () can send those LSAs */
  1321. size = sizeof (struct ospf6_lsa_header) + sizeof (struct ospf6_dbdesc);
  1322. for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
  1323. lsa = ospf6_lsdb_next (lsa))
  1324. {
  1325. if (size + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
  1326. {
  1327. ospf6_lsa_unlock (lsa);
  1328. break;
  1329. }
  1330. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->dbdesc_list);
  1331. ospf6_lsdb_remove (lsa, on->summary_list);
  1332. size += sizeof (struct ospf6_lsa_header);
  1333. }
  1334. if (on->summary_list->count == 0)
  1335. UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  1336. /* If slave, More bit check must be done here */
  1337. if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */
  1338. ! CHECK_FLAG (on->dbdesc_last.bits, OSPF6_DBDESC_MBIT) &&
  1339. ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
  1340. thread_add_event (master, exchange_done, on, 0);
  1341. thread_execute (master, ospf6_dbdesc_send, on, 0);
  1342. return 0;
  1343. }
  1344. int
  1345. ospf6_lsreq_send (struct thread *thread)
  1346. {
  1347. struct ospf6_neighbor *on;
  1348. struct ospf6_header *oh;
  1349. struct ospf6_lsreq_entry *e;
  1350. char *p;
  1351. struct ospf6_lsa *lsa;
  1352. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1353. on->thread_send_lsreq = (struct thread *) NULL;
  1354. /* LSReq will be sent only in ExStart or Loading */
  1355. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  1356. on->state != OSPF6_NEIGHBOR_LOADING)
  1357. {
  1358. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSREQ, SEND))
  1359. zlog_info ("Quit to send LSReq to neighbor %s state %s",
  1360. on->name, ospf6_neighbor_state_str[on->state]);
  1361. return 0;
  1362. }
  1363. /* schedule loading_done if request list is empty */
  1364. if (on->request_list->count == 0)
  1365. {
  1366. thread_add_event (master, loading_done, on, 0);
  1367. return 0;
  1368. }
  1369. /* set next thread */
  1370. on->thread_send_lsreq =
  1371. thread_add_timer (master, ospf6_lsreq_send, on,
  1372. on->ospf6_if->rxmt_interval);
  1373. memset (sendbuf, 0, iobuflen);
  1374. oh = (struct ospf6_header *) sendbuf;
  1375. /* set Request entries in lsreq */
  1376. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1377. for (lsa = ospf6_lsdb_head (on->request_list); lsa;
  1378. lsa = ospf6_lsdb_next (lsa))
  1379. {
  1380. /* MTU check */
  1381. if (p - sendbuf + sizeof (struct ospf6_lsreq_entry) > on->ospf6_if->ifmtu)
  1382. {
  1383. ospf6_lsa_unlock (lsa);
  1384. break;
  1385. }
  1386. e = (struct ospf6_lsreq_entry *) p;
  1387. e->type = lsa->header->type;
  1388. e->id = lsa->header->id;
  1389. e->adv_router = lsa->header->adv_router;
  1390. p += sizeof (struct ospf6_lsreq_entry);
  1391. }
  1392. oh->type = OSPF6_MESSAGE_TYPE_LSREQ;
  1393. oh->length = htons (p - sendbuf);
  1394. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1395. on->ospf6_if, oh);
  1396. return 0;
  1397. }
  1398. int
  1399. ospf6_lsupdate_send_neighbor (struct thread *thread)
  1400. {
  1401. struct ospf6_neighbor *on;
  1402. struct ospf6_header *oh;
  1403. struct ospf6_lsupdate *lsupdate;
  1404. char *p;
  1405. int num;
  1406. struct ospf6_lsa *lsa;
  1407. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1408. on->thread_send_lsupdate = (struct thread *) NULL;
  1409. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1410. zlog_info ("LSUpdate to neighbor %s", on->name);
  1411. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  1412. {
  1413. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1414. zlog_info ("Quit to send (neighbor state %s)",
  1415. ospf6_neighbor_state_str[on->state]);
  1416. return 0;
  1417. }
  1418. /* if we have nothing to send, return */
  1419. if (on->lsupdate_list->count == 0 &&
  1420. on->retrans_list->count == 0)
  1421. {
  1422. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1423. zlog_info ("Quit to send (nothing to send)");
  1424. return 0;
  1425. }
  1426. memset (sendbuf, 0, iobuflen);
  1427. oh = (struct ospf6_header *) sendbuf;
  1428. lsupdate = (struct ospf6_lsupdate *)
  1429. ((caddr_t) oh + sizeof (struct ospf6_header));
  1430. p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  1431. num = 0;
  1432. /* lsupdate_list lists those LSA which doesn't need to be
  1433. retransmitted. remove those from the list */
  1434. for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
  1435. lsa = ospf6_lsdb_next (lsa))
  1436. {
  1437. /* MTU check */
  1438. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
  1439. {
  1440. ospf6_lsa_unlock (lsa);
  1441. break;
  1442. }
  1443. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1444. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1445. p += OSPF6_LSA_SIZE (lsa->header);
  1446. num++;
  1447. assert (lsa->lock == 2);
  1448. ospf6_lsdb_remove (lsa, on->lsupdate_list);
  1449. }
  1450. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  1451. lsa = ospf6_lsdb_next (lsa))
  1452. {
  1453. /* MTU check */
  1454. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
  1455. {
  1456. ospf6_lsa_unlock (lsa);
  1457. break;
  1458. }
  1459. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1460. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1461. p += OSPF6_LSA_SIZE (lsa->header);
  1462. num++;
  1463. }
  1464. lsupdate->lsa_number = htonl (num);
  1465. oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1466. oh->length = htons (p - sendbuf);
  1467. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1468. on->ospf6_if, oh);
  1469. if (on->lsupdate_list->count != 0 ||
  1470. on->retrans_list->count != 0)
  1471. {
  1472. if (on->lsupdate_list->count != 0)
  1473. on->thread_send_lsupdate =
  1474. thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
  1475. else
  1476. on->thread_send_lsupdate =
  1477. thread_add_timer (master, ospf6_lsupdate_send_neighbor, on,
  1478. on->ospf6_if->rxmt_interval);
  1479. }
  1480. return 0;
  1481. }
  1482. int
  1483. ospf6_lsupdate_send_interface (struct thread *thread)
  1484. {
  1485. struct ospf6_interface *oi;
  1486. struct ospf6_header *oh;
  1487. struct ospf6_lsupdate *lsupdate;
  1488. char *p;
  1489. int num;
  1490. struct ospf6_lsa *lsa;
  1491. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1492. oi->thread_send_lsupdate = (struct thread *) NULL;
  1493. if (oi->state <= OSPF6_INTERFACE_WAITING)
  1494. {
  1495. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1496. zlog_info ("Quit to send LSUpdate to interface %s state %s",
  1497. oi->interface->name, ospf6_interface_state_str[oi->state]);
  1498. return 0;
  1499. }
  1500. /* if we have nothing to send, return */
  1501. if (oi->lsupdate_list->count == 0)
  1502. return 0;
  1503. if (IS_OSPF6_DEBUG_LSA (SEND))
  1504. zlog_info ("LSA Send to %s", oi->interface->name);
  1505. memset (sendbuf, 0, iobuflen);
  1506. oh = (struct ospf6_header *) sendbuf;
  1507. lsupdate = (struct ospf6_lsupdate *)((caddr_t) oh +
  1508. sizeof (struct ospf6_header));
  1509. p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  1510. num = 0;
  1511. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  1512. lsa = ospf6_lsdb_next (lsa))
  1513. {
  1514. /* MTU check */
  1515. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > oi->ifmtu)
  1516. {
  1517. ospf6_lsa_unlock (lsa);
  1518. break;
  1519. }
  1520. if (IS_OSPF6_DEBUG_LSA (SEND))
  1521. ospf6_lsa_header_print (lsa);
  1522. ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
  1523. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1524. p += OSPF6_LSA_SIZE (lsa->header);
  1525. num++;
  1526. assert (lsa->lock == 2);
  1527. ospf6_lsdb_remove (lsa, oi->lsupdate_list);
  1528. }
  1529. lsupdate->lsa_number = htonl (num);
  1530. oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1531. oh->length = htons (p - sendbuf);
  1532. if (oi->state == OSPF6_INTERFACE_DR ||
  1533. oi->state == OSPF6_INTERFACE_BDR)
  1534. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1535. else
  1536. ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
  1537. if (oi->lsupdate_list->count > 0)
  1538. {
  1539. oi->thread_send_lsupdate =
  1540. thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0);
  1541. }
  1542. return 0;
  1543. }
  1544. int
  1545. ospf6_lsack_send_neighbor (struct thread *thread)
  1546. {
  1547. struct ospf6_neighbor *on;
  1548. struct ospf6_header *oh;
  1549. char *p;
  1550. struct ospf6_lsa *lsa;
  1551. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1552. on->thread_send_lsack = (struct thread *) NULL;
  1553. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  1554. {
  1555. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
  1556. zlog_info ("Quit to send LSAck to neighbor %s state %s",
  1557. on->name, ospf6_neighbor_state_str[on->state]);
  1558. return 0;
  1559. }
  1560. /* if we have nothing to send, return */
  1561. if (on->lsack_list->count == 0)
  1562. return 0;
  1563. memset (sendbuf, 0, iobuflen);
  1564. oh = (struct ospf6_header *) sendbuf;
  1565. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1566. for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
  1567. lsa = ospf6_lsdb_next (lsa))
  1568. {
  1569. /* MTU check */
  1570. if (p - sendbuf + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
  1571. {
  1572. /* if we run out of packet size/space here,
  1573. better to try again soon. */
  1574. THREAD_OFF (on->thread_send_lsack);
  1575. on->thread_send_lsack =
  1576. thread_add_event (master, ospf6_lsack_send_neighbor, on, 0);
  1577. ospf6_lsa_unlock (lsa);
  1578. break;
  1579. }
  1580. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1581. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1582. p += sizeof (struct ospf6_lsa_header);
  1583. assert (lsa->lock == 2);
  1584. ospf6_lsdb_remove (lsa, on->lsack_list);
  1585. }
  1586. oh->type = OSPF6_MESSAGE_TYPE_LSACK;
  1587. oh->length = htons (p - sendbuf);
  1588. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1589. on->ospf6_if, oh);
  1590. return 0;
  1591. }
  1592. int
  1593. ospf6_lsack_send_interface (struct thread *thread)
  1594. {
  1595. struct ospf6_interface *oi;
  1596. struct ospf6_header *oh;
  1597. char *p;
  1598. struct ospf6_lsa *lsa;
  1599. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1600. oi->thread_send_lsack = (struct thread *) NULL;
  1601. if (oi->state <= OSPF6_INTERFACE_WAITING)
  1602. {
  1603. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
  1604. zlog_info ("Quit to send LSAck to interface %s state %s",
  1605. oi->interface->name, ospf6_interface_state_str[oi->state]);
  1606. return 0;
  1607. }
  1608. /* if we have nothing to send, return */
  1609. if (oi->lsack_list->count == 0)
  1610. return 0;
  1611. memset (sendbuf, 0, iobuflen);
  1612. oh = (struct ospf6_header *) sendbuf;
  1613. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1614. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  1615. lsa = ospf6_lsdb_next (lsa))
  1616. {
  1617. /* MTU check */
  1618. if (p - sendbuf + sizeof (struct ospf6_lsa_header) > oi->ifmtu)
  1619. {
  1620. /* if we run out of packet size/space here,
  1621. better to try again soon. */
  1622. THREAD_OFF (oi->thread_send_lsack);
  1623. oi->thread_send_lsack =
  1624. thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
  1625. ospf6_lsa_unlock (lsa);
  1626. break;
  1627. }
  1628. ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
  1629. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1630. p += sizeof (struct ospf6_lsa_header);
  1631. assert (lsa->lock == 2);
  1632. ospf6_lsdb_remove (lsa, oi->lsack_list);
  1633. }
  1634. oh->type = OSPF6_MESSAGE_TYPE_LSACK;
  1635. oh->length = htons (p - sendbuf);
  1636. if (oi->state == OSPF6_INTERFACE_DR ||
  1637. oi->state == OSPF6_INTERFACE_BDR)
  1638. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1639. else
  1640. ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
  1641. if (oi->thread_send_lsack == NULL && oi->lsack_list->count > 0)
  1642. {
  1643. oi->thread_send_lsack =
  1644. thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
  1645. }
  1646. return 0;
  1647. }
  1648. /* Commands */
  1649. DEFUN (debug_ospf6_message,
  1650. debug_ospf6_message_cmd,
  1651. "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
  1652. DEBUG_STR
  1653. OSPF6_STR
  1654. "Debug OSPFv3 message\n"
  1655. "Debug Unknown message\n"
  1656. "Debug Hello message\n"
  1657. "Debug Database Description message\n"
  1658. "Debug Link State Request message\n"
  1659. "Debug Link State Update message\n"
  1660. "Debug Link State Acknowledgement message\n"
  1661. "Debug All message\n"
  1662. )
  1663. {
  1664. unsigned char level = 0;
  1665. int type = 0;
  1666. int i;
  1667. assert (argc > 0);
  1668. /* check type */
  1669. if (! strncmp (argv[0], "u", 1))
  1670. type = OSPF6_MESSAGE_TYPE_UNKNOWN;
  1671. else if (! strncmp (argv[0], "h", 1))
  1672. type = OSPF6_MESSAGE_TYPE_HELLO;
  1673. else if (! strncmp (argv[0], "d", 1))
  1674. type = OSPF6_MESSAGE_TYPE_DBDESC;
  1675. else if (! strncmp (argv[0], "lsr", 3))
  1676. type = OSPF6_MESSAGE_TYPE_LSREQ;
  1677. else if (! strncmp (argv[0], "lsu", 3))
  1678. type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1679. else if (! strncmp (argv[0], "lsa", 3))
  1680. type = OSPF6_MESSAGE_TYPE_LSACK;
  1681. else if (! strncmp (argv[0], "a", 1))
  1682. type = OSPF6_MESSAGE_TYPE_ALL;
  1683. if (argc == 1)
  1684. level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
  1685. else if (! strncmp (argv[1], "s", 1))
  1686. level = OSPF6_DEBUG_MESSAGE_SEND;
  1687. else if (! strncmp (argv[1], "r", 1))
  1688. level = OSPF6_DEBUG_MESSAGE_RECV;
  1689. if (type == OSPF6_MESSAGE_TYPE_ALL)
  1690. {
  1691. for (i = 0; i < 6; i++)
  1692. OSPF6_DEBUG_MESSAGE_ON (i, level);
  1693. }
  1694. else
  1695. OSPF6_DEBUG_MESSAGE_ON (type, level);
  1696. return CMD_SUCCESS;
  1697. }
  1698. ALIAS (debug_ospf6_message,
  1699. debug_ospf6_message_sendrecv_cmd,
  1700. "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
  1701. DEBUG_STR
  1702. OSPF6_STR
  1703. "Debug OSPFv3 message\n"
  1704. "Debug Unknown message\n"
  1705. "Debug Hello message\n"
  1706. "Debug Database Description message\n"
  1707. "Debug Link State Request message\n"
  1708. "Debug Link State Update message\n"
  1709. "Debug Link State Acknowledgement message\n"
  1710. "Debug All message\n"
  1711. "Debug only sending message\n"
  1712. "Debug only receiving message\n"
  1713. );
  1714. DEFUN (no_debug_ospf6_message,
  1715. no_debug_ospf6_message_cmd,
  1716. "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
  1717. NO_STR
  1718. DEBUG_STR
  1719. OSPF6_STR
  1720. "Debug OSPFv3 message\n"
  1721. "Debug Unknown message\n"
  1722. "Debug Hello message\n"
  1723. "Debug Database Description message\n"
  1724. "Debug Link State Request message\n"
  1725. "Debug Link State Update message\n"
  1726. "Debug Link State Acknowledgement message\n"
  1727. "Debug All message\n"
  1728. )
  1729. {
  1730. unsigned char level = 0;
  1731. int type = 0;
  1732. int i;
  1733. assert (argc > 0);
  1734. /* check type */
  1735. if (! strncmp (argv[0], "u", 1))
  1736. type = OSPF6_MESSAGE_TYPE_UNKNOWN;
  1737. else if (! strncmp (argv[0], "h", 1))
  1738. type = OSPF6_MESSAGE_TYPE_HELLO;
  1739. else if (! strncmp (argv[0], "d", 1))
  1740. type = OSPF6_MESSAGE_TYPE_DBDESC;
  1741. else if (! strncmp (argv[0], "lsr", 3))
  1742. type = OSPF6_MESSAGE_TYPE_LSREQ;
  1743. else if (! strncmp (argv[0], "lsu", 3))
  1744. type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1745. else if (! strncmp (argv[0], "lsa", 3))
  1746. type = OSPF6_MESSAGE_TYPE_LSACK;
  1747. else if (! strncmp (argv[0], "a", 1))
  1748. type = OSPF6_MESSAGE_TYPE_ALL;
  1749. if (argc == 1)
  1750. level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
  1751. else if (! strncmp (argv[1], "s", 1))
  1752. level = OSPF6_DEBUG_MESSAGE_SEND;
  1753. else if (! strncmp (argv[1], "r", 1))
  1754. level = OSPF6_DEBUG_MESSAGE_RECV;
  1755. if (type == OSPF6_MESSAGE_TYPE_ALL)
  1756. {
  1757. for (i = 0; i < 6; i++)
  1758. OSPF6_DEBUG_MESSAGE_OFF (i, level);
  1759. }
  1760. else
  1761. OSPF6_DEBUG_MESSAGE_OFF (type, level);
  1762. return CMD_SUCCESS;
  1763. }
  1764. ALIAS (no_debug_ospf6_message,
  1765. no_debug_ospf6_message_sendrecv_cmd,
  1766. "no debug ospf6 message "
  1767. "(unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
  1768. NO_STR
  1769. DEBUG_STR
  1770. OSPF6_STR
  1771. "Debug OSPFv3 message\n"
  1772. "Debug Unknown message\n"
  1773. "Debug Hello message\n"
  1774. "Debug Database Description message\n"
  1775. "Debug Link State Request message\n"
  1776. "Debug Link State Update message\n"
  1777. "Debug Link State Acknowledgement message\n"
  1778. "Debug All message\n"
  1779. "Debug only sending message\n"
  1780. "Debug only receiving message\n"
  1781. );
  1782. int
  1783. config_write_ospf6_debug_message (struct vty *vty)
  1784. {
  1785. char *type_str[] = {"unknown", "hello", "dbdesc",
  1786. "lsreq", "lsupdate", "lsack"};
  1787. unsigned char s = 0, r = 0;
  1788. int i;
  1789. for (i = 0; i < 6; i++)
  1790. {
  1791. if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
  1792. s |= 1 << i;
  1793. if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1794. r |= 1 << i;
  1795. }
  1796. if (s == 0x3f && r == 0x3f)
  1797. {
  1798. vty_out (vty, "debug ospf6 message all%s", VNL);
  1799. return 0;
  1800. }
  1801. if (s == 0x3f && r == 0)
  1802. {
  1803. vty_out (vty, "debug ospf6 message all send%s", VNL);
  1804. return 0;
  1805. }
  1806. else if (s == 0 && r == 0x3f)
  1807. {
  1808. vty_out (vty, "debug ospf6 message all recv%s", VNL);
  1809. return 0;
  1810. }
  1811. /* Unknown message is logged by default */
  1812. if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND) &&
  1813. ! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1814. vty_out (vty, "no debug ospf6 message unknown%s", VNL);
  1815. else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND))
  1816. vty_out (vty, "no debug ospf6 message unknown send%s", VNL);
  1817. else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1818. vty_out (vty, "no debug ospf6 message unknown recv%s", VNL);
  1819. for (i = 1; i < 6; i++)
  1820. {
  1821. if (IS_OSPF6_DEBUG_MESSAGE (i, SEND) &&
  1822. IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1823. vty_out (vty, "debug ospf6 message %s%s", type_str[i], VNL);
  1824. else if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
  1825. vty_out (vty, "debug ospf6 message %s send%s", type_str[i],
  1826. VNL);
  1827. else if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1828. vty_out (vty, "debug ospf6 message %s recv%s", type_str[i],
  1829. VNL);
  1830. }
  1831. return 0;
  1832. }
  1833. void
  1834. install_element_ospf6_debug_message ()
  1835. {
  1836. install_element (ENABLE_NODE, &debug_ospf6_message_cmd);
  1837. install_element (ENABLE_NODE, &no_debug_ospf6_message_cmd);
  1838. install_element (ENABLE_NODE, &debug_ospf6_message_sendrecv_cmd);
  1839. install_element (ENABLE_NODE, &no_debug_ospf6_message_sendrecv_cmd);
  1840. install_element (CONFIG_NODE, &debug_ospf6_message_cmd);
  1841. install_element (CONFIG_NODE, &no_debug_ospf6_message_cmd);
  1842. install_element (CONFIG_NODE, &debug_ospf6_message_sendrecv_cmd);
  1843. install_element (CONFIG_NODE, &no_debug_ospf6_message_sendrecv_cmd);
  1844. }