ospf6_message.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  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 "ospf6d.h"
  29. #include "ospf6_proto.h"
  30. #include "ospf6_lsa.h"
  31. #include "ospf6_lsdb.h"
  32. #include "ospf6_network.h"
  33. #include "ospf6_message.h"
  34. #include "ospf6_top.h"
  35. #include "ospf6_area.h"
  36. #include "ospf6_neighbor.h"
  37. #include "ospf6_interface.h"
  38. #include "ospf6_flood.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 == 0)
  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. his->scope = ospf6_get_lsa_scope (his->header->type, on);
  444. lsdb = ospf6_get_scoped_lsdb (his->header->type, his->scope);
  445. if (lsdb == NULL)
  446. {
  447. zlog_warn ("Can't decide scoped LSDB");
  448. ospf6_lsa_delete (his);
  449. thread_add_event (master, seqnumber_mismatch, on, 0);
  450. return;
  451. }
  452. if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL &&
  453. ospf6_area_is_stub (on->ospf6_if->area))
  454. {
  455. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  456. zlog_info ("E-bit mismatch with LSA Headers");
  457. ospf6_lsa_delete (his);
  458. thread_add_event (master, seqnumber_mismatch, on, 0);
  459. return;
  460. }
  461. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  462. his->header->adv_router, lsdb);
  463. if (mine == NULL || ospf6_lsa_compare (his, mine) < 0)
  464. {
  465. if (IS_OSPF6_DEBUG_LSA (RECV) || IS_OSPF6_DEBUG_LSA (DATABASE))
  466. zlog_info ("Add %s's request-list: %s", on->name, his->name);
  467. ospf6_lsdb_add (his, on->request_list);
  468. }
  469. else
  470. ospf6_lsa_delete (his);
  471. }
  472. if (p != OSPF6_MESSAGE_END (oh))
  473. {
  474. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  475. zlog_info ("Trailing garbage ignored");
  476. }
  477. /* Increment sequence number */
  478. on->dbdesc_seqnum ++;
  479. /* schedule send lsreq */
  480. if (on->thread_send_lsreq == NULL)
  481. on->thread_send_lsreq =
  482. thread_add_event (master, ospf6_lsreq_send, on, 0);
  483. THREAD_OFF (on->thread_send_dbdesc);
  484. /* More bit check */
  485. if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
  486. ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
  487. thread_add_event (master, exchange_done, on, 0);
  488. else
  489. on->thread_send_dbdesc =
  490. thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
  491. /* save last received dbdesc */
  492. memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
  493. }
  494. static void
  495. ospf6_dbdesc_recv_slave (struct ospf6_header *oh,
  496. struct ospf6_neighbor *on)
  497. {
  498. struct ospf6_dbdesc *dbdesc;
  499. char *p;
  500. dbdesc = (struct ospf6_dbdesc *)
  501. ((caddr_t) oh + sizeof (struct ospf6_header));
  502. if (on->state < OSPF6_NEIGHBOR_INIT)
  503. {
  504. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  505. zlog_info ("Neighbor state less than Init, ignore");
  506. return;
  507. }
  508. switch (on->state)
  509. {
  510. case OSPF6_NEIGHBOR_TWOWAY:
  511. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  512. zlog_info ("Neighbor state is 2-Way, ignore");
  513. return;
  514. case OSPF6_NEIGHBOR_INIT:
  515. thread_execute (master, twoway_received, on, 0);
  516. if (on->state != OSPF6_NEIGHBOR_EXSTART)
  517. {
  518. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  519. zlog_info ("Neighbor state is not ExStart, ignore");
  520. return;
  521. }
  522. /* else fall through to ExStart */
  523. case OSPF6_NEIGHBOR_EXSTART:
  524. /* If the neighbor is Master, act as Slave. Schedule negotiation_done
  525. and process LSA Headers. Otherwise, ignore this message */
  526. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) &&
  527. CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
  528. CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) &&
  529. ntohs (oh->length) == sizeof (struct ospf6_header) +
  530. sizeof (struct ospf6_dbdesc))
  531. {
  532. /* set the master/slave bit to slave */
  533. UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
  534. /* set the DD sequence number to one specified by master */
  535. on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
  536. /* schedule NegotiationDone */
  537. thread_execute (master, negotiation_done, on, 0);
  538. /* Record neighbor options */
  539. memcpy (on->options, dbdesc->options, sizeof (on->options));
  540. }
  541. else
  542. {
  543. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  544. zlog_info ("Negotiation failed");
  545. return;
  546. }
  547. break;
  548. case OSPF6_NEIGHBOR_EXCHANGE:
  549. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  550. {
  551. /* Duplicated DatabaseDescription causes slave to retransmit */
  552. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  553. zlog_info ("Duplicated dbdesc causes retransmit");
  554. THREAD_OFF (on->thread_send_dbdesc);
  555. on->thread_send_dbdesc =
  556. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  557. return;
  558. }
  559. if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT))
  560. {
  561. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  562. zlog_info ("Master/Slave bit mismatch");
  563. thread_add_event (master, seqnumber_mismatch, on, 0);
  564. return;
  565. }
  566. if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT))
  567. {
  568. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  569. zlog_info ("Initialize bit mismatch");
  570. thread_add_event (master, seqnumber_mismatch, on, 0);
  571. return;
  572. }
  573. if (memcmp (on->options, dbdesc->options, sizeof (on->options)))
  574. {
  575. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  576. zlog_info ("Option field mismatch");
  577. thread_add_event (master, seqnumber_mismatch, on, 0);
  578. return;
  579. }
  580. if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum + 1)
  581. {
  582. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  583. zlog_info ("Sequence number mismatch (%#lx expected)",
  584. (u_long) on->dbdesc_seqnum + 1);
  585. thread_add_event (master, seqnumber_mismatch, on, 0);
  586. return;
  587. }
  588. break;
  589. case OSPF6_NEIGHBOR_LOADING:
  590. case OSPF6_NEIGHBOR_FULL:
  591. if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
  592. {
  593. /* Duplicated DatabaseDescription causes slave to retransmit */
  594. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  595. zlog_info ("Duplicated dbdesc causes retransmit");
  596. THREAD_OFF (on->thread_send_dbdesc);
  597. on->thread_send_dbdesc =
  598. thread_add_event (master, ospf6_dbdesc_send, on, 0);
  599. return;
  600. }
  601. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  602. zlog_info ("Not duplicate dbdesc in state %s",
  603. ospf6_neighbor_state_str[on->state]);
  604. thread_add_event (master, seqnumber_mismatch, on, 0);
  605. return;
  606. default:
  607. assert (0);
  608. break;
  609. }
  610. /* Process LSA headers */
  611. for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  612. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  613. p += sizeof (struct ospf6_lsa_header))
  614. {
  615. struct ospf6_lsa *his, *mine;
  616. struct ospf6_lsdb *lsdb = NULL;
  617. his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
  618. his->scope = ospf6_get_lsa_scope (his->header->type, on);
  619. lsdb = ospf6_get_scoped_lsdb (his->header->type, his->scope);
  620. if (lsdb == NULL)
  621. {
  622. zlog_warn ("Can't decide scoped LSDB");
  623. ospf6_lsa_delete (his);
  624. thread_add_event (master, seqnumber_mismatch, on, 0);
  625. return;
  626. }
  627. if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL &&
  628. ospf6_area_is_stub (on->ospf6_if->area))
  629. {
  630. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  631. zlog_info ("E-bit mismatch with LSA Headers");
  632. ospf6_lsa_delete (his);
  633. thread_add_event (master, seqnumber_mismatch, on, 0);
  634. return;
  635. }
  636. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  637. his->header->adv_router, lsdb);
  638. if (mine == NULL || ospf6_lsa_compare (his, mine) < 0)
  639. {
  640. if (IS_OSPF6_DEBUG_LSA (RECV) || IS_OSPF6_DEBUG_LSA (DATABASE))
  641. zlog_info ("Add %s to request-list of %s", his->name, on->name);
  642. ospf6_lsdb_add (his, on->request_list);
  643. }
  644. else
  645. ospf6_lsa_delete (his);
  646. }
  647. if (p != OSPF6_MESSAGE_END (oh))
  648. {
  649. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  650. zlog_info ("Trailing garbage ignored");
  651. }
  652. /* Set sequence number to Master's */
  653. on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
  654. /* schedule send lsreq */
  655. if (on->thread_send_lsreq == NULL)
  656. on->thread_send_lsreq =
  657. thread_add_event (master, ospf6_lsreq_send, on, 0);
  658. THREAD_OFF (on->thread_send_dbdesc);
  659. on->thread_send_dbdesc =
  660. thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
  661. /* save last received dbdesc */
  662. memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
  663. }
  664. void
  665. ospf6_dbdesc_recv (struct in6_addr *src, struct in6_addr *dst,
  666. struct ospf6_interface *oi, struct ospf6_header *oh)
  667. {
  668. struct ospf6_neighbor *on;
  669. struct ospf6_dbdesc *dbdesc;
  670. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  671. return;
  672. on = ospf6_neighbor_lookup (oh->router_id, oi);
  673. if (on == NULL)
  674. {
  675. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  676. zlog_info ("Neighbor not found, ignore");
  677. return;
  678. }
  679. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  680. {
  681. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  682. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  683. return;
  684. }
  685. dbdesc = (struct ospf6_dbdesc *)
  686. ((caddr_t) oh + sizeof (struct ospf6_header));
  687. /* Interface MTU check */
  688. if (ntohs (dbdesc->ifmtu) != oi->ifmtu)
  689. {
  690. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  691. zlog_info ("I/F MTU mismatch");
  692. return;
  693. }
  694. if (dbdesc->reserved1 || dbdesc->reserved2)
  695. {
  696. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  697. zlog_info ("Non-0 reserved field in %s's DbDesc, correct",
  698. on->name);
  699. dbdesc->reserved1 = 0;
  700. dbdesc->reserved2 = 0;
  701. }
  702. if (ntohl (oh->router_id) < ntohl (ospf6->router_id))
  703. ospf6_dbdesc_recv_master (oh, on);
  704. else if (ntohl (ospf6->router_id) < ntohl (oh->router_id))
  705. ospf6_dbdesc_recv_slave (oh, on);
  706. else
  707. {
  708. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  709. zlog_info ("Can't decide which is master, ignore");
  710. }
  711. }
  712. void
  713. ospf6_lsreq_recv (struct in6_addr *src, struct in6_addr *dst,
  714. struct ospf6_interface *oi, struct ospf6_header *oh)
  715. {
  716. struct ospf6_neighbor *on;
  717. char *p;
  718. struct ospf6_lsreq_entry *e;
  719. void *scope = NULL;
  720. struct ospf6_lsdb *lsdb = NULL;
  721. struct ospf6_lsa *lsa;
  722. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  723. return;
  724. on = ospf6_neighbor_lookup (oh->router_id, oi);
  725. if (on == NULL)
  726. {
  727. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  728. zlog_info ("Neighbor not found, ignore");
  729. return;
  730. }
  731. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  732. {
  733. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  734. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  735. return;
  736. }
  737. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  738. on->state != OSPF6_NEIGHBOR_LOADING &&
  739. on->state != OSPF6_NEIGHBOR_FULL)
  740. {
  741. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  742. zlog_info ("Neighbor state less than Exchange, ignore");
  743. return;
  744. }
  745. /* Process each request */
  746. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  747. p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh);
  748. p += sizeof (struct ospf6_lsreq_entry))
  749. {
  750. e = (struct ospf6_lsreq_entry *) p;
  751. scope = ospf6_get_lsa_scope (e->type, on);
  752. lsdb = ospf6_get_scoped_lsdb (e->type, scope);
  753. /* Find database copy */
  754. lsa = ospf6_lsdb_lookup (e->type, e->id, e->adv_router, lsdb);
  755. if (lsa == NULL)
  756. {
  757. char id[16], adv_router[16];
  758. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  759. {
  760. inet_ntop (AF_INET, &e->id, id, sizeof (id));
  761. inet_ntop (AF_INET, &e->adv_router, adv_router,
  762. sizeof (adv_router));
  763. zlog_info ("Can't find requested [%s Id:%s Adv:%s]",
  764. OSPF6_LSTYPE_NAME (e->type), id, adv_router);
  765. }
  766. thread_add_event (master, bad_lsreq, on, 0);
  767. return;
  768. }
  769. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  770. zlog_info ("Add copy of %s to lsupdate_list of %s",
  771. lsa->name, on->name);
  772. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->lsupdate_list);
  773. }
  774. if (p != OSPF6_MESSAGE_END (oh))
  775. {
  776. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  777. zlog_info ("Trailing garbage ignored");
  778. }
  779. /* schedule send lsupdate */
  780. THREAD_OFF (on->thread_send_lsupdate);
  781. on->thread_send_lsupdate =
  782. thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
  783. }
  784. void
  785. ospf6_lsupdate_recv (struct in6_addr *src, struct in6_addr *dst,
  786. struct ospf6_interface *oi, struct ospf6_header *oh)
  787. {
  788. struct ospf6_neighbor *on;
  789. struct ospf6_lsupdate *lsupdate;
  790. unsigned long num;
  791. char *p;
  792. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  793. return;
  794. on = ospf6_neighbor_lookup (oh->router_id, oi);
  795. if (on == NULL)
  796. {
  797. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  798. zlog_info ("Neighbor not found, ignore");
  799. return;
  800. }
  801. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  802. {
  803. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  804. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  805. return;
  806. }
  807. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  808. on->state != OSPF6_NEIGHBOR_LOADING &&
  809. on->state != OSPF6_NEIGHBOR_FULL)
  810. {
  811. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  812. zlog_info ("Neighbor state less than Exchange, ignore");
  813. return;
  814. }
  815. lsupdate = (struct ospf6_lsupdate *)
  816. ((caddr_t) oh + sizeof (struct ospf6_header));
  817. num = ntohl (lsupdate->lsa_number);
  818. /* Process LSAs */
  819. for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  820. p < OSPF6_MESSAGE_END (oh) &&
  821. p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh);
  822. p += OSPF6_LSA_SIZE (p))
  823. {
  824. if (num == 0)
  825. break;
  826. if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header))
  827. {
  828. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  829. zlog_info ("Malformed LSA length, quit processing");
  830. break;
  831. }
  832. ospf6_receive_lsa ((struct ospf6_lsa_header *) p, on);
  833. num--;
  834. }
  835. if (num != 0)
  836. {
  837. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  838. zlog_info ("Malformed LSA number or LSA length");
  839. }
  840. if (p != OSPF6_MESSAGE_END (oh))
  841. {
  842. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  843. zlog_info ("Trailing garbage ignored");
  844. }
  845. /* RFC2328 Section 10.9: When the neighbor responds to these requests
  846. with the proper Link State Update packet(s), the Link state request
  847. list is truncated and a new Link State Request packet is sent. */
  848. /* send new Link State Request packet if this LS Update packet
  849. can be recognized as a response to our previous LS Request */
  850. if (! IN6_IS_ADDR_MULTICAST (dst) &&
  851. (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
  852. on->state == OSPF6_NEIGHBOR_LOADING))
  853. {
  854. THREAD_OFF (on->thread_send_lsreq);
  855. on->thread_send_lsreq =
  856. thread_add_event (master, ospf6_lsreq_send, on, 0);
  857. }
  858. }
  859. void
  860. ospf6_lsack_recv (struct in6_addr *src, struct in6_addr *dst,
  861. struct ospf6_interface *oi, struct ospf6_header *oh)
  862. {
  863. struct ospf6_neighbor *on;
  864. char *p;
  865. struct ospf6_lsa *his, *mine;
  866. struct ospf6_lsdb *lsdb = NULL;
  867. assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK);
  868. if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
  869. return;
  870. on = ospf6_neighbor_lookup (oh->router_id, oi);
  871. if (on == NULL)
  872. {
  873. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  874. zlog_info ("Neighbor not found, ignore");
  875. return;
  876. }
  877. if (memcmp (src, &on->linklocal_addr, sizeof (struct in6_addr)))
  878. {
  879. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  880. zlog_info ("Seems to be from Secondary I/F of the neighbor, ignore");
  881. return;
  882. }
  883. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  884. on->state != OSPF6_NEIGHBOR_LOADING &&
  885. on->state != OSPF6_NEIGHBOR_FULL)
  886. {
  887. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  888. zlog_info ("Neighbor state less than Exchange, ignore");
  889. return;
  890. }
  891. for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
  892. p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
  893. p += sizeof (struct ospf6_lsa_header))
  894. {
  895. his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
  896. his->scope = ospf6_get_lsa_scope (his->header->type, on);
  897. lsdb = ospf6_get_scoped_lsdb (his->header->type, his->scope);
  898. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV) ||
  899. IS_OSPF6_DEBUG_LSA (SEND))
  900. zlog_info ("%s acknowledged by %s", his->name, on->name);
  901. /* Find database copy */
  902. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  903. his->header->adv_router, lsdb);
  904. if (mine == NULL)
  905. {
  906. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  907. zlog_info ("No database copy");
  908. ospf6_lsa_delete (his);
  909. continue;
  910. }
  911. /* Check if the LSA is on his retrans-list */
  912. mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
  913. his->header->adv_router, on->retrans_list);
  914. if (mine == NULL)
  915. {
  916. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  917. zlog_info ("Not on %s's retrans-list", on->name);
  918. ospf6_lsa_delete (his);
  919. continue;
  920. }
  921. if (ospf6_lsa_compare (his, mine) != 0)
  922. {
  923. /* Log this questionable acknowledgement,
  924. and examine the next one. */
  925. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  926. zlog_info ("Questionable acknowledgement");
  927. ospf6_lsa_delete (his);
  928. continue;
  929. }
  930. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV) ||
  931. IS_OSPF6_DEBUG_LSA (SEND))
  932. zlog_info ("Acknowledged, remove from %s's retrans-list",
  933. on->name);
  934. if (OSPF6_LSA_IS_MAXAGE (mine))
  935. ospf6_maxage_remove (on->ospf6_if->area->ospf6);
  936. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  937. zlog_info ("remove %s from retrans_list of %s",
  938. mine->name, on->name);
  939. ospf6_decrement_onretrans (mine);
  940. ospf6_lsdb_remove (mine, on->retrans_list);
  941. ospf6_lsa_delete (his);
  942. }
  943. if (p != OSPF6_MESSAGE_END (oh))
  944. {
  945. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  946. zlog_info ("Trailing garbage ignored");
  947. }
  948. }
  949. char *recvbuf = NULL;
  950. char *sendbuf = NULL;
  951. int iobuflen = 0;
  952. int
  953. ospf6_iobuf_size (int size)
  954. {
  955. char *recvnew, *sendnew;
  956. if (size <= iobuflen)
  957. return iobuflen;
  958. recvnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
  959. sendnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
  960. if (recvnew == NULL || sendnew == NULL)
  961. {
  962. zlog_info ("Could not allocate I/O buffer of size %d.", size);
  963. return iobuflen;
  964. }
  965. if (recvbuf)
  966. XFREE (MTYPE_OSPF6_MESSAGE, recvbuf);
  967. if (sendbuf)
  968. XFREE (MTYPE_OSPF6_MESSAGE, sendbuf);
  969. recvbuf = recvnew;
  970. sendbuf = sendnew;
  971. iobuflen = size;
  972. return iobuflen;
  973. }
  974. int
  975. ospf6_receive (struct thread *thread)
  976. {
  977. int sockfd, len;
  978. char srcname[64], dstname[64];
  979. struct in6_addr src, dst;
  980. unsigned int ifindex;
  981. struct iovec iovector[2];
  982. struct ospf6_interface *oi;
  983. struct ospf6_header *oh;
  984. /* add next read thread */
  985. sockfd = THREAD_FD (thread);
  986. thread_add_read (master, ospf6_receive, NULL, sockfd);
  987. /* initialize */
  988. memset (recvbuf, 0, iobuflen);
  989. iovector[0].iov_base = recvbuf;
  990. iovector[0].iov_len = iobuflen;
  991. iovector[1].iov_base = NULL;
  992. iovector[1].iov_len = 0;
  993. /* receive message */
  994. len = ospf6_recvmsg (&src, &dst, &ifindex, iovector);
  995. if (len > iobuflen)
  996. {
  997. zlog_err ("Excess message read");
  998. return 0;
  999. }
  1000. else if (len < sizeof (struct ospf6_header))
  1001. {
  1002. zlog_err ("Deficient message read");
  1003. return 0;
  1004. }
  1005. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  1006. if (oi == NULL || oi->area == NULL)
  1007. {
  1008. zlog_info ("Message received on disabled interface");
  1009. return 0;
  1010. }
  1011. oh = (struct ospf6_header *) recvbuf;
  1012. /* Log */
  1013. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  1014. {
  1015. inet_ntop (AF_INET6, &src, srcname, sizeof (srcname));
  1016. inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname));
  1017. zlog_info ("%s received on %s",
  1018. OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
  1019. zlog_info (" src: %s", srcname);
  1020. zlog_info (" dst: %s", dstname);
  1021. if (len != ntohs (oh->length))
  1022. zlog_info ("Message length does not match actually received: %d", len);
  1023. switch (oh->type)
  1024. {
  1025. case OSPF6_MESSAGE_TYPE_HELLO:
  1026. ospf6_hello_print (oh);
  1027. break;
  1028. case OSPF6_MESSAGE_TYPE_DBDESC:
  1029. ospf6_dbdesc_print (oh);
  1030. break;
  1031. case OSPF6_MESSAGE_TYPE_LSREQ:
  1032. ospf6_lsreq_print (oh);
  1033. break;
  1034. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1035. ospf6_lsupdate_print (oh);
  1036. break;
  1037. case OSPF6_MESSAGE_TYPE_LSACK:
  1038. ospf6_lsack_print (oh);
  1039. break;
  1040. default:
  1041. zlog_info ("Unknown message");
  1042. break;
  1043. }
  1044. }
  1045. if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
  1046. {
  1047. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
  1048. zlog_info ("Ignore message on passive interface %s",
  1049. oi->interface->name);
  1050. return 0;
  1051. }
  1052. switch (oh->type)
  1053. {
  1054. case OSPF6_MESSAGE_TYPE_HELLO:
  1055. ospf6_hello_recv (&src, &dst, oi, oh);
  1056. break;
  1057. case OSPF6_MESSAGE_TYPE_DBDESC:
  1058. ospf6_dbdesc_recv (&src, &dst, oi, oh);
  1059. break;
  1060. case OSPF6_MESSAGE_TYPE_LSREQ:
  1061. ospf6_lsreq_recv (&src, &dst, oi, oh);
  1062. break;
  1063. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1064. ospf6_lsupdate_recv (&src, &dst, oi, oh);
  1065. break;
  1066. case OSPF6_MESSAGE_TYPE_LSACK:
  1067. ospf6_lsack_recv (&src, &dst, oi, oh);
  1068. break;
  1069. default:
  1070. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1071. zlog_info ("Unknown message");
  1072. break;
  1073. }
  1074. return 0;
  1075. }
  1076. void
  1077. ospf6_send (struct in6_addr *src, struct in6_addr *dst,
  1078. struct ospf6_interface *oi, struct ospf6_header *oh)
  1079. {
  1080. int len;
  1081. char srcname[64], dstname[64];
  1082. struct iovec iovector[2];
  1083. /* initialize */
  1084. iovector[0].iov_base = (caddr_t) oh;
  1085. iovector[0].iov_len = ntohs (oh->length);
  1086. iovector[1].iov_base = NULL;
  1087. iovector[1].iov_len = 0;
  1088. /* fill OSPF header */
  1089. oh->version = OSPFV3_VERSION;
  1090. /* message type must be set before */
  1091. /* message length must be set before */
  1092. oh->router_id = oi->area->ospf6->router_id;
  1093. oh->area_id = oi->area->area_id;
  1094. /* checksum is calculated by kernel */
  1095. oh->instance_id = oi->instance_id;
  1096. oh->reserved = 0;
  1097. /* Log */
  1098. if (IS_OSPF6_DEBUG_MESSAGE (oh->type, SEND))
  1099. {
  1100. inet_ntop (AF_INET6, dst, dstname, sizeof (dstname));
  1101. if (src)
  1102. inet_ntop (AF_INET6, src, srcname, sizeof (srcname));
  1103. else
  1104. memset (srcname, 0, sizeof (srcname));
  1105. zlog_info ("%s send on %s",
  1106. OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
  1107. zlog_info (" src: %s", srcname);
  1108. zlog_info (" dst: %s", dstname);
  1109. switch (oh->type)
  1110. {
  1111. case OSPF6_MESSAGE_TYPE_HELLO:
  1112. ospf6_hello_print (oh);
  1113. break;
  1114. case OSPF6_MESSAGE_TYPE_DBDESC:
  1115. ospf6_dbdesc_print (oh);
  1116. break;
  1117. case OSPF6_MESSAGE_TYPE_LSREQ:
  1118. ospf6_lsreq_print (oh);
  1119. break;
  1120. case OSPF6_MESSAGE_TYPE_LSUPDATE:
  1121. ospf6_lsupdate_print (oh);
  1122. break;
  1123. case OSPF6_MESSAGE_TYPE_LSACK:
  1124. ospf6_lsack_print (oh);
  1125. break;
  1126. default:
  1127. zlog_info ("Unknown message");
  1128. assert (0);
  1129. break;
  1130. }
  1131. }
  1132. /* send message */
  1133. len = ospf6_sendmsg (src, dst, &oi->interface->ifindex, iovector);
  1134. if (len != ntohs (oh->length))
  1135. zlog_err ("Could not send entire message");
  1136. }
  1137. int
  1138. ospf6_hello_send (struct thread *thread)
  1139. {
  1140. struct ospf6_interface *oi;
  1141. struct ospf6_header *oh;
  1142. struct ospf6_hello *hello;
  1143. char *p;
  1144. listnode node;
  1145. struct ospf6_neighbor *on;
  1146. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1147. oi->thread_send_hello = (struct thread *) NULL;
  1148. if (oi->state <= OSPF6_INTERFACE_DOWN)
  1149. {
  1150. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
  1151. zlog_info ("Unable to send Hello on down interface %s",
  1152. oi->interface->name);
  1153. return 0;
  1154. }
  1155. /* set next thread */
  1156. oi->thread_send_hello = thread_add_timer (master, ospf6_hello_send,
  1157. oi, oi->hello_interval);
  1158. memset (sendbuf, 0, iobuflen);
  1159. oh = (struct ospf6_header *) sendbuf;
  1160. hello = (struct ospf6_hello *)((caddr_t) oh + sizeof (struct ospf6_header));
  1161. hello->interface_id = htonl (oi->interface->ifindex);
  1162. hello->priority = oi->priority;
  1163. hello->options[0] = oi->area->options[0];
  1164. hello->options[1] = oi->area->options[1];
  1165. hello->options[2] = oi->area->options[2];
  1166. hello->hello_interval = htons (oi->hello_interval);
  1167. hello->dead_interval = htons (oi->dead_interval);
  1168. hello->drouter = oi->drouter;
  1169. hello->bdrouter = oi->bdrouter;
  1170. p = (char *)((caddr_t) hello + sizeof (struct ospf6_hello));
  1171. for (node = listhead (oi->neighbor_list); node; nextnode (node))
  1172. {
  1173. on = (struct ospf6_neighbor *) getdata (node);
  1174. if (on->state < OSPF6_NEIGHBOR_INIT)
  1175. continue;
  1176. if (p - sendbuf + sizeof (u_int32_t) > oi->ifmtu)
  1177. {
  1178. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
  1179. zlog_info ("sending Hello message: exceeds I/F MTU");
  1180. break;
  1181. }
  1182. memcpy (p, &on->router_id, sizeof (u_int32_t));
  1183. p += sizeof (u_int32_t);
  1184. }
  1185. oh->type = OSPF6_MESSAGE_TYPE_HELLO;
  1186. oh->length = htons (p - sendbuf);
  1187. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1188. return 0;
  1189. }
  1190. int
  1191. ospf6_dbdesc_send (struct thread *thread)
  1192. {
  1193. struct ospf6_neighbor *on;
  1194. struct ospf6_header *oh;
  1195. struct ospf6_dbdesc *dbdesc;
  1196. char *p;
  1197. struct ospf6_lsa *lsa;
  1198. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1199. on->thread_send_dbdesc = (struct thread *) NULL;
  1200. if (on->state < OSPF6_NEIGHBOR_EXSTART)
  1201. {
  1202. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_DBDESC, SEND))
  1203. zlog_info ("Quit to send DbDesc to neighbor %s state %s",
  1204. on->name, ospf6_neighbor_state_str[on->state]);
  1205. return 0;
  1206. }
  1207. /* set next thread if master */
  1208. if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
  1209. on->thread_send_dbdesc =
  1210. thread_add_timer (master, ospf6_dbdesc_send, on,
  1211. on->ospf6_if->rxmt_interval);
  1212. memset (sendbuf, 0, iobuflen);
  1213. oh = (struct ospf6_header *) sendbuf;
  1214. dbdesc = (struct ospf6_dbdesc *)((caddr_t) oh +
  1215. sizeof (struct ospf6_header));
  1216. /* if this is initial one, initialize sequence number for DbDesc */
  1217. if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
  1218. {
  1219. struct timeval tv;
  1220. if (gettimeofday (&tv, (struct timezone *) NULL) < 0)
  1221. tv.tv_sec = 1;
  1222. on->dbdesc_seqnum = tv.tv_sec;
  1223. }
  1224. dbdesc->options[0] = on->ospf6_if->area->options[0];
  1225. dbdesc->options[1] = on->ospf6_if->area->options[1];
  1226. dbdesc->options[2] = on->ospf6_if->area->options[2];
  1227. dbdesc->ifmtu = htons (on->ospf6_if->ifmtu);
  1228. dbdesc->bits = on->dbdesc_bits;
  1229. dbdesc->seqnum = htonl (on->dbdesc_seqnum);
  1230. /* if this is not initial one, set LSA headers in dbdesc */
  1231. p = (char *)((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
  1232. if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
  1233. {
  1234. for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
  1235. lsa = ospf6_lsdb_next (lsa))
  1236. {
  1237. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1238. /* MTU check */
  1239. if (p - sendbuf + sizeof (struct ospf6_lsa_header) >
  1240. on->ospf6_if->ifmtu)
  1241. {
  1242. ospf6_lsa_unlock (lsa);
  1243. break;
  1244. }
  1245. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1246. p += sizeof (struct ospf6_lsa_header);
  1247. }
  1248. }
  1249. oh->type = OSPF6_MESSAGE_TYPE_DBDESC;
  1250. oh->length = htons (p - sendbuf);
  1251. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1252. on->ospf6_if, oh);
  1253. return 0;
  1254. }
  1255. int
  1256. ospf6_dbdesc_send_newone (struct thread *thread)
  1257. {
  1258. struct ospf6_neighbor *on;
  1259. struct ospf6_lsa *lsa;
  1260. unsigned int size = 0;
  1261. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1262. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  1263. zlog_info ("Remove entire dbdesc_list of %s: sending newone", on->name);
  1264. ospf6_lsdb_remove_all (on->dbdesc_list);
  1265. /* move LSAs from summary_list to dbdesc_list (within neighbor structure)
  1266. so that ospf6_send_dbdesc () can send those LSAs */
  1267. size = sizeof (struct ospf6_lsa_header) + sizeof (struct ospf6_dbdesc);
  1268. for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
  1269. lsa = ospf6_lsdb_next (lsa))
  1270. {
  1271. if (size + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
  1272. {
  1273. ospf6_lsa_unlock (lsa);
  1274. break;
  1275. }
  1276. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  1277. zlog_info ("Move %s from summary_list to dbdesc_list of %s",
  1278. lsa->name, on->name);
  1279. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->dbdesc_list);
  1280. ospf6_lsdb_remove (lsa, on->summary_list);
  1281. size += sizeof (struct ospf6_lsa_header);
  1282. }
  1283. if (on->summary_list->count == 0)
  1284. UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
  1285. /* If slave, More bit check must be done here */
  1286. if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */
  1287. ! CHECK_FLAG (on->dbdesc_last.bits, OSPF6_DBDESC_MBIT) &&
  1288. ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
  1289. thread_add_event (master, exchange_done, on, 0);
  1290. thread_execute (master, ospf6_dbdesc_send, on, 0);
  1291. return 0;
  1292. }
  1293. int
  1294. ospf6_lsreq_send (struct thread *thread)
  1295. {
  1296. struct ospf6_neighbor *on;
  1297. struct ospf6_header *oh;
  1298. struct ospf6_lsreq_entry *e;
  1299. char *p;
  1300. struct ospf6_lsa *lsa;
  1301. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1302. on->thread_send_lsreq = (struct thread *) NULL;
  1303. /* LSReq will be sent only in ExStart or Loading */
  1304. if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
  1305. on->state != OSPF6_NEIGHBOR_LOADING)
  1306. {
  1307. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSREQ, SEND))
  1308. zlog_info ("Quit to send LSReq to neighbor %s state %s",
  1309. on->name, ospf6_neighbor_state_str[on->state]);
  1310. return 0;
  1311. }
  1312. /* schedule loading_done if request list is empty */
  1313. if (on->request_list->count == 0)
  1314. {
  1315. thread_add_event (master, loading_done, on, 0);
  1316. return 0;
  1317. }
  1318. /* set next thread */
  1319. on->thread_send_lsreq =
  1320. thread_add_timer (master, ospf6_lsreq_send, on,
  1321. on->ospf6_if->rxmt_interval);
  1322. memset (sendbuf, 0, iobuflen);
  1323. oh = (struct ospf6_header *) sendbuf;
  1324. /* set Request entries in lsreq */
  1325. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1326. for (lsa = ospf6_lsdb_head (on->request_list); lsa;
  1327. lsa = ospf6_lsdb_next (lsa))
  1328. {
  1329. /* MTU check */
  1330. if (p - sendbuf + sizeof (struct ospf6_lsreq_entry) > on->ospf6_if->ifmtu)
  1331. {
  1332. ospf6_lsa_unlock (lsa);
  1333. break;
  1334. }
  1335. e = (struct ospf6_lsreq_entry *) p;
  1336. e->type = lsa->header->type;
  1337. e->id = lsa->header->id;
  1338. e->adv_router = lsa->header->adv_router;
  1339. p += sizeof (struct ospf6_lsreq_entry);
  1340. }
  1341. oh->type = OSPF6_MESSAGE_TYPE_LSREQ;
  1342. oh->length = htons (p - sendbuf);
  1343. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1344. on->ospf6_if, oh);
  1345. return 0;
  1346. }
  1347. int
  1348. ospf6_lsupdate_send_neighbor (struct thread *thread)
  1349. {
  1350. struct ospf6_neighbor *on;
  1351. struct ospf6_header *oh;
  1352. struct ospf6_lsupdate *lsupdate;
  1353. char *p;
  1354. int num;
  1355. struct ospf6_lsa *lsa;
  1356. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1357. on->thread_send_lsupdate = (struct thread *) NULL;
  1358. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  1359. {
  1360. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1361. zlog_info ("Quit to send LSUpdate to neighbor %s state %s",
  1362. on->name, ospf6_neighbor_state_str[on->state]);
  1363. return 0;
  1364. }
  1365. /* if we have nothing to send, return */
  1366. if (on->lsupdate_list->count == 0 &&
  1367. on->retrans_list->count == 0)
  1368. return 0;
  1369. if (IS_OSPF6_DEBUG_LSA (SEND))
  1370. zlog_info ("LSA Send to %s", on->name);
  1371. memset (sendbuf, 0, iobuflen);
  1372. oh = (struct ospf6_header *) sendbuf;
  1373. lsupdate = (struct ospf6_lsupdate *)
  1374. ((caddr_t) oh + sizeof (struct ospf6_header));
  1375. p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  1376. num = 0;
  1377. /* lsupdate_list lists those LSA which doesn't need to be
  1378. retransmitted. remove those from the list */
  1379. for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
  1380. lsa = ospf6_lsdb_next (lsa))
  1381. {
  1382. /* MTU check */
  1383. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
  1384. {
  1385. ospf6_lsa_unlock (lsa);
  1386. break;
  1387. }
  1388. if (IS_OSPF6_DEBUG_LSA (SEND))
  1389. ospf6_lsa_header_print (lsa);
  1390. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1391. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1392. p += OSPF6_LSA_SIZE (lsa->header);
  1393. num++;
  1394. assert (lsa->lock == 2);
  1395. ospf6_lsdb_remove (lsa, on->lsupdate_list);
  1396. }
  1397. for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
  1398. lsa = ospf6_lsdb_next (lsa))
  1399. {
  1400. /* MTU check */
  1401. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
  1402. {
  1403. ospf6_lsa_unlock (lsa);
  1404. break;
  1405. }
  1406. if (IS_OSPF6_DEBUG_LSA (SEND))
  1407. ospf6_lsa_header_print (lsa);
  1408. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1409. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1410. p += OSPF6_LSA_SIZE (lsa->header);
  1411. num++;
  1412. }
  1413. lsupdate->lsa_number = htonl (num);
  1414. oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1415. oh->length = htons (p - sendbuf);
  1416. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1417. on->ospf6_if, oh);
  1418. if (on->lsupdate_list->count != 0 ||
  1419. on->retrans_list->count != 0)
  1420. {
  1421. if (on->lsupdate_list->count != 0)
  1422. on->thread_send_lsupdate =
  1423. thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
  1424. else
  1425. on->thread_send_lsupdate =
  1426. thread_add_timer (master, ospf6_lsupdate_send_neighbor, on,
  1427. on->ospf6_if->rxmt_interval);
  1428. }
  1429. return 0;
  1430. }
  1431. int
  1432. ospf6_lsupdate_send_interface (struct thread *thread)
  1433. {
  1434. struct ospf6_interface *oi;
  1435. struct ospf6_header *oh;
  1436. struct ospf6_lsupdate *lsupdate;
  1437. char *p;
  1438. int num;
  1439. struct ospf6_lsa *lsa;
  1440. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1441. oi->thread_send_lsupdate = (struct thread *) NULL;
  1442. if (oi->state <= OSPF6_INTERFACE_WAITING)
  1443. {
  1444. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
  1445. zlog_info ("Quit to send LSUpdate to interface %s state %s",
  1446. oi->interface->name, ospf6_interface_state_str[oi->state]);
  1447. return 0;
  1448. }
  1449. /* if we have nothing to send, return */
  1450. if (oi->lsupdate_list->count == 0)
  1451. return 0;
  1452. if (IS_OSPF6_DEBUG_LSA (SEND))
  1453. zlog_info ("LSA Send to %s", oi->interface->name);
  1454. memset (sendbuf, 0, iobuflen);
  1455. oh = (struct ospf6_header *) sendbuf;
  1456. lsupdate = (struct ospf6_lsupdate *)((caddr_t) oh +
  1457. sizeof (struct ospf6_header));
  1458. p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
  1459. num = 0;
  1460. for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
  1461. lsa = ospf6_lsdb_next (lsa))
  1462. {
  1463. /* MTU check */
  1464. if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > oi->ifmtu)
  1465. {
  1466. ospf6_lsa_unlock (lsa);
  1467. break;
  1468. }
  1469. if (IS_OSPF6_DEBUG_LSA (SEND))
  1470. ospf6_lsa_header_print (lsa);
  1471. ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
  1472. memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
  1473. p += OSPF6_LSA_SIZE (lsa->header);
  1474. num++;
  1475. assert (lsa->lock == 2);
  1476. ospf6_lsdb_remove (lsa, oi->lsupdate_list);
  1477. }
  1478. lsupdate->lsa_number = htonl (num);
  1479. oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1480. oh->length = htons (p - sendbuf);
  1481. if (oi->state == OSPF6_INTERFACE_DR ||
  1482. oi->state == OSPF6_INTERFACE_BDR)
  1483. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1484. else
  1485. ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
  1486. if (oi->lsupdate_list->count > 0)
  1487. {
  1488. oi->thread_send_lsupdate =
  1489. thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0);
  1490. }
  1491. return 0;
  1492. }
  1493. int
  1494. ospf6_lsack_send_neighbor (struct thread *thread)
  1495. {
  1496. struct ospf6_neighbor *on;
  1497. struct ospf6_header *oh;
  1498. char *p;
  1499. struct ospf6_lsa *lsa;
  1500. on = (struct ospf6_neighbor *) THREAD_ARG (thread);
  1501. on->thread_send_lsack = (struct thread *) NULL;
  1502. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  1503. {
  1504. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
  1505. zlog_info ("Quit to send LSAck to neighbor %s state %s",
  1506. on->name, ospf6_neighbor_state_str[on->state]);
  1507. return 0;
  1508. }
  1509. /* if we have nothing to send, return */
  1510. if (on->lsack_list->count == 0)
  1511. return 0;
  1512. memset (sendbuf, 0, iobuflen);
  1513. oh = (struct ospf6_header *) sendbuf;
  1514. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1515. for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
  1516. lsa = ospf6_lsdb_next (lsa))
  1517. {
  1518. /* MTU check */
  1519. if (p - sendbuf + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
  1520. {
  1521. /* if we run out of packet size/space here,
  1522. better to try again soon. */
  1523. THREAD_OFF (on->thread_send_lsack);
  1524. on->thread_send_lsack =
  1525. thread_add_event (master, ospf6_lsack_send_neighbor, on, 0);
  1526. ospf6_lsa_unlock (lsa);
  1527. break;
  1528. }
  1529. ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
  1530. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1531. p += sizeof (struct ospf6_lsa_header);
  1532. assert (lsa->lock == 2);
  1533. ospf6_lsdb_remove (lsa, on->lsack_list);
  1534. }
  1535. oh->type = OSPF6_MESSAGE_TYPE_LSACK;
  1536. oh->length = htons (p - sendbuf);
  1537. ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
  1538. on->ospf6_if, oh);
  1539. return 0;
  1540. }
  1541. int
  1542. ospf6_lsack_send_interface (struct thread *thread)
  1543. {
  1544. struct ospf6_interface *oi;
  1545. struct ospf6_header *oh;
  1546. char *p;
  1547. struct ospf6_lsa *lsa;
  1548. oi = (struct ospf6_interface *) THREAD_ARG (thread);
  1549. oi->thread_send_lsack = (struct thread *) NULL;
  1550. if (oi->state <= OSPF6_INTERFACE_WAITING)
  1551. {
  1552. if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
  1553. zlog_info ("Quit to send LSAck to interface %s state %s",
  1554. oi->interface->name, ospf6_interface_state_str[oi->state]);
  1555. return 0;
  1556. }
  1557. /* if we have nothing to send, return */
  1558. if (oi->lsack_list->count == 0)
  1559. return 0;
  1560. memset (sendbuf, 0, iobuflen);
  1561. oh = (struct ospf6_header *) sendbuf;
  1562. p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
  1563. for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
  1564. lsa = ospf6_lsdb_next (lsa))
  1565. {
  1566. /* MTU check */
  1567. if (p - sendbuf + sizeof (struct ospf6_lsa_header) > oi->ifmtu)
  1568. {
  1569. /* if we run out of packet size/space here,
  1570. better to try again soon. */
  1571. THREAD_OFF (oi->thread_send_lsack);
  1572. oi->thread_send_lsack =
  1573. thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
  1574. ospf6_lsa_unlock (lsa);
  1575. break;
  1576. }
  1577. ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
  1578. memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
  1579. p += sizeof (struct ospf6_lsa_header);
  1580. assert (lsa->lock == 2);
  1581. ospf6_lsdb_remove (lsa, oi->lsack_list);
  1582. }
  1583. oh->type = OSPF6_MESSAGE_TYPE_LSACK;
  1584. oh->length = htons (p - sendbuf);
  1585. if (oi->state == OSPF6_INTERFACE_DR ||
  1586. oi->state == OSPF6_INTERFACE_BDR)
  1587. ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
  1588. else
  1589. ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
  1590. if (oi->thread_send_lsack == NULL && oi->lsack_list->count > 0)
  1591. {
  1592. oi->thread_send_lsack =
  1593. thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
  1594. }
  1595. return 0;
  1596. }
  1597. /* Commands */
  1598. DEFUN (debug_ospf6_message,
  1599. debug_ospf6_message_cmd,
  1600. "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
  1601. DEBUG_STR
  1602. OSPF6_STR
  1603. "Debug OSPFv3 message\n"
  1604. "Debug Unknown message\n"
  1605. "Debug Hello message\n"
  1606. "Debug Database Description message\n"
  1607. "Debug Link State Request message\n"
  1608. "Debug Link State Update message\n"
  1609. "Debug Link State Acknowledgement message\n"
  1610. "Debug All message\n"
  1611. )
  1612. {
  1613. unsigned char level = 0;
  1614. int type = 0;
  1615. int i;
  1616. assert (argc > 0);
  1617. /* check type */
  1618. if (! strncmp (argv[0], "u", 1))
  1619. type = OSPF6_MESSAGE_TYPE_UNKNOWN;
  1620. else if (! strncmp (argv[0], "h", 1))
  1621. type = OSPF6_MESSAGE_TYPE_HELLO;
  1622. else if (! strncmp (argv[0], "d", 1))
  1623. type = OSPF6_MESSAGE_TYPE_DBDESC;
  1624. else if (! strncmp (argv[0], "lsr", 3))
  1625. type = OSPF6_MESSAGE_TYPE_LSREQ;
  1626. else if (! strncmp (argv[0], "lsu", 3))
  1627. type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1628. else if (! strncmp (argv[0], "lsa", 3))
  1629. type = OSPF6_MESSAGE_TYPE_LSACK;
  1630. else if (! strncmp (argv[0], "a", 1))
  1631. type = OSPF6_MESSAGE_TYPE_ALL;
  1632. if (argc == 1)
  1633. level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
  1634. else if (! strncmp (argv[1], "s", 1))
  1635. level = OSPF6_DEBUG_MESSAGE_SEND;
  1636. else if (! strncmp (argv[1], "r", 1))
  1637. level = OSPF6_DEBUG_MESSAGE_RECV;
  1638. if (type == OSPF6_MESSAGE_TYPE_ALL)
  1639. {
  1640. for (i = 0; i < 6; i++)
  1641. OSPF6_DEBUG_MESSAGE_ON (i, level);
  1642. }
  1643. else
  1644. OSPF6_DEBUG_MESSAGE_ON (type, level);
  1645. return CMD_SUCCESS;
  1646. }
  1647. ALIAS (debug_ospf6_message,
  1648. debug_ospf6_message_sendrecv_cmd,
  1649. "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
  1650. DEBUG_STR
  1651. OSPF6_STR
  1652. "Debug OSPFv3 message\n"
  1653. "Debug Unknown message\n"
  1654. "Debug Hello message\n"
  1655. "Debug Database Description message\n"
  1656. "Debug Link State Request message\n"
  1657. "Debug Link State Update message\n"
  1658. "Debug Link State Acknowledgement message\n"
  1659. "Debug All message\n"
  1660. "Debug only sending message\n"
  1661. "Debug only receiving message\n"
  1662. );
  1663. DEFUN (no_debug_ospf6_message,
  1664. no_debug_ospf6_message_cmd,
  1665. "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
  1666. NO_STR
  1667. DEBUG_STR
  1668. OSPF6_STR
  1669. "Debug OSPFv3 message\n"
  1670. "Debug Unknown message\n"
  1671. "Debug Hello message\n"
  1672. "Debug Database Description message\n"
  1673. "Debug Link State Request message\n"
  1674. "Debug Link State Update message\n"
  1675. "Debug Link State Acknowledgement message\n"
  1676. "Debug All message\n"
  1677. )
  1678. {
  1679. unsigned char level = 0;
  1680. int type = 0;
  1681. int i;
  1682. assert (argc > 0);
  1683. /* check type */
  1684. if (! strncmp (argv[0], "u", 1))
  1685. type = OSPF6_MESSAGE_TYPE_UNKNOWN;
  1686. else if (! strncmp (argv[0], "h", 1))
  1687. type = OSPF6_MESSAGE_TYPE_HELLO;
  1688. else if (! strncmp (argv[0], "d", 1))
  1689. type = OSPF6_MESSAGE_TYPE_DBDESC;
  1690. else if (! strncmp (argv[0], "lsr", 3))
  1691. type = OSPF6_MESSAGE_TYPE_LSREQ;
  1692. else if (! strncmp (argv[0], "lsu", 3))
  1693. type = OSPF6_MESSAGE_TYPE_LSUPDATE;
  1694. else if (! strncmp (argv[0], "lsa", 3))
  1695. type = OSPF6_MESSAGE_TYPE_LSACK;
  1696. else if (! strncmp (argv[0], "a", 1))
  1697. type = OSPF6_MESSAGE_TYPE_ALL;
  1698. if (argc == 1)
  1699. level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
  1700. else if (! strncmp (argv[1], "s", 1))
  1701. level = OSPF6_DEBUG_MESSAGE_SEND;
  1702. else if (! strncmp (argv[1], "r", 1))
  1703. level = OSPF6_DEBUG_MESSAGE_RECV;
  1704. if (type == OSPF6_MESSAGE_TYPE_ALL)
  1705. {
  1706. for (i = 0; i < 6; i++)
  1707. OSPF6_DEBUG_MESSAGE_OFF (i, level);
  1708. }
  1709. else
  1710. OSPF6_DEBUG_MESSAGE_OFF (type, level);
  1711. return CMD_SUCCESS;
  1712. }
  1713. ALIAS (no_debug_ospf6_message,
  1714. no_debug_ospf6_message_sendrecv_cmd,
  1715. "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
  1716. NO_STR
  1717. DEBUG_STR
  1718. OSPF6_STR
  1719. "Debug OSPFv3 message\n"
  1720. "Debug Unknown message\n"
  1721. "Debug Hello message\n"
  1722. "Debug Database Description message\n"
  1723. "Debug Link State Request message\n"
  1724. "Debug Link State Update message\n"
  1725. "Debug Link State Acknowledgement message\n"
  1726. "Debug All message\n"
  1727. "Debug only sending message\n"
  1728. "Debug only receiving message\n"
  1729. );
  1730. int
  1731. config_write_ospf6_debug_message (struct vty *vty)
  1732. {
  1733. char *type_str[] = {"unknown", "hello", "dbdesc",
  1734. "lsreq", "lsupdate", "lsack"};
  1735. unsigned char s = 0, r = 0;
  1736. int i;
  1737. for (i = 0; i < 6; i++)
  1738. {
  1739. if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
  1740. s |= 1 << i;
  1741. if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1742. r |= 1 << i;
  1743. }
  1744. if (s == 0x3f && r == 0x3f)
  1745. {
  1746. vty_out (vty, "debug ospf6 message all%s", VTY_NEWLINE);
  1747. return 0;
  1748. }
  1749. if (s == 0x3f && r == 0)
  1750. {
  1751. vty_out (vty, "debug ospf6 message all send%s", VTY_NEWLINE);
  1752. return 0;
  1753. }
  1754. else if (s == 0 && r == 0x3f)
  1755. {
  1756. vty_out (vty, "debug ospf6 message all recv%s", VTY_NEWLINE);
  1757. return 0;
  1758. }
  1759. /* Unknown message is logged by default */
  1760. if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND) &&
  1761. ! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1762. vty_out (vty, "no debug ospf6 message unknown%s", VTY_NEWLINE);
  1763. else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND))
  1764. vty_out (vty, "no debug ospf6 message unknown send%s", VTY_NEWLINE);
  1765. else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
  1766. vty_out (vty, "no debug ospf6 message unknown recv%s", VTY_NEWLINE);
  1767. for (i = 1; i < 6; i++)
  1768. {
  1769. if (IS_OSPF6_DEBUG_MESSAGE (i, SEND) &&
  1770. IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1771. vty_out (vty, "debug ospf6 message %s%s", type_str[i], VTY_NEWLINE);
  1772. else if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
  1773. vty_out (vty, "debug ospf6 message %s send%s", type_str[i],
  1774. VTY_NEWLINE);
  1775. else if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
  1776. vty_out (vty, "debug ospf6 message %s recv%s", type_str[i],
  1777. VTY_NEWLINE);
  1778. }
  1779. return 0;
  1780. }
  1781. void
  1782. install_element_ospf6_debug_message ()
  1783. {
  1784. install_element (ENABLE_NODE, &debug_ospf6_message_cmd);
  1785. install_element (ENABLE_NODE, &no_debug_ospf6_message_cmd);
  1786. install_element (ENABLE_NODE, &debug_ospf6_message_sendrecv_cmd);
  1787. install_element (ENABLE_NODE, &no_debug_ospf6_message_sendrecv_cmd);
  1788. install_element (CONFIG_NODE, &debug_ospf6_message_cmd);
  1789. install_element (CONFIG_NODE, &no_debug_ospf6_message_cmd);
  1790. install_element (CONFIG_NODE, &debug_ospf6_message_sendrecv_cmd);
  1791. install_element (CONFIG_NODE, &no_debug_ospf6_message_sendrecv_cmd);
  1792. }