4 * Copyright (C) 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static const char rcsid
[] _U_
=
40 "@(#) Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.17.2.1 2005/04/20 22:19:06 guy Exp";
42 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
47 #include <tcpdump-stdinc.h>
53 #include "interface.h"
54 #include "addrtoname.h"
57 /* items outside of rfc2292bis */
59 #define IP6OPT_MINLEN 2
61 #ifndef IP6OPT_RTALERT_LEN
62 #define IP6OPT_RTALERT_LEN 4
64 #ifndef IP6OPT_JUMBO_LEN
65 #define IP6OPT_JUMBO_LEN 6
67 #define IP6OPT_HOMEADDR_MINLEN 18
68 #define IP6OPT_BU_MINLEN 10
69 #define IP6OPT_BA_MINLEN 13
70 #define IP6OPT_BR_MINLEN 2
71 #define IP6SOPT_UI 0x2
72 #define IP6SOPT_UI_MINLEN 4
73 #define IP6SOPT_ALTCOA 0x3
74 #define IP6SOPT_ALTCOA_MINLEN 18
75 #define IP6SOPT_AUTH 0x4
76 #define IP6SOPT_AUTH_MINLEN 6
78 static void ip6_sopt_print(const u_char
*, int);
81 ip6_sopt_print(const u_char
*bp
, int len
)
86 for (i
= 0; i
< len
; i
+= optlen
) {
87 if (bp
[i
] == IP6OPT_PAD1
)
91 optlen
= bp
[i
+ 1] + 2;
103 if (len
- i
< IP6OPT_MINLEN
) {
104 printf(", padn: trunc");
110 if (len
- i
< IP6SOPT_UI_MINLEN
) {
111 printf(", ui: trunc");
114 printf(", ui: 0x%04x ", EXTRACT_16BITS(&bp
[i
+ 2]));
117 if (len
- i
< IP6SOPT_ALTCOA_MINLEN
) {
118 printf(", altcoa: trunc");
121 printf(", alt-CoA: %s", ip6addr_string(&bp
[i
+2]));
124 if (len
- i
< IP6SOPT_AUTH_MINLEN
) {
125 printf(", auth: trunc");
128 printf(", auth spi: 0x%08x", EXTRACT_32BITS(&bp
[i
+ 2]));
131 if (len
- i
< IP6OPT_MINLEN
) {
132 printf(", sopt_type %d: trunc)", bp
[i
]);
135 printf(", sopt_type 0x%02x: len=%d", bp
[i
], bp
[i
+ 1]);
146 ip6_opt_print(const u_char
*bp
, int len
)
151 for (i
= 0; i
< len
; i
+= optlen
) {
152 if (bp
[i
] == IP6OPT_PAD1
)
156 optlen
= bp
[i
+ 1] + 2;
160 if (i
+ optlen
> len
)
168 if (len
- i
< IP6OPT_MINLEN
) {
169 printf("(padn: trunc)");
174 case IP6OPT_ROUTER_ALERT
:
175 if (len
- i
< IP6OPT_RTALERT_LEN
) {
176 printf("(rtalert: trunc)");
179 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
180 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
183 printf("(rtalert: 0x%04x) ", EXTRACT_16BITS(&bp
[i
+ 2]));
186 if (len
- i
< IP6OPT_JUMBO_LEN
) {
187 printf("(jumbo: trunc)");
190 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
191 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
194 printf("(jumbo: %u) ", EXTRACT_32BITS(&bp
[i
+ 2]));
196 case IP6OPT_HOME_ADDRESS
:
197 if (len
- i
< IP6OPT_HOMEADDR_MINLEN
) {
198 printf("(homeaddr: trunc)");
201 if (bp
[i
+ 1] < IP6OPT_HOMEADDR_MINLEN
- 2) {
202 printf("(homeaddr: invalid len %d)", bp
[i
+ 1]);
205 printf("(homeaddr: %s", ip6addr_string(&bp
[i
+ 2]));
206 if (bp
[i
+ 1] > IP6OPT_HOMEADDR_MINLEN
- 2) {
207 ip6_sopt_print(&bp
[i
+ IP6OPT_HOMEADDR_MINLEN
],
208 (optlen
- IP6OPT_HOMEADDR_MINLEN
));
212 case IP6OPT_BINDING_UPDATE
:
213 if (len
- i
< IP6OPT_BU_MINLEN
) {
214 printf("(bu: trunc)");
217 if (bp
[i
+ 1] < IP6OPT_BU_MINLEN
- 2) {
218 printf("(bu: invalid len %d)", bp
[i
+ 1]);
222 if (bp
[i
+ 2] & 0x80)
224 if (bp
[i
+ 2] & 0x40)
226 if (bp
[i
+ 2] & 0x20)
228 if (bp
[i
+ 2] & 0x10)
230 if ((bp
[i
+ 2] & 0x0f) || bp
[i
+ 3] || bp
[i
+ 4])
232 printf(", sequence: %u", bp
[i
+ 5]);
233 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 6]));
235 if (bp
[i
+ 1] > IP6OPT_BU_MINLEN
- 2) {
236 ip6_sopt_print(&bp
[i
+ IP6OPT_BU_MINLEN
],
237 (optlen
- IP6OPT_BU_MINLEN
));
241 case IP6OPT_BINDING_ACK
:
242 if (len
- i
< IP6OPT_BA_MINLEN
) {
243 printf("(ba: trunc)");
246 if (bp
[i
+ 1] < IP6OPT_BA_MINLEN
- 2) {
247 printf("(ba: invalid len %d)", bp
[i
+ 1]);
251 printf("status: %u", bp
[i
+ 2]);
254 printf(", sequence: %u", bp
[i
+ 4]);
255 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 5]));
256 printf(", refresh: %u", EXTRACT_32BITS(&bp
[i
+ 9]));
258 if (bp
[i
+ 1] > IP6OPT_BA_MINLEN
- 2) {
259 ip6_sopt_print(&bp
[i
+ IP6OPT_BA_MINLEN
],
260 (optlen
- IP6OPT_BA_MINLEN
));
264 case IP6OPT_BINDING_REQ
:
265 if (len
- i
< IP6OPT_BR_MINLEN
) {
266 printf("(br: trunc)");
270 if (bp
[i
+ 1] > IP6OPT_BR_MINLEN
- 2) {
271 ip6_sopt_print(&bp
[i
+ IP6OPT_BR_MINLEN
],
272 (optlen
- IP6OPT_BR_MINLEN
));
277 if (len
- i
< IP6OPT_MINLEN
) {
278 printf("(type %d: trunc)", bp
[i
]);
281 printf("(opt_type 0x%02x: len=%d) ", bp
[i
], bp
[i
+ 1]);
296 hbhopt_print(register const u_char
*bp
)
298 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
301 TCHECK(dp
->ip6h_len
);
302 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
303 TCHECK2(*dp
, hbhlen
);
306 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
311 fputs("[|HBH]", stdout
);
316 dstopt_print(register const u_char
*bp
)
318 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
321 TCHECK(dp
->ip6d_len
);
322 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
323 TCHECK2(*dp
, dstoptlen
);
326 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
327 dstoptlen
- sizeof(*dp
));
333 fputs("[|DSTOPT]", stdout
);