print-icmp6.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  1. /*
  2. * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. */
  21. /* \summary: IPv6 Internet Control Message Protocol (ICMPv6) printer */
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25. #include <netdissect-stdinc.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include "netdissect.h"
  29. #include "addrtoname.h"
  30. #include "addrtostr.h"
  31. #include "extract.h"
  32. #include "ip6.h"
  33. #include "ipproto.h"
  34. #include "udp.h"
  35. #include "ah.h"
  36. /* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */
  37. /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */
  38. /*
  39. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  40. * All rights reserved.
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted provided that the following conditions
  44. * are met:
  45. * 1. Redistributions of source code must retain the above copyright
  46. * notice, this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright
  48. * notice, this list of conditions and the following disclaimer in the
  49. * documentation and/or other materials provided with the distribution.
  50. * 3. Neither the name of the project nor the names of its contributors
  51. * may be used to endorse or promote products derived from this software
  52. * without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  55. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  56. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  57. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  58. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  59. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  60. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  61. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  64. * SUCH DAMAGE.
  65. */
  66. struct icmp6_hdr {
  67. uint8_t icmp6_type; /* type field */
  68. uint8_t icmp6_code; /* code field */
  69. uint16_t icmp6_cksum; /* checksum field */
  70. union {
  71. uint32_t icmp6_un_data32[1]; /* type-specific field */
  72. uint16_t icmp6_un_data16[2]; /* type-specific field */
  73. uint8_t icmp6_un_data8[4]; /* type-specific field */
  74. } icmp6_dataun;
  75. };
  76. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  77. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  78. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  79. #define icmp6_pptr icmp6_data32[0] /* parameter prob */
  80. #define icmp6_mtu icmp6_data32[0] /* packet too big */
  81. #define icmp6_id icmp6_data16[0] /* echo request/reply */
  82. #define icmp6_seq icmp6_data16[1] /* echo request/reply */
  83. #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
  84. #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
  85. #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
  86. #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
  87. #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
  88. #define ICMP6_ECHO_REQUEST 128 /* echo service */
  89. #define ICMP6_ECHO_REPLY 129 /* echo reply */
  90. #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
  91. #define MLD6_LISTENER_QUERY 130 /* multicast listener query */
  92. #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
  93. #define MLD6_LISTENER_REPORT 131 /* multicast listener report */
  94. #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
  95. #define MLD6_LISTENER_DONE 132 /* multicast listener done */
  96. #define ND_ROUTER_SOLICIT 133 /* router solicitation */
  97. #define ND_ROUTER_ADVERT 134 /* router advertisement */
  98. #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
  99. #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
  100. #define ND_REDIRECT 137 /* redirect */
  101. #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
  102. #define ICMP6_WRUREQUEST 139 /* who are you request */
  103. #define ICMP6_WRUREPLY 140 /* who are you reply */
  104. #define ICMP6_FQDN_QUERY 139 /* FQDN query */
  105. #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
  106. #define ICMP6_NI_QUERY 139 /* node information request */
  107. #define ICMP6_NI_REPLY 140 /* node information reply */
  108. #define IND_SOLICIT 141 /* inverse neighbor solicitation */
  109. #define IND_ADVERT 142 /* inverse neighbor advertisement */
  110. #define ICMP6_V2_MEMBERSHIP_REPORT 143 /* v2 membership report */
  111. #define MLDV2_LISTENER_REPORT 143 /* v2 multicast listener report */
  112. #define ICMP6_HADISCOV_REQUEST 144
  113. #define ICMP6_HADISCOV_REPLY 145
  114. #define ICMP6_MOBILEPREFIX_SOLICIT 146
  115. #define ICMP6_MOBILEPREFIX_ADVERT 147
  116. #define MLD6_MTRACE_RESP 200 /* mtrace response(to sender) */
  117. #define MLD6_MTRACE 201 /* mtrace messages */
  118. #define ICMP6_MAXTYPE 201
  119. #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
  120. #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
  121. #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
  122. #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
  123. #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
  124. #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
  125. #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
  126. #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
  127. #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
  128. #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
  129. #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
  130. #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
  131. #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
  132. #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
  133. #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
  134. #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
  135. #define ICMP6_NI_REFUSED 1 /* node information request is refused */
  136. #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
  137. #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
  138. #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
  139. #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
  140. /* Used in kernel only */
  141. #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
  142. #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
  143. /*
  144. * Multicast Listener Discovery
  145. */
  146. struct mld6_hdr {
  147. struct icmp6_hdr mld6_hdr;
  148. struct in6_addr mld6_addr; /* multicast address */
  149. };
  150. #define mld6_type mld6_hdr.icmp6_type
  151. #define mld6_code mld6_hdr.icmp6_code
  152. #define mld6_cksum mld6_hdr.icmp6_cksum
  153. #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
  154. #define mld6_reserved mld6_hdr.icmp6_data16[1]
  155. #define MLD_MINLEN 24
  156. #define MLDV2_MINLEN 28
  157. /*
  158. * Neighbor Discovery
  159. */
  160. struct nd_router_solicit { /* router solicitation */
  161. struct icmp6_hdr nd_rs_hdr;
  162. /* could be followed by options */
  163. };
  164. #define nd_rs_type nd_rs_hdr.icmp6_type
  165. #define nd_rs_code nd_rs_hdr.icmp6_code
  166. #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
  167. #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
  168. struct nd_router_advert { /* router advertisement */
  169. struct icmp6_hdr nd_ra_hdr;
  170. uint32_t nd_ra_reachable; /* reachable time */
  171. uint32_t nd_ra_retransmit; /* retransmit timer */
  172. /* could be followed by options */
  173. };
  174. #define nd_ra_type nd_ra_hdr.icmp6_type
  175. #define nd_ra_code nd_ra_hdr.icmp6_code
  176. #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
  177. #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
  178. #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
  179. #define ND_RA_FLAG_MANAGED 0x80
  180. #define ND_RA_FLAG_OTHER 0x40
  181. #define ND_RA_FLAG_HOME_AGENT 0x20
  182. /*
  183. * Router preference values based on draft-draves-ipngwg-router-selection-01.
  184. * These are non-standard definitions.
  185. */
  186. #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
  187. #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
  188. #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
  189. #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
  190. #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
  191. #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
  192. struct nd_neighbor_solicit { /* neighbor solicitation */
  193. struct icmp6_hdr nd_ns_hdr;
  194. struct in6_addr nd_ns_target; /*target address */
  195. /* could be followed by options */
  196. };
  197. #define nd_ns_type nd_ns_hdr.icmp6_type
  198. #define nd_ns_code nd_ns_hdr.icmp6_code
  199. #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
  200. #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
  201. struct nd_neighbor_advert { /* neighbor advertisement */
  202. struct icmp6_hdr nd_na_hdr;
  203. struct in6_addr nd_na_target; /* target address */
  204. /* could be followed by options */
  205. };
  206. #define nd_na_type nd_na_hdr.icmp6_type
  207. #define nd_na_code nd_na_hdr.icmp6_code
  208. #define nd_na_cksum nd_na_hdr.icmp6_cksum
  209. #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
  210. #define ND_NA_FLAG_ROUTER 0x80000000
  211. #define ND_NA_FLAG_SOLICITED 0x40000000
  212. #define ND_NA_FLAG_OVERRIDE 0x20000000
  213. struct nd_redirect { /* redirect */
  214. struct icmp6_hdr nd_rd_hdr;
  215. struct in6_addr nd_rd_target; /* target address */
  216. struct in6_addr nd_rd_dst; /* destination address */
  217. /* could be followed by options */
  218. };
  219. #define nd_rd_type nd_rd_hdr.icmp6_type
  220. #define nd_rd_code nd_rd_hdr.icmp6_code
  221. #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
  222. #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
  223. struct nd_opt_hdr { /* Neighbor discovery option header */
  224. uint8_t nd_opt_type;
  225. uint8_t nd_opt_len;
  226. /* followed by option specific data*/
  227. };
  228. #define ND_OPT_SOURCE_LINKADDR 1
  229. #define ND_OPT_TARGET_LINKADDR 2
  230. #define ND_OPT_PREFIX_INFORMATION 3
  231. #define ND_OPT_REDIRECTED_HEADER 4
  232. #define ND_OPT_MTU 5
  233. #define ND_OPT_ADVINTERVAL 7
  234. #define ND_OPT_HOMEAGENT_INFO 8
  235. #define ND_OPT_ROUTE_INFO 24 /* RFC4191 */
  236. #define ND_OPT_RDNSS 25
  237. #define ND_OPT_DNSSL 31
  238. struct nd_opt_prefix_info { /* prefix information */
  239. nd_uint8_t nd_opt_pi_type;
  240. nd_uint8_t nd_opt_pi_len;
  241. nd_uint8_t nd_opt_pi_prefix_len;
  242. nd_uint8_t nd_opt_pi_flags_reserved;
  243. nd_uint32_t nd_opt_pi_valid_time;
  244. nd_uint32_t nd_opt_pi_preferred_time;
  245. nd_uint32_t nd_opt_pi_reserved2;
  246. struct in6_addr nd_opt_pi_prefix;
  247. };
  248. #define ND_OPT_PI_FLAG_ONLINK 0x80
  249. #define ND_OPT_PI_FLAG_AUTO 0x40
  250. #define ND_OPT_PI_FLAG_ROUTER 0x20 /*2292bis*/
  251. struct nd_opt_rd_hdr { /* redirected header */
  252. uint8_t nd_opt_rh_type;
  253. uint8_t nd_opt_rh_len;
  254. uint16_t nd_opt_rh_reserved1;
  255. uint32_t nd_opt_rh_reserved2;
  256. /* followed by IP header and data */
  257. };
  258. struct nd_opt_mtu { /* MTU option */
  259. uint8_t nd_opt_mtu_type;
  260. uint8_t nd_opt_mtu_len;
  261. uint16_t nd_opt_mtu_reserved;
  262. uint32_t nd_opt_mtu_mtu;
  263. };
  264. struct nd_opt_rdnss { /* RDNSS RFC 6106 5.1 */
  265. uint8_t nd_opt_rdnss_type;
  266. uint8_t nd_opt_rdnss_len;
  267. uint16_t nd_opt_rdnss_reserved;
  268. uint32_t nd_opt_rdnss_lifetime;
  269. struct in6_addr nd_opt_rdnss_addr[1]; /* variable-length */
  270. };
  271. struct nd_opt_dnssl { /* DNSSL RFC 6106 5.2 */
  272. uint8_t nd_opt_dnssl_type;
  273. uint8_t nd_opt_dnssl_len;
  274. uint16_t nd_opt_dnssl_reserved;
  275. uint32_t nd_opt_dnssl_lifetime;
  276. /* followed by list of DNS search domains, variable-length */
  277. };
  278. struct nd_opt_advinterval { /* Advertisement interval option */
  279. uint8_t nd_opt_adv_type;
  280. uint8_t nd_opt_adv_len;
  281. uint16_t nd_opt_adv_reserved;
  282. uint32_t nd_opt_adv_interval;
  283. };
  284. struct nd_opt_homeagent_info { /* Home Agent info */
  285. uint8_t nd_opt_hai_type;
  286. uint8_t nd_opt_hai_len;
  287. uint16_t nd_opt_hai_reserved;
  288. int16_t nd_opt_hai_preference;
  289. uint16_t nd_opt_hai_lifetime;
  290. };
  291. struct nd_opt_route_info { /* route info */
  292. uint8_t nd_opt_rti_type;
  293. uint8_t nd_opt_rti_len;
  294. uint8_t nd_opt_rti_prefixlen;
  295. uint8_t nd_opt_rti_flags;
  296. uint32_t nd_opt_rti_lifetime;
  297. /* prefix follows */
  298. };
  299. /*
  300. * icmp6 namelookup
  301. */
  302. struct icmp6_namelookup {
  303. struct icmp6_hdr icmp6_nl_hdr;
  304. uint8_t icmp6_nl_nonce[8];
  305. int32_t icmp6_nl_ttl;
  306. #if 0
  307. uint8_t icmp6_nl_len;
  308. uint8_t icmp6_nl_name[3];
  309. #endif
  310. /* could be followed by options */
  311. };
  312. /*
  313. * icmp6 node information
  314. */
  315. struct icmp6_nodeinfo {
  316. struct icmp6_hdr icmp6_ni_hdr;
  317. uint8_t icmp6_ni_nonce[8];
  318. /* could be followed by reply data */
  319. };
  320. #define ni_type icmp6_ni_hdr.icmp6_type
  321. #define ni_code icmp6_ni_hdr.icmp6_code
  322. #define ni_cksum icmp6_ni_hdr.icmp6_cksum
  323. #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
  324. #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
  325. #define NI_QTYPE_NOOP 0 /* NOOP */
  326. #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
  327. #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
  328. #define NI_QTYPE_DNSNAME 2 /* DNS Name */
  329. #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
  330. #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
  331. /* network endian */
  332. #define NI_SUPTYPE_FLAG_COMPRESS ((uint16_t)htons(0x1))
  333. #define NI_FQDN_FLAG_VALIDTTL ((uint16_t)htons(0x1))
  334. /* network endian */
  335. #define NI_NODEADDR_FLAG_TRUNCATE ((uint16_t)htons(0x1))
  336. #define NI_NODEADDR_FLAG_ALL ((uint16_t)htons(0x2))
  337. #define NI_NODEADDR_FLAG_COMPAT ((uint16_t)htons(0x4))
  338. #define NI_NODEADDR_FLAG_LINKLOCAL ((uint16_t)htons(0x8))
  339. #define NI_NODEADDR_FLAG_SITELOCAL ((uint16_t)htons(0x10))
  340. #define NI_NODEADDR_FLAG_GLOBAL ((uint16_t)htons(0x20))
  341. #define NI_NODEADDR_FLAG_ANYCAST ((uint16_t)htons(0x40)) /* just experimental. not in spec */
  342. struct ni_reply_fqdn {
  343. uint32_t ni_fqdn_ttl; /* TTL */
  344. uint8_t ni_fqdn_namelen; /* length in octets of the FQDN */
  345. uint8_t ni_fqdn_name[3]; /* XXX: alignment */
  346. };
  347. /*
  348. * Router Renumbering. as router-renum-08.txt
  349. */
  350. struct icmp6_router_renum { /* router renumbering header */
  351. struct icmp6_hdr rr_hdr;
  352. uint8_t rr_segnum;
  353. uint8_t rr_flags;
  354. uint16_t rr_maxdelay;
  355. uint32_t rr_reserved;
  356. };
  357. #define ICMP6_RR_FLAGS_TEST 0x80
  358. #define ICMP6_RR_FLAGS_REQRESULT 0x40
  359. #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
  360. #define ICMP6_RR_FLAGS_SPECSITE 0x10
  361. #define ICMP6_RR_FLAGS_PREVDONE 0x08
  362. #define rr_type rr_hdr.icmp6_type
  363. #define rr_code rr_hdr.icmp6_code
  364. #define rr_cksum rr_hdr.icmp6_cksum
  365. #define rr_seqnum rr_hdr.icmp6_data32[0]
  366. struct rr_pco_match { /* match prefix part */
  367. uint8_t rpm_code;
  368. uint8_t rpm_len;
  369. uint8_t rpm_ordinal;
  370. uint8_t rpm_matchlen;
  371. uint8_t rpm_minlen;
  372. uint8_t rpm_maxlen;
  373. uint16_t rpm_reserved;
  374. struct in6_addr rpm_prefix;
  375. };
  376. #define RPM_PCO_ADD 1
  377. #define RPM_PCO_CHANGE 2
  378. #define RPM_PCO_SETGLOBAL 3
  379. #define RPM_PCO_MAX 4
  380. struct rr_pco_use { /* use prefix part */
  381. uint8_t rpu_uselen;
  382. uint8_t rpu_keeplen;
  383. uint8_t rpu_ramask;
  384. uint8_t rpu_raflags;
  385. uint32_t rpu_vltime;
  386. uint32_t rpu_pltime;
  387. uint32_t rpu_flags;
  388. struct in6_addr rpu_prefix;
  389. };
  390. #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
  391. #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
  392. /* network endian */
  393. #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((uint32_t)htonl(0x80000000))
  394. #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((uint32_t)htonl(0x40000000))
  395. struct rr_result { /* router renumbering result message */
  396. uint16_t rrr_flags;
  397. uint8_t rrr_ordinal;
  398. uint8_t rrr_matchedlen;
  399. uint32_t rrr_ifid;
  400. struct in6_addr rrr_prefix;
  401. };
  402. /* network endian */
  403. #define ICMP6_RR_RESULT_FLAGS_OOB ((uint16_t)htons(0x0002))
  404. #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((uint16_t)htons(0x0001))
  405. static const char *get_rtpref(u_int);
  406. static const char *get_lifetime(uint32_t);
  407. static void print_lladdr(netdissect_options *ndo, const u_char *, size_t);
  408. static void icmp6_opt_print(netdissect_options *ndo, const u_char *, int);
  409. static void mld6_print(netdissect_options *ndo, const u_char *);
  410. static void mldv2_report_print(netdissect_options *ndo, const u_char *, u_int);
  411. static void mldv2_query_print(netdissect_options *ndo, const u_char *, u_int);
  412. static const struct udphdr *get_upperlayer(netdissect_options *ndo, const u_char *, u_int *);
  413. static void dnsname_print(netdissect_options *ndo, const u_char *, const u_char *);
  414. static void icmp6_nodeinfo_print(netdissect_options *ndo, u_int, const u_char *, const u_char *);
  415. static void icmp6_rrenum_print(netdissect_options *ndo, const u_char *, const u_char *);
  416. #ifndef abs
  417. #define abs(a) ((0 < (a)) ? (a) : -(a))
  418. #endif
  419. #include "rpl.h"
  420. static const struct tok icmp6_type_values[] = {
  421. { ICMP6_DST_UNREACH, "destination unreachable"},
  422. { ICMP6_PACKET_TOO_BIG, "packet too big"},
  423. { ICMP6_TIME_EXCEEDED, "time exceeded in-transit"},
  424. { ICMP6_PARAM_PROB, "parameter problem"},
  425. { ICMP6_ECHO_REQUEST, "echo request"},
  426. { ICMP6_ECHO_REPLY, "echo reply"},
  427. { MLD6_LISTENER_QUERY, "multicast listener query"},
  428. { MLD6_LISTENER_REPORT, "multicast listener report"},
  429. { MLD6_LISTENER_DONE, "multicast listener done"},
  430. { ND_ROUTER_SOLICIT, "router solicitation"},
  431. { ND_ROUTER_ADVERT, "router advertisement"},
  432. { ND_NEIGHBOR_SOLICIT, "neighbor solicitation"},
  433. { ND_NEIGHBOR_ADVERT, "neighbor advertisement"},
  434. { ND_REDIRECT, "redirect"},
  435. { ICMP6_ROUTER_RENUMBERING, "router renumbering"},
  436. { IND_SOLICIT, "inverse neighbor solicitation"},
  437. { IND_ADVERT, "inverse neighbor advertisement"},
  438. { MLDV2_LISTENER_REPORT, "multicast listener report v2"},
  439. { ICMP6_HADISCOV_REQUEST, "ha discovery request"},
  440. { ICMP6_HADISCOV_REPLY, "ha discovery reply"},
  441. { ICMP6_MOBILEPREFIX_SOLICIT, "mobile router solicitation"},
  442. { ICMP6_MOBILEPREFIX_ADVERT, "mobile router advertisement"},
  443. { ICMP6_WRUREQUEST, "who-are-you request"},
  444. { ICMP6_WRUREPLY, "who-are-you reply"},
  445. { ICMP6_NI_QUERY, "node information query"},
  446. { ICMP6_NI_REPLY, "node information reply"},
  447. { MLD6_MTRACE, "mtrace message"},
  448. { MLD6_MTRACE_RESP, "mtrace response"},
  449. { ND_RPL_MESSAGE, "RPL"},
  450. { 0, NULL }
  451. };
  452. static const struct tok icmp6_dst_unreach_code_values[] = {
  453. { ICMP6_DST_UNREACH_NOROUTE, "unreachable route" },
  454. { ICMP6_DST_UNREACH_ADMIN, " unreachable prohibited"},
  455. { ICMP6_DST_UNREACH_BEYONDSCOPE, "beyond scope"},
  456. { ICMP6_DST_UNREACH_ADDR, "unreachable address"},
  457. { ICMP6_DST_UNREACH_NOPORT, "unreachable port"},
  458. { 0, NULL }
  459. };
  460. static const struct tok icmp6_opt_pi_flag_values[] = {
  461. { ND_OPT_PI_FLAG_ONLINK, "onlink" },
  462. { ND_OPT_PI_FLAG_AUTO, "auto" },
  463. { ND_OPT_PI_FLAG_ROUTER, "router" },
  464. { 0, NULL }
  465. };
  466. static const struct tok icmp6_opt_ra_flag_values[] = {
  467. { ND_RA_FLAG_MANAGED, "managed" },
  468. { ND_RA_FLAG_OTHER, "other stateful"},
  469. { ND_RA_FLAG_HOME_AGENT, "home agent"},
  470. { 0, NULL }
  471. };
  472. static const struct tok icmp6_nd_na_flag_values[] = {
  473. { ND_NA_FLAG_ROUTER, "router" },
  474. { ND_NA_FLAG_SOLICITED, "solicited" },
  475. { ND_NA_FLAG_OVERRIDE, "override" },
  476. { 0, NULL }
  477. };
  478. static const struct tok icmp6_opt_values[] = {
  479. { ND_OPT_SOURCE_LINKADDR, "source link-address"},
  480. { ND_OPT_TARGET_LINKADDR, "destination link-address"},
  481. { ND_OPT_PREFIX_INFORMATION, "prefix info"},
  482. { ND_OPT_REDIRECTED_HEADER, "redirected header"},
  483. { ND_OPT_MTU, "mtu"},
  484. { ND_OPT_RDNSS, "rdnss"},
  485. { ND_OPT_DNSSL, "dnssl"},
  486. { ND_OPT_ADVINTERVAL, "advertisement interval"},
  487. { ND_OPT_HOMEAGENT_INFO, "homeagent information"},
  488. { ND_OPT_ROUTE_INFO, "route info"},
  489. { 0, NULL }
  490. };
  491. /* mldv2 report types */
  492. static const struct tok mldv2report2str[] = {
  493. { 1, "is_in" },
  494. { 2, "is_ex" },
  495. { 3, "to_in" },
  496. { 4, "to_ex" },
  497. { 5, "allow" },
  498. { 6, "block" },
  499. { 0, NULL }
  500. };
  501. static const char *
  502. get_rtpref(u_int v)
  503. {
  504. static const char *rtpref_str[] = {
  505. "medium", /* 00 */
  506. "high", /* 01 */
  507. "rsv", /* 10 */
  508. "low" /* 11 */
  509. };
  510. return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
  511. }
  512. static const char *
  513. get_lifetime(uint32_t v)
  514. {
  515. static char buf[20];
  516. if (v == (uint32_t)~0UL)
  517. return "infinity";
  518. else {
  519. snprintf(buf, sizeof(buf), "%us", v);
  520. return buf;
  521. }
  522. }
  523. static void
  524. print_lladdr(netdissect_options *ndo, const uint8_t *p, size_t l)
  525. {
  526. const uint8_t *ep, *q;
  527. q = p;
  528. ep = p + l;
  529. while (l > 0 && q < ep) {
  530. if (q > p)
  531. ND_PRINT((ndo,":"));
  532. ND_PRINT((ndo,"%02x", *q++));
  533. l--;
  534. }
  535. }
  536. static int icmp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
  537. const struct icmp6_hdr *icp, u_int len)
  538. {
  539. return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)icp, len, len,
  540. IPPROTO_ICMPV6);
  541. }
  542. static const struct tok rpl_mop_values[] = {
  543. { RPL_DIO_NONSTORING, "nonstoring"},
  544. { RPL_DIO_STORING, "storing"},
  545. { RPL_DIO_NONSTORING_MULTICAST, "nonstoring-multicast"},
  546. { RPL_DIO_STORING_MULTICAST, "storing-multicast"},
  547. { 0, NULL},
  548. };
  549. static const struct tok rpl_subopt_values[] = {
  550. { RPL_OPT_PAD0, "pad0"},
  551. { RPL_OPT_PADN, "padN"},
  552. { RPL_DIO_METRICS, "metrics"},
  553. { RPL_DIO_ROUTINGINFO, "routinginfo"},
  554. { RPL_DIO_CONFIG, "config"},
  555. { RPL_DAO_RPLTARGET, "rpltarget"},
  556. { RPL_DAO_TRANSITINFO, "transitinfo"},
  557. { RPL_DIO_DESTPREFIX, "destprefix"},
  558. { RPL_DAO_RPLTARGET_DESC, "rpltargetdesc"},
  559. { 0, NULL},
  560. };
  561. static void
  562. rpl_dio_printopt(netdissect_options *ndo,
  563. const struct rpl_dio_genoption *opt,
  564. u_int length)
  565. {
  566. if(length < RPL_DIO_GENOPTION_LEN) return;
  567. length -= RPL_DIO_GENOPTION_LEN;
  568. ND_TCHECK(opt->rpl_dio_len);
  569. while((opt->rpl_dio_type == RPL_OPT_PAD0 &&
  570. (const u_char *)opt < ndo->ndo_snapend) ||
  571. ND_TTEST2(*opt,(opt->rpl_dio_len+2))) {
  572. unsigned int optlen = opt->rpl_dio_len+2;
  573. if(opt->rpl_dio_type == RPL_OPT_PAD0) {
  574. optlen = 1;
  575. ND_PRINT((ndo, " opt:pad0"));
  576. } else {
  577. ND_PRINT((ndo, " opt:%s len:%u ",
  578. tok2str(rpl_subopt_values, "subopt:%u", opt->rpl_dio_type),
  579. optlen));
  580. if(ndo->ndo_vflag > 2) {
  581. unsigned int paylen = opt->rpl_dio_len;
  582. if(paylen > length) paylen = length;
  583. hex_print(ndo,
  584. " ",
  585. ((const uint8_t *)opt) + RPL_DIO_GENOPTION_LEN, /* content of DIO option */
  586. paylen);
  587. }
  588. }
  589. opt = (const struct rpl_dio_genoption *)(((const char *)opt) + optlen);
  590. length -= optlen;
  591. }
  592. return;
  593. trunc:
  594. ND_PRINT((ndo," [|truncated]"));
  595. return;
  596. }
  597. static void
  598. rpl_dio_print(netdissect_options *ndo,
  599. const u_char *bp, u_int length)
  600. {
  601. const struct nd_rpl_dio *dio = (const struct nd_rpl_dio *)bp;
  602. const char *dagid_str;
  603. ND_TCHECK(*dio);
  604. dagid_str = ip6addr_string (ndo, dio->rpl_dagid);
  605. ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u,rank:%u,%smop:%s,prf:%u]",
  606. dagid_str,
  607. dio->rpl_dtsn,
  608. dio->rpl_instanceid,
  609. EXTRACT_16BITS(&dio->rpl_dagrank),
  610. RPL_DIO_GROUNDED(dio->rpl_mopprf) ? "grounded,":"",
  611. tok2str(rpl_mop_values, "mop%u", RPL_DIO_MOP(dio->rpl_mopprf)),
  612. RPL_DIO_PRF(dio->rpl_mopprf)));
  613. if(ndo->ndo_vflag > 1) {
  614. const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)&dio[1];
  615. rpl_dio_printopt(ndo, opt, length);
  616. }
  617. return;
  618. trunc:
  619. ND_PRINT((ndo," [|truncated]"));
  620. return;
  621. }
  622. static void
  623. rpl_dao_print(netdissect_options *ndo,
  624. const u_char *bp, u_int length)
  625. {
  626. const struct nd_rpl_dao *dao = (const struct nd_rpl_dao *)bp;
  627. const char *dagid_str = "<elided>";
  628. ND_TCHECK(*dao);
  629. if (length < ND_RPL_DAO_MIN_LEN)
  630. goto tooshort;
  631. bp += ND_RPL_DAO_MIN_LEN;
  632. length -= ND_RPL_DAO_MIN_LEN;
  633. if(RPL_DAO_D(dao->rpl_flags)) {
  634. ND_TCHECK2(dao->rpl_dagid, DAGID_LEN);
  635. if (length < DAGID_LEN)
  636. goto tooshort;
  637. dagid_str = ip6addr_string (ndo, dao->rpl_dagid);
  638. bp += DAGID_LEN;
  639. length -= DAGID_LEN;
  640. }
  641. ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u%s%s,%02x]",
  642. dagid_str,
  643. dao->rpl_daoseq,
  644. dao->rpl_instanceid,
  645. RPL_DAO_K(dao->rpl_flags) ? ",acK":"",
  646. RPL_DAO_D(dao->rpl_flags) ? ",Dagid":"",
  647. dao->rpl_flags));
  648. if(ndo->ndo_vflag > 1) {
  649. const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)bp;
  650. rpl_dio_printopt(ndo, opt, length);
  651. }
  652. return;
  653. trunc:
  654. ND_PRINT((ndo," [|truncated]"));
  655. return;
  656. tooshort:
  657. ND_PRINT((ndo," [|length too short]"));
  658. return;
  659. }
  660. static void
  661. rpl_daoack_print(netdissect_options *ndo,
  662. const u_char *bp, u_int length)
  663. {
  664. const struct nd_rpl_daoack *daoack = (const struct nd_rpl_daoack *)bp;
  665. const char *dagid_str = "<elided>";
  666. ND_TCHECK2(*daoack, ND_RPL_DAOACK_MIN_LEN);
  667. if (length < ND_RPL_DAOACK_MIN_LEN)
  668. goto tooshort;
  669. bp += ND_RPL_DAOACK_MIN_LEN;
  670. length -= ND_RPL_DAOACK_MIN_LEN;
  671. if(RPL_DAOACK_D(daoack->rpl_flags)) {
  672. ND_TCHECK2(daoack->rpl_dagid, DAGID_LEN);
  673. if (length < DAGID_LEN)
  674. goto tooshort;
  675. dagid_str = ip6addr_string (ndo, daoack->rpl_dagid);
  676. bp += DAGID_LEN;
  677. length -= DAGID_LEN;
  678. }
  679. ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u,status:%u]",
  680. dagid_str,
  681. daoack->rpl_daoseq,
  682. daoack->rpl_instanceid,
  683. daoack->rpl_status));
  684. /* no officially defined options for DAOACK, but print any we find */
  685. if(ndo->ndo_vflag > 1) {
  686. const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)bp;
  687. rpl_dio_printopt(ndo, opt, length);
  688. }
  689. return;
  690. trunc:
  691. ND_PRINT((ndo," [|dao-truncated]"));
  692. return;
  693. tooshort:
  694. ND_PRINT((ndo," [|dao-length too short]"));
  695. return;
  696. }
  697. static void
  698. rpl_print(netdissect_options *ndo,
  699. const struct icmp6_hdr *hdr,
  700. const u_char *bp, u_int length)
  701. {
  702. int secured = hdr->icmp6_code & 0x80;
  703. int basecode= hdr->icmp6_code & 0x7f;
  704. if(secured) {
  705. ND_PRINT((ndo, ", (SEC) [worktodo]"));
  706. /* XXX
  707. * the next header pointer needs to move forward to
  708. * skip the secure part.
  709. */
  710. return;
  711. } else {
  712. ND_PRINT((ndo, ", (CLR)"));
  713. }
  714. switch(basecode) {
  715. case ND_RPL_DAG_IS:
  716. ND_PRINT((ndo, "DODAG Information Solicitation"));
  717. if(ndo->ndo_vflag) {
  718. }
  719. break;
  720. case ND_RPL_DAG_IO:
  721. ND_PRINT((ndo, "DODAG Information Object"));
  722. if(ndo->ndo_vflag) {
  723. rpl_dio_print(ndo, bp, length);
  724. }
  725. break;
  726. case ND_RPL_DAO:
  727. ND_PRINT((ndo, "Destination Advertisement Object"));
  728. if(ndo->ndo_vflag) {
  729. rpl_dao_print(ndo, bp, length);
  730. }
  731. break;
  732. case ND_RPL_DAO_ACK:
  733. ND_PRINT((ndo, "Destination Advertisement Object Ack"));
  734. if(ndo->ndo_vflag) {
  735. rpl_daoack_print(ndo, bp, length);
  736. }
  737. break;
  738. default:
  739. ND_PRINT((ndo, "RPL message, unknown code %u",hdr->icmp6_code));
  740. break;
  741. }
  742. return;
  743. #if 0
  744. trunc:
  745. ND_PRINT((ndo," [|truncated]"));
  746. return;
  747. #endif
  748. }
  749. void
  750. icmp6_print(netdissect_options *ndo,
  751. const u_char *bp, u_int length, const u_char *bp2, int fragmented)
  752. {
  753. const struct icmp6_hdr *dp;
  754. const struct ip6_hdr *ip;
  755. const struct ip6_hdr *oip;
  756. const struct udphdr *ouh;
  757. int dport;
  758. const u_char *ep;
  759. u_int prot;
  760. dp = (const struct icmp6_hdr *)bp;
  761. ip = (const struct ip6_hdr *)bp2;
  762. oip = (const struct ip6_hdr *)(dp + 1);
  763. /* 'ep' points to the end of available data. */
  764. ep = ndo->ndo_snapend;
  765. ND_TCHECK(dp->icmp6_cksum);
  766. if (ndo->ndo_vflag && !fragmented) {
  767. uint16_t sum, udp_sum;
  768. if (ND_TTEST2(bp[0], length)) {
  769. udp_sum = EXTRACT_16BITS(&dp->icmp6_cksum);
  770. sum = icmp6_cksum(ndo, ip, dp, length);
  771. if (sum != 0)
  772. ND_PRINT((ndo,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
  773. udp_sum,
  774. in_cksum_shouldbe(udp_sum, sum)));
  775. else
  776. ND_PRINT((ndo,"[icmp6 sum ok] "));
  777. }
  778. }
  779. ND_PRINT((ndo,"ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",dp->icmp6_type)));
  780. /* display cosmetics: print the packet length for printer that use the vflag now */
  781. if (ndo->ndo_vflag && (dp->icmp6_type == ND_ROUTER_SOLICIT ||
  782. dp->icmp6_type == ND_ROUTER_ADVERT ||
  783. dp->icmp6_type == ND_NEIGHBOR_ADVERT ||
  784. dp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
  785. dp->icmp6_type == ND_REDIRECT ||
  786. dp->icmp6_type == ICMP6_HADISCOV_REPLY ||
  787. dp->icmp6_type == ICMP6_MOBILEPREFIX_ADVERT ))
  788. ND_PRINT((ndo,", length %u", length));
  789. switch (dp->icmp6_type) {
  790. case ICMP6_DST_UNREACH:
  791. ND_TCHECK(oip->ip6_dst);
  792. ND_PRINT((ndo,", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code)));
  793. switch (dp->icmp6_code) {
  794. case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
  795. case ICMP6_DST_UNREACH_ADMIN:
  796. case ICMP6_DST_UNREACH_ADDR:
  797. ND_PRINT((ndo," %s",ip6addr_string(ndo, &oip->ip6_dst)));
  798. break;
  799. case ICMP6_DST_UNREACH_BEYONDSCOPE:
  800. ND_PRINT((ndo," %s, source address %s",
  801. ip6addr_string(ndo, &oip->ip6_dst),
  802. ip6addr_string(ndo, &oip->ip6_src)));
  803. break;
  804. case ICMP6_DST_UNREACH_NOPORT:
  805. if ((ouh = get_upperlayer(ndo, (const u_char *)oip, &prot))
  806. == NULL)
  807. goto trunc;
  808. dport = EXTRACT_16BITS(&ouh->uh_dport);
  809. switch (prot) {
  810. case IPPROTO_TCP:
  811. ND_PRINT((ndo,", %s tcp port %s",
  812. ip6addr_string(ndo, &oip->ip6_dst),
  813. tcpport_string(ndo, dport)));
  814. break;
  815. case IPPROTO_UDP:
  816. ND_PRINT((ndo,", %s udp port %s",
  817. ip6addr_string(ndo, &oip->ip6_dst),
  818. udpport_string(ndo, dport)));
  819. break;
  820. default:
  821. ND_PRINT((ndo,", %s protocol %d port %d unreachable",
  822. ip6addr_string(ndo, &oip->ip6_dst),
  823. oip->ip6_nxt, dport));
  824. break;
  825. }
  826. break;
  827. default:
  828. if (ndo->ndo_vflag <= 1) {
  829. print_unknown_data(ndo, bp,"\n\t",length);
  830. return;
  831. }
  832. break;
  833. }
  834. break;
  835. case ICMP6_PACKET_TOO_BIG:
  836. ND_TCHECK(dp->icmp6_mtu);
  837. ND_PRINT((ndo,", mtu %u", EXTRACT_32BITS(&dp->icmp6_mtu)));
  838. break;
  839. case ICMP6_TIME_EXCEEDED:
  840. ND_TCHECK(oip->ip6_dst);
  841. switch (dp->icmp6_code) {
  842. case ICMP6_TIME_EXCEED_TRANSIT:
  843. ND_PRINT((ndo," for %s",
  844. ip6addr_string(ndo, &oip->ip6_dst)));
  845. break;
  846. case ICMP6_TIME_EXCEED_REASSEMBLY:
  847. ND_PRINT((ndo," (reassembly)"));
  848. break;
  849. default:
  850. ND_PRINT((ndo,", unknown code (%u)", dp->icmp6_code));
  851. break;
  852. }
  853. break;
  854. case ICMP6_PARAM_PROB:
  855. ND_TCHECK(oip->ip6_dst);
  856. switch (dp->icmp6_code) {
  857. case ICMP6_PARAMPROB_HEADER:
  858. ND_PRINT((ndo,", erroneous - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
  859. break;
  860. case ICMP6_PARAMPROB_NEXTHEADER:
  861. ND_PRINT((ndo,", next header - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
  862. break;
  863. case ICMP6_PARAMPROB_OPTION:
  864. ND_PRINT((ndo,", option - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
  865. break;
  866. default:
  867. ND_PRINT((ndo,", code-#%d",
  868. dp->icmp6_code));
  869. break;
  870. }
  871. break;
  872. case ICMP6_ECHO_REQUEST:
  873. case ICMP6_ECHO_REPLY:
  874. ND_TCHECK(dp->icmp6_seq);
  875. ND_PRINT((ndo,", seq %u", EXTRACT_16BITS(&dp->icmp6_seq)));
  876. break;
  877. case ICMP6_MEMBERSHIP_QUERY:
  878. if (length == MLD_MINLEN) {
  879. mld6_print(ndo, (const u_char *)dp);
  880. } else if (length >= MLDV2_MINLEN) {
  881. ND_PRINT((ndo," v2"));
  882. mldv2_query_print(ndo, (const u_char *)dp, length);
  883. } else {
  884. ND_PRINT((ndo," unknown-version (len %u) ", length));
  885. }
  886. break;
  887. case ICMP6_MEMBERSHIP_REPORT:
  888. mld6_print(ndo, (const u_char *)dp);
  889. break;
  890. case ICMP6_MEMBERSHIP_REDUCTION:
  891. mld6_print(ndo, (const u_char *)dp);
  892. break;
  893. case ND_ROUTER_SOLICIT:
  894. #define RTSOLLEN 8
  895. if (ndo->ndo_vflag) {
  896. icmp6_opt_print(ndo, (const u_char *)dp + RTSOLLEN,
  897. length - RTSOLLEN);
  898. }
  899. break;
  900. case ND_ROUTER_ADVERT:
  901. #define RTADVLEN 16
  902. if (ndo->ndo_vflag) {
  903. const struct nd_router_advert *p;
  904. p = (const struct nd_router_advert *)dp;
  905. ND_TCHECK(p->nd_ra_retransmit);
  906. ND_PRINT((ndo,"\n\thop limit %u, Flags [%s]" \
  907. ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
  908. (u_int)p->nd_ra_curhoplimit,
  909. bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
  910. get_rtpref(p->nd_ra_flags_reserved),
  911. EXTRACT_16BITS(&p->nd_ra_router_lifetime),
  912. EXTRACT_32BITS(&p->nd_ra_reachable),
  913. EXTRACT_32BITS(&p->nd_ra_retransmit)));
  914. icmp6_opt_print(ndo, (const u_char *)dp + RTADVLEN,
  915. length - RTADVLEN);
  916. }
  917. break;
  918. case ND_NEIGHBOR_SOLICIT:
  919. {
  920. const struct nd_neighbor_solicit *p;
  921. p = (const struct nd_neighbor_solicit *)dp;
  922. ND_TCHECK(p->nd_ns_target);
  923. ND_PRINT((ndo,", who has %s", ip6addr_string(ndo, &p->nd_ns_target)));
  924. if (ndo->ndo_vflag) {
  925. #define NDSOLLEN 24
  926. icmp6_opt_print(ndo, (const u_char *)dp + NDSOLLEN,
  927. length - NDSOLLEN);
  928. }
  929. }
  930. break;
  931. case ND_NEIGHBOR_ADVERT:
  932. {
  933. const struct nd_neighbor_advert *p;
  934. p = (const struct nd_neighbor_advert *)dp;
  935. ND_TCHECK(p->nd_na_target);
  936. ND_PRINT((ndo,", tgt is %s",
  937. ip6addr_string(ndo, &p->nd_na_target)));
  938. if (ndo->ndo_vflag) {
  939. ND_PRINT((ndo,", Flags [%s]",
  940. bittok2str(icmp6_nd_na_flag_values,
  941. "none",
  942. EXTRACT_32BITS(&p->nd_na_flags_reserved))));
  943. #define NDADVLEN 24
  944. icmp6_opt_print(ndo, (const u_char *)dp + NDADVLEN,
  945. length - NDADVLEN);
  946. #undef NDADVLEN
  947. }
  948. }
  949. break;
  950. case ND_REDIRECT:
  951. #define RDR(i) ((const struct nd_redirect *)(i))
  952. ND_TCHECK(RDR(dp)->nd_rd_dst);
  953. ND_PRINT((ndo,", %s", ip6addr_string(ndo, &RDR(dp)->nd_rd_dst)));
  954. ND_TCHECK(RDR(dp)->nd_rd_target);
  955. ND_PRINT((ndo," to %s",
  956. ip6addr_string(ndo, &RDR(dp)->nd_rd_target)));
  957. #define REDIRECTLEN 40
  958. if (ndo->ndo_vflag) {
  959. icmp6_opt_print(ndo, (const u_char *)dp + REDIRECTLEN,
  960. length - REDIRECTLEN);
  961. }
  962. break;
  963. #undef REDIRECTLEN
  964. #undef RDR
  965. case ICMP6_ROUTER_RENUMBERING:
  966. icmp6_rrenum_print(ndo, bp, ep);
  967. break;
  968. case ICMP6_NI_QUERY:
  969. case ICMP6_NI_REPLY:
  970. icmp6_nodeinfo_print(ndo, length, bp, ep);
  971. break;
  972. case IND_SOLICIT:
  973. case IND_ADVERT:
  974. break;
  975. case ICMP6_V2_MEMBERSHIP_REPORT:
  976. mldv2_report_print(ndo, (const u_char *) dp, length);
  977. break;
  978. case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
  979. case ICMP6_HADISCOV_REQUEST:
  980. ND_TCHECK(dp->icmp6_data16[0]);
  981. ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
  982. break;
  983. case ICMP6_HADISCOV_REPLY:
  984. if (ndo->ndo_vflag) {
  985. const struct in6_addr *in6;
  986. const u_char *cp;
  987. ND_TCHECK(dp->icmp6_data16[0]);
  988. ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
  989. cp = (const u_char *)dp + length;
  990. in6 = (const struct in6_addr *)(dp + 1);
  991. for (; (const u_char *)in6 < cp; in6++) {
  992. ND_TCHECK(*in6);
  993. ND_PRINT((ndo,", %s", ip6addr_string(ndo, in6)));
  994. }
  995. }
  996. break;
  997. case ICMP6_MOBILEPREFIX_ADVERT:
  998. if (ndo->ndo_vflag) {
  999. ND_TCHECK(dp->icmp6_data16[0]);
  1000. ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
  1001. ND_TCHECK(dp->icmp6_data16[1]);
  1002. if (dp->icmp6_data16[1] & 0xc0)
  1003. ND_PRINT((ndo," "));
  1004. if (dp->icmp6_data16[1] & 0x80)
  1005. ND_PRINT((ndo,"M"));
  1006. if (dp->icmp6_data16[1] & 0x40)
  1007. ND_PRINT((ndo,"O"));
  1008. #define MPADVLEN 8
  1009. icmp6_opt_print(ndo, (const u_char *)dp + MPADVLEN,
  1010. length - MPADVLEN);
  1011. }
  1012. break;
  1013. case ND_RPL_MESSAGE:
  1014. /* plus 4, because struct icmp6_hdr contains 4 bytes of icmp payload */
  1015. rpl_print(ndo, dp, &dp->icmp6_data8[0], length-sizeof(struct icmp6_hdr)+4);
  1016. break;
  1017. default:
  1018. ND_PRINT((ndo,", length %u", length));
  1019. if (ndo->ndo_vflag <= 1)
  1020. print_unknown_data(ndo, bp,"\n\t", length);
  1021. return;
  1022. }
  1023. if (!ndo->ndo_vflag)
  1024. ND_PRINT((ndo,", length %u", length));
  1025. return;
  1026. trunc:
  1027. ND_PRINT((ndo, "[|icmp6]"));
  1028. }
  1029. static const struct udphdr *
  1030. get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
  1031. {
  1032. const u_char *ep;
  1033. const struct ip6_hdr *ip6 = (const struct ip6_hdr *)bp;
  1034. const struct udphdr *uh;
  1035. const struct ip6_hbh *hbh;
  1036. const struct ip6_frag *fragh;
  1037. const struct ah *ah;
  1038. u_int nh;
  1039. int hlen;
  1040. /* 'ep' points to the end of available data. */
  1041. ep = ndo->ndo_snapend;
  1042. if (!ND_TTEST(ip6->ip6_nxt))
  1043. return NULL;
  1044. nh = ip6->ip6_nxt;
  1045. hlen = sizeof(struct ip6_hdr);
  1046. while (bp < ep) {
  1047. bp += hlen;
  1048. switch(nh) {
  1049. case IPPROTO_UDP:
  1050. case IPPROTO_TCP:
  1051. uh = (const struct udphdr *)bp;
  1052. if (ND_TTEST(uh->uh_dport)) {
  1053. *prot = nh;
  1054. return(uh);
  1055. }
  1056. else
  1057. return(NULL);
  1058. /* NOTREACHED */
  1059. case IPPROTO_HOPOPTS:
  1060. case IPPROTO_DSTOPTS:
  1061. case IPPROTO_ROUTING:
  1062. hbh = (const struct ip6_hbh *)bp;
  1063. if (!ND_TTEST(hbh->ip6h_len))
  1064. return(NULL);
  1065. nh = hbh->ip6h_nxt;
  1066. hlen = (hbh->ip6h_len + 1) << 3;
  1067. break;
  1068. case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
  1069. fragh = (const struct ip6_frag *)bp;
  1070. if (!ND_TTEST(fragh->ip6f_offlg))
  1071. return(NULL);
  1072. /* fragments with non-zero offset are meaningless */
  1073. if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
  1074. return(NULL);
  1075. nh = fragh->ip6f_nxt;
  1076. hlen = sizeof(struct ip6_frag);
  1077. break;
  1078. case IPPROTO_AH:
  1079. ah = (const struct ah *)bp;
  1080. if (!ND_TTEST(ah->ah_len))
  1081. return(NULL);
  1082. nh = ah->ah_nxt;
  1083. hlen = (ah->ah_len + 2) << 2;
  1084. break;
  1085. default: /* unknown or undecodable header */
  1086. *prot = nh; /* meaningless, but set here anyway */
  1087. return(NULL);
  1088. }
  1089. }
  1090. return(NULL); /* should be notreached, though */
  1091. }
  1092. static void
  1093. icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid)
  1094. {
  1095. const struct nd_opt_hdr *op;
  1096. const struct nd_opt_prefix_info *opp;
  1097. const struct nd_opt_mtu *opm;
  1098. const struct nd_opt_rdnss *oprd;
  1099. const struct nd_opt_dnssl *opds;
  1100. const struct nd_opt_advinterval *opa;
  1101. const struct nd_opt_homeagent_info *oph;
  1102. const struct nd_opt_route_info *opri;
  1103. const u_char *cp, *ep, *domp;
  1104. struct in6_addr in6;
  1105. const struct in6_addr *in6p;
  1106. size_t l;
  1107. u_int i;
  1108. #define ECHECK(var) if ((const u_char *)&(var) > ep - sizeof(var)) return
  1109. cp = bp;
  1110. /* 'ep' points to the end of available data. */
  1111. ep = ndo->ndo_snapend;
  1112. while (cp < ep) {
  1113. op = (const struct nd_opt_hdr *)cp;
  1114. ECHECK(op->nd_opt_len);
  1115. if (resid <= 0)
  1116. return;
  1117. if (op->nd_opt_len == 0)
  1118. goto trunc;
  1119. if (cp + (op->nd_opt_len << 3) > ep)
  1120. goto trunc;
  1121. ND_PRINT((ndo,"\n\t %s option (%u), length %u (%u): ",
  1122. tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
  1123. op->nd_opt_type,
  1124. op->nd_opt_len << 3,
  1125. op->nd_opt_len));
  1126. switch (op->nd_opt_type) {
  1127. case ND_OPT_SOURCE_LINKADDR:
  1128. l = (op->nd_opt_len << 3) - 2;
  1129. print_lladdr(ndo, cp + 2, l);
  1130. break;
  1131. case ND_OPT_TARGET_LINKADDR:
  1132. l = (op->nd_opt_len << 3) - 2;
  1133. print_lladdr(ndo, cp + 2, l);
  1134. break;
  1135. case ND_OPT_PREFIX_INFORMATION:
  1136. opp = (const struct nd_opt_prefix_info *)op;
  1137. ND_TCHECK(opp->nd_opt_pi_prefix);
  1138. ND_PRINT((ndo,"%s/%u%s, Flags [%s], valid time %s",
  1139. ip6addr_string(ndo, &opp->nd_opt_pi_prefix),
  1140. opp->nd_opt_pi_prefix_len,
  1141. (op->nd_opt_len != 4) ? "badlen" : "",
  1142. bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
  1143. get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time))));
  1144. ND_PRINT((ndo,", pref. time %s", get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_preferred_time))));
  1145. break;
  1146. case ND_OPT_REDIRECTED_HEADER:
  1147. print_unknown_data(ndo, bp,"\n\t ",op->nd_opt_len<<3);
  1148. /* xxx */
  1149. break;
  1150. case ND_OPT_MTU:
  1151. opm = (const struct nd_opt_mtu *)op;
  1152. ND_TCHECK(opm->nd_opt_mtu_mtu);
  1153. ND_PRINT((ndo," %u%s",
  1154. EXTRACT_32BITS(&opm->nd_opt_mtu_mtu),
  1155. (op->nd_opt_len != 1) ? "bad option length" : "" ));
  1156. break;
  1157. case ND_OPT_RDNSS:
  1158. oprd = (const struct nd_opt_rdnss *)op;
  1159. l = (op->nd_opt_len - 1) / 2;
  1160. ND_PRINT((ndo," lifetime %us,",
  1161. EXTRACT_32BITS(&oprd->nd_opt_rdnss_lifetime)));
  1162. for (i = 0; i < l; i++) {
  1163. ND_TCHECK(oprd->nd_opt_rdnss_addr[i]);
  1164. ND_PRINT((ndo," addr: %s",
  1165. ip6addr_string(ndo, &oprd->nd_opt_rdnss_addr[i])));
  1166. }
  1167. break;
  1168. case ND_OPT_DNSSL:
  1169. opds = (const struct nd_opt_dnssl *)op;
  1170. ND_PRINT((ndo," lifetime %us, domain(s):",
  1171. EXTRACT_32BITS(&opds->nd_opt_dnssl_lifetime)));
  1172. domp = cp + 8; /* domain names, variable-sized, RFC1035-encoded */
  1173. while (domp < cp + (op->nd_opt_len << 3) && *domp != '\0')
  1174. {
  1175. ND_PRINT((ndo, " "));
  1176. if ((domp = ns_nprint (ndo, domp, bp)) == NULL)
  1177. goto trunc;
  1178. }
  1179. break;
  1180. case ND_OPT_ADVINTERVAL:
  1181. opa = (const struct nd_opt_advinterval *)op;
  1182. ND_TCHECK(opa->nd_opt_adv_interval);
  1183. ND_PRINT((ndo," %ums", EXTRACT_32BITS(&opa->nd_opt_adv_interval)));
  1184. break;
  1185. case ND_OPT_HOMEAGENT_INFO:
  1186. oph = (const struct nd_opt_homeagent_info *)op;
  1187. ND_TCHECK(oph->nd_opt_hai_lifetime);
  1188. ND_PRINT((ndo," preference %u, lifetime %u",
  1189. EXTRACT_16BITS(&oph->nd_opt_hai_preference),
  1190. EXTRACT_16BITS(&oph->nd_opt_hai_lifetime)));
  1191. break;
  1192. case ND_OPT_ROUTE_INFO:
  1193. opri = (const struct nd_opt_route_info *)op;
  1194. ND_TCHECK(opri->nd_opt_rti_lifetime);
  1195. memset(&in6, 0, sizeof(in6));
  1196. in6p = (const struct in6_addr *)(opri + 1);
  1197. switch (op->nd_opt_len) {
  1198. case 1:
  1199. break;
  1200. case 2:
  1201. ND_TCHECK2(*in6p, 8);
  1202. memcpy(&in6, opri + 1, 8);
  1203. break;
  1204. case 3:
  1205. ND_TCHECK(*in6p);
  1206. memcpy(&in6, opri + 1, sizeof(in6));
  1207. break;
  1208. default:
  1209. goto trunc;
  1210. }
  1211. ND_PRINT((ndo," %s/%u", ip6addr_string(ndo, &in6),
  1212. opri->nd_opt_rti_prefixlen));
  1213. ND_PRINT((ndo,", pref=%s", get_rtpref(opri->nd_opt_rti_flags)));
  1214. ND_PRINT((ndo,", lifetime=%s",
  1215. get_lifetime(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime))));
  1216. break;
  1217. default:
  1218. if (ndo->ndo_vflag <= 1) {
  1219. print_unknown_data(ndo,cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
  1220. return;
  1221. }
  1222. break;
  1223. }
  1224. /* do we want to see an additional hexdump ? */
  1225. if (ndo->ndo_vflag> 1)
  1226. print_unknown_data(ndo, cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
  1227. cp += op->nd_opt_len << 3;
  1228. resid -= op->nd_opt_len << 3;
  1229. }
  1230. return;
  1231. trunc:
  1232. ND_PRINT((ndo, "[ndp opt]"));
  1233. return;
  1234. #undef ECHECK
  1235. }
  1236. static void
  1237. mld6_print(netdissect_options *ndo, const u_char *bp)
  1238. {
  1239. const struct mld6_hdr *mp = (const struct mld6_hdr *)bp;
  1240. const u_char *ep;
  1241. /* 'ep' points to the end of available data. */
  1242. ep = ndo->ndo_snapend;
  1243. if ((const u_char *)mp + sizeof(*mp) > ep)
  1244. return;
  1245. ND_PRINT((ndo,"max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay)));
  1246. ND_PRINT((ndo,"addr: %s", ip6addr_string(ndo, &mp->mld6_addr)));
  1247. }
  1248. static void
  1249. mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
  1250. {
  1251. const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
  1252. u_int group, nsrcs, ngroups;
  1253. u_int i, j;
  1254. /* Minimum len is 8 */
  1255. if (len < 8) {
  1256. ND_PRINT((ndo," [invalid len %d]", len));
  1257. return;
  1258. }
  1259. ND_TCHECK(icp->icmp6_data16[1]);
  1260. ngroups = EXTRACT_16BITS(&icp->icmp6_data16[1]);
  1261. ND_PRINT((ndo,", %d group record(s)", ngroups));
  1262. if (ndo->ndo_vflag > 0) {
  1263. /* Print the group records */
  1264. group = 8;
  1265. for (i = 0; i < ngroups; i++) {
  1266. /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
  1267. if (len < group + 20) {
  1268. ND_PRINT((ndo," [invalid number of groups]"));
  1269. return;
  1270. }
  1271. ND_TCHECK2(bp[group + 4], sizeof(struct in6_addr));
  1272. ND_PRINT((ndo," [gaddr %s", ip6addr_string(ndo, &bp[group + 4])));
  1273. ND_PRINT((ndo," %s", tok2str(mldv2report2str, " [v2-report-#%d]",
  1274. bp[group])));
  1275. nsrcs = (bp[group + 2] << 8) + bp[group + 3];
  1276. /* Check the number of sources and print them */
  1277. if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
  1278. ND_PRINT((ndo," [invalid number of sources %d]", nsrcs));
  1279. return;
  1280. }
  1281. if (ndo->ndo_vflag == 1)
  1282. ND_PRINT((ndo,", %d source(s)", nsrcs));
  1283. else {
  1284. /* Print the sources */
  1285. ND_PRINT((ndo," {"));
  1286. for (j = 0; j < nsrcs; j++) {
  1287. ND_TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
  1288. sizeof(struct in6_addr));
  1289. ND_PRINT((ndo," %s", ip6addr_string(ndo, &bp[group + 20 + j * sizeof(struct in6_addr)])));
  1290. }
  1291. ND_PRINT((ndo," }"));
  1292. }
  1293. /* Next group record */
  1294. group += 20 + nsrcs * sizeof(struct in6_addr);
  1295. ND_PRINT((ndo,"]"));
  1296. }
  1297. }
  1298. return;
  1299. trunc:
  1300. ND_PRINT((ndo,"[|icmp6]"));
  1301. return;
  1302. }
  1303. static void
  1304. mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
  1305. {
  1306. const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
  1307. u_int mrc;
  1308. int mrt, qqi;
  1309. u_int nsrcs;
  1310. register u_int i;
  1311. /* Minimum len is 28 */
  1312. if (len < 28) {
  1313. ND_PRINT((ndo," [invalid len %d]", len));
  1314. return;
  1315. }
  1316. ND_TCHECK(icp->icmp6_data16[0]);
  1317. mrc = EXTRACT_16BITS(&icp->icmp6_data16[0]);
  1318. if (mrc < 32768) {
  1319. mrt = mrc;
  1320. } else {
  1321. mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
  1322. }
  1323. if (ndo->ndo_vflag) {
  1324. ND_PRINT((ndo," [max resp delay=%d]", mrt));
  1325. }
  1326. ND_TCHECK2(bp[8], sizeof(struct in6_addr));
  1327. ND_PRINT((ndo," [gaddr %s", ip6addr_string(ndo, &bp[8])));
  1328. if (ndo->ndo_vflag) {
  1329. ND_TCHECK(bp[25]);
  1330. if (bp[24] & 0x08) {
  1331. ND_PRINT((ndo," sflag"));
  1332. }
  1333. if (bp[24] & 0x07) {
  1334. ND_PRINT((ndo," robustness=%d", bp[24] & 0x07));
  1335. }
  1336. if (bp[25] < 128) {
  1337. qqi = bp[25];
  1338. } else {
  1339. qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
  1340. }
  1341. ND_PRINT((ndo," qqi=%d", qqi));
  1342. }
  1343. ND_TCHECK2(bp[26], 2);
  1344. nsrcs = EXTRACT_16BITS(&bp[26]);
  1345. if (nsrcs > 0) {
  1346. if (len < 28 + nsrcs * sizeof(struct in6_addr))
  1347. ND_PRINT((ndo," [invalid number of sources]"));
  1348. else if (ndo->ndo_vflag > 1) {
  1349. ND_PRINT((ndo," {"));
  1350. for (i = 0; i < nsrcs; i++) {
  1351. ND_TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
  1352. sizeof(struct in6_addr));
  1353. ND_PRINT((ndo," %s", ip6addr_string(ndo, &bp[28 + i * sizeof(struct in6_addr)])));
  1354. }
  1355. ND_PRINT((ndo," }"));
  1356. } else
  1357. ND_PRINT((ndo,", %d source(s)", nsrcs));
  1358. }
  1359. ND_PRINT((ndo,"]"));
  1360. return;
  1361. trunc:
  1362. ND_PRINT((ndo,"[|icmp6]"));
  1363. return;
  1364. }
  1365. static void
  1366. dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
  1367. {
  1368. int i;
  1369. /* DNS name decoding - no decompression */
  1370. ND_PRINT((ndo,", \""));
  1371. while (cp < ep) {
  1372. i = *cp++;
  1373. if (i) {
  1374. if (i > ep - cp) {
  1375. ND_PRINT((ndo,"???"));
  1376. break;
  1377. }
  1378. while (i-- && cp < ep) {
  1379. safeputchar(ndo, *cp);
  1380. cp++;
  1381. }
  1382. if (cp + 1 < ep && *cp)
  1383. ND_PRINT((ndo,"."));
  1384. } else {
  1385. if (cp == ep) {
  1386. /* FQDN */
  1387. ND_PRINT((ndo,"."));
  1388. } else if (cp + 1 == ep && *cp == '\0') {
  1389. /* truncated */
  1390. } else {
  1391. /* invalid */
  1392. ND_PRINT((ndo,"???"));
  1393. }
  1394. break;
  1395. }
  1396. }
  1397. ND_PRINT((ndo,"\""));
  1398. }
  1399. static void
  1400. icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, const u_char *ep)
  1401. {
  1402. const struct icmp6_nodeinfo *ni6;
  1403. const struct icmp6_hdr *dp;
  1404. const u_char *cp;
  1405. size_t siz, i;
  1406. int needcomma;
  1407. if (ep < bp)
  1408. return;
  1409. dp = (const struct icmp6_hdr *)bp;
  1410. ni6 = (const struct icmp6_nodeinfo *)bp;
  1411. siz = ep - bp;
  1412. switch (ni6->ni_type) {
  1413. case ICMP6_NI_QUERY:
  1414. if (siz == sizeof(*dp) + 4) {
  1415. /* KAME who-are-you */
  1416. ND_PRINT((ndo," who-are-you request"));
  1417. break;
  1418. }
  1419. ND_PRINT((ndo," node information query"));
  1420. ND_TCHECK2(*dp, sizeof(*ni6));
  1421. ni6 = (const struct icmp6_nodeinfo *)dp;
  1422. ND_PRINT((ndo," (")); /*)*/
  1423. switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
  1424. case NI_QTYPE_NOOP:
  1425. ND_PRINT((ndo,"noop"));
  1426. break;
  1427. case NI_QTYPE_SUPTYPES:
  1428. ND_PRINT((ndo,"supported qtypes"));
  1429. i = EXTRACT_16BITS(&ni6->ni_flags);
  1430. if (i)
  1431. ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
  1432. break;
  1433. case NI_QTYPE_FQDN:
  1434. ND_PRINT((ndo,"DNS name"));
  1435. break;
  1436. case NI_QTYPE_NODEADDR:
  1437. ND_PRINT((ndo,"node addresses"));
  1438. i = ni6->ni_flags;
  1439. if (!i)
  1440. break;
  1441. /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
  1442. ND_PRINT((ndo," [%s%s%s%s%s%s]",
  1443. (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
  1444. (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
  1445. (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
  1446. (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
  1447. (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
  1448. (i & NI_NODEADDR_FLAG_ALL) ? "A" : ""));
  1449. break;
  1450. default:
  1451. ND_PRINT((ndo,"unknown"));
  1452. break;
  1453. }
  1454. if (ni6->ni_qtype == NI_QTYPE_NOOP ||
  1455. ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
  1456. if (siz != sizeof(*ni6))
  1457. if (ndo->ndo_vflag)
  1458. ND_PRINT((ndo,", invalid len"));
  1459. /*(*/
  1460. ND_PRINT((ndo,")"));
  1461. break;
  1462. }
  1463. /* XXX backward compat, icmp-name-lookup-03 */
  1464. if (siz == sizeof(*ni6)) {
  1465. ND_PRINT((ndo,", 03 draft"));
  1466. /*(*/
  1467. ND_PRINT((ndo,")"));
  1468. break;
  1469. }
  1470. switch (ni6->ni_code) {
  1471. case ICMP6_NI_SUBJ_IPV6:
  1472. if (!ND_TTEST2(*dp,
  1473. sizeof(*ni6) + sizeof(struct in6_addr)))
  1474. break;
  1475. if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
  1476. if (ndo->ndo_vflag)
  1477. ND_PRINT((ndo,", invalid subject len"));
  1478. break;
  1479. }
  1480. ND_PRINT((ndo,", subject=%s",
  1481. ip6addr_string(ndo, ni6 + 1)));
  1482. break;
  1483. case ICMP6_NI_SUBJ_FQDN:
  1484. ND_PRINT((ndo,", subject=DNS name"));
  1485. cp = (const u_char *)(ni6 + 1);
  1486. if (cp[0] == ep - cp - 1) {
  1487. /* icmp-name-lookup-03, pascal string */
  1488. if (ndo->ndo_vflag)
  1489. ND_PRINT((ndo,", 03 draft"));
  1490. cp++;
  1491. ND_PRINT((ndo,", \""));
  1492. while (cp < ep) {
  1493. safeputchar(ndo, *cp);
  1494. cp++;
  1495. }
  1496. ND_PRINT((ndo,"\""));
  1497. } else
  1498. dnsname_print(ndo, cp, ep);
  1499. break;
  1500. case ICMP6_NI_SUBJ_IPV4:
  1501. if (!ND_TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
  1502. break;
  1503. if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
  1504. if (ndo->ndo_vflag)
  1505. ND_PRINT((ndo,", invalid subject len"));
  1506. break;
  1507. }
  1508. ND_PRINT((ndo,", subject=%s",
  1509. ipaddr_string(ndo, ni6 + 1)));
  1510. break;
  1511. default:
  1512. ND_PRINT((ndo,", unknown subject"));
  1513. break;
  1514. }
  1515. /*(*/
  1516. ND_PRINT((ndo,")"));
  1517. break;
  1518. case ICMP6_NI_REPLY:
  1519. if (icmp6len > siz) {
  1520. ND_PRINT((ndo,"[|icmp6: node information reply]"));
  1521. break;
  1522. }
  1523. needcomma = 0;
  1524. ND_TCHECK2(*dp, sizeof(*ni6));
  1525. ni6 = (const struct icmp6_nodeinfo *)dp;
  1526. ND_PRINT((ndo," node information reply"));
  1527. ND_PRINT((ndo," (")); /*)*/
  1528. switch (ni6->ni_code) {
  1529. case ICMP6_NI_SUCCESS:
  1530. if (ndo->ndo_vflag) {
  1531. ND_PRINT((ndo,"success"));
  1532. needcomma++;
  1533. }
  1534. break;
  1535. case ICMP6_NI_REFUSED:
  1536. ND_PRINT((ndo,"refused"));
  1537. needcomma++;
  1538. if (siz != sizeof(*ni6))
  1539. if (ndo->ndo_vflag)
  1540. ND_PRINT((ndo,", invalid length"));
  1541. break;
  1542. case ICMP6_NI_UNKNOWN:
  1543. ND_PRINT((ndo,"unknown"));
  1544. needcomma++;
  1545. if (siz != sizeof(*ni6))
  1546. if (ndo->ndo_vflag)
  1547. ND_PRINT((ndo,", invalid length"));
  1548. break;
  1549. }
  1550. if (ni6->ni_code != ICMP6_NI_SUCCESS) {
  1551. /*(*/
  1552. ND_PRINT((ndo,")"));
  1553. break;
  1554. }
  1555. switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
  1556. case NI_QTYPE_NOOP:
  1557. if (needcomma)
  1558. ND_PRINT((ndo,", "));
  1559. ND_PRINT((ndo,"noop"));
  1560. if (siz != sizeof(*ni6))
  1561. if (ndo->ndo_vflag)
  1562. ND_PRINT((ndo,", invalid length"));
  1563. break;
  1564. case NI_QTYPE_SUPTYPES:
  1565. if (needcomma)
  1566. ND_PRINT((ndo,", "));
  1567. ND_PRINT((ndo,"supported qtypes"));
  1568. i = EXTRACT_16BITS(&ni6->ni_flags);
  1569. if (i)
  1570. ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
  1571. break;
  1572. case NI_QTYPE_FQDN:
  1573. if (needcomma)
  1574. ND_PRINT((ndo,", "));
  1575. ND_PRINT((ndo,"DNS name"));
  1576. cp = (const u_char *)(ni6 + 1) + 4;
  1577. ND_TCHECK(cp[0]);
  1578. if (cp[0] == ep - cp - 1) {
  1579. /* icmp-name-lookup-03, pascal string */
  1580. if (ndo->ndo_vflag)
  1581. ND_PRINT((ndo,", 03 draft"));
  1582. cp++;
  1583. ND_PRINT((ndo,", \""));
  1584. while (cp < ep) {
  1585. safeputchar(ndo, *cp);
  1586. cp++;
  1587. }
  1588. ND_PRINT((ndo,"\""));
  1589. } else
  1590. dnsname_print(ndo, cp, ep);
  1591. if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0)
  1592. ND_PRINT((ndo," [TTL=%u]", EXTRACT_32BITS(ni6 + 1)));
  1593. break;
  1594. case NI_QTYPE_NODEADDR:
  1595. if (needcomma)
  1596. ND_PRINT((ndo,", "));
  1597. ND_PRINT((ndo,"node addresses"));
  1598. i = sizeof(*ni6);
  1599. while (i < siz) {
  1600. if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
  1601. break;
  1602. ND_PRINT((ndo," %s", ip6addr_string(ndo, bp + i)));
  1603. i += sizeof(struct in6_addr);
  1604. ND_PRINT((ndo,"(%d)", (int32_t)EXTRACT_32BITS(bp + i)));
  1605. i += sizeof(int32_t);
  1606. }
  1607. i = ni6->ni_flags;
  1608. if (!i)
  1609. break;
  1610. ND_PRINT((ndo," [%s%s%s%s%s%s%s]",
  1611. (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
  1612. (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
  1613. (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
  1614. (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
  1615. (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
  1616. (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
  1617. (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : ""));
  1618. break;
  1619. default:
  1620. if (needcomma)
  1621. ND_PRINT((ndo,", "));
  1622. ND_PRINT((ndo,"unknown"));
  1623. break;
  1624. }
  1625. /*(*/
  1626. ND_PRINT((ndo,")"));
  1627. break;
  1628. }
  1629. return;
  1630. trunc:
  1631. ND_PRINT((ndo, "[|icmp6]"));
  1632. }
  1633. static void
  1634. icmp6_rrenum_print(netdissect_options *ndo, const u_char *bp, const u_char *ep)
  1635. {
  1636. const struct icmp6_router_renum *rr6;
  1637. const char *cp;
  1638. const struct rr_pco_match *match;
  1639. const struct rr_pco_use *use;
  1640. char hbuf[NI_MAXHOST];
  1641. int n;
  1642. if (ep < bp)
  1643. return;
  1644. rr6 = (const struct icmp6_router_renum *)bp;
  1645. cp = (const char *)(rr6 + 1);
  1646. ND_TCHECK(rr6->rr_reserved);
  1647. switch (rr6->rr_code) {
  1648. case ICMP6_ROUTER_RENUMBERING_COMMAND:
  1649. ND_PRINT((ndo,"router renum: command"));
  1650. break;
  1651. case ICMP6_ROUTER_RENUMBERING_RESULT:
  1652. ND_PRINT((ndo,"router renum: result"));
  1653. break;
  1654. case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
  1655. ND_PRINT((ndo,"router renum: sequence number reset"));
  1656. break;
  1657. default:
  1658. ND_PRINT((ndo,"router renum: code-#%d", rr6->rr_code));
  1659. break;
  1660. }
  1661. ND_PRINT((ndo,", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum)));
  1662. if (ndo->ndo_vflag) {
  1663. #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
  1664. ND_PRINT((ndo,"[")); /*]*/
  1665. if (rr6->rr_flags) {
  1666. ND_PRINT((ndo,"%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
  1667. F(ICMP6_RR_FLAGS_REQRESULT, "R"),
  1668. F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
  1669. F(ICMP6_RR_FLAGS_SPECSITE, "S"),
  1670. F(ICMP6_RR_FLAGS_PREVDONE, "P")));
  1671. }
  1672. ND_PRINT((ndo,"seg=%u,", rr6->rr_segnum));
  1673. ND_PRINT((ndo,"maxdelay=%u", EXTRACT_16BITS(&rr6->rr_maxdelay)));
  1674. if (rr6->rr_reserved)
  1675. ND_PRINT((ndo,"rsvd=0x%x", EXTRACT_32BITS(&rr6->rr_reserved)));
  1676. /*[*/
  1677. ND_PRINT((ndo,"]"));
  1678. #undef F
  1679. }
  1680. if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
  1681. match = (const struct rr_pco_match *)cp;
  1682. cp = (const char *)(match + 1);
  1683. ND_TCHECK(match->rpm_prefix);
  1684. if (ndo->ndo_vflag > 1)
  1685. ND_PRINT((ndo,"\n\t"));
  1686. else
  1687. ND_PRINT((ndo," "));
  1688. ND_PRINT((ndo,"match(")); /*)*/
  1689. switch (match->rpm_code) {
  1690. case RPM_PCO_ADD: ND_PRINT((ndo,"add")); break;
  1691. case RPM_PCO_CHANGE: ND_PRINT((ndo,"change")); break;
  1692. case RPM_PCO_SETGLOBAL: ND_PRINT((ndo,"setglobal")); break;
  1693. default: ND_PRINT((ndo,"#%u", match->rpm_code)); break;
  1694. }
  1695. if (ndo->ndo_vflag) {
  1696. ND_PRINT((ndo,",ord=%u", match->rpm_ordinal));
  1697. ND_PRINT((ndo,",min=%u", match->rpm_minlen));
  1698. ND_PRINT((ndo,",max=%u", match->rpm_maxlen));
  1699. }
  1700. if (addrtostr6(&match->rpm_prefix, hbuf, sizeof(hbuf)))
  1701. ND_PRINT((ndo,",%s/%u", hbuf, match->rpm_matchlen));
  1702. else
  1703. ND_PRINT((ndo,",?/%u", match->rpm_matchlen));
  1704. /*(*/
  1705. ND_PRINT((ndo,")"));
  1706. n = match->rpm_len - 3;
  1707. if (n % 4)
  1708. goto trunc;
  1709. n /= 4;
  1710. while (n-- > 0) {
  1711. use = (const struct rr_pco_use *)cp;
  1712. cp = (const char *)(use + 1);
  1713. ND_TCHECK(use->rpu_prefix);
  1714. if (ndo->ndo_vflag > 1)
  1715. ND_PRINT((ndo,"\n\t"));
  1716. else
  1717. ND_PRINT((ndo," "));
  1718. ND_PRINT((ndo,"use(")); /*)*/
  1719. if (use->rpu_flags) {
  1720. #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
  1721. ND_PRINT((ndo,"%s%s,",
  1722. F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
  1723. F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P")));
  1724. #undef F
  1725. }
  1726. if (ndo->ndo_vflag) {
  1727. ND_PRINT((ndo,"mask=0x%x,", use->rpu_ramask));
  1728. ND_PRINT((ndo,"raflags=0x%x,", use->rpu_raflags));
  1729. if (~use->rpu_vltime == 0)
  1730. ND_PRINT((ndo,"vltime=infty,"));
  1731. else
  1732. ND_PRINT((ndo,"vltime=%u,",
  1733. EXTRACT_32BITS(&use->rpu_vltime)));
  1734. if (~use->rpu_pltime == 0)
  1735. ND_PRINT((ndo,"pltime=infty,"));
  1736. else
  1737. ND_PRINT((ndo,"pltime=%u,",
  1738. EXTRACT_32BITS(&use->rpu_pltime)));
  1739. }
  1740. if (addrtostr6(&use->rpu_prefix, hbuf, sizeof(hbuf)))
  1741. ND_PRINT((ndo,"%s/%u/%u", hbuf, use->rpu_uselen,
  1742. use->rpu_keeplen));
  1743. else
  1744. ND_PRINT((ndo,"?/%u/%u", use->rpu_uselen,
  1745. use->rpu_keeplen));
  1746. /*(*/
  1747. ND_PRINT((ndo,")"));
  1748. }
  1749. }
  1750. return;
  1751. trunc:
  1752. ND_PRINT((ndo,"[|icmp6]"));
  1753. }
  1754. /*
  1755. * Local Variables:
  1756. * c-style: whitesmith
  1757. * c-basic-offset: 8
  1758. * End:
  1759. */