ospf6_message.c 61 KB

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