2 * Copyright (C) 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char rcsid
[] _U_
=
36 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.17.2.1 2005/04/20 22:19:06 guy Exp $";
40 #include <tcpdump-stdinc.h>
46 #include "interface.h"
47 #include "addrtoname.h"
50 /* items outside of rfc2292bis */
52 #define IP6OPT_MINLEN 2
54 #ifndef IP6OPT_RTALERT_LEN
55 #define IP6OPT_RTALERT_LEN 4
57 #ifndef IP6OPT_JUMBO_LEN
58 #define IP6OPT_JUMBO_LEN 6
60 #define IP6OPT_HOMEADDR_MINLEN 18
61 #define IP6OPT_BU_MINLEN 10
62 #define IP6OPT_BA_MINLEN 13
63 #define IP6OPT_BR_MINLEN 2
64 #define IP6SOPT_UI 0x2
65 #define IP6SOPT_UI_MINLEN 4
66 #define IP6SOPT_ALTCOA 0x3
67 #define IP6SOPT_ALTCOA_MINLEN 18
68 #define IP6SOPT_AUTH 0x4
69 #define IP6SOPT_AUTH_MINLEN 6
71 static void ip6_sopt_print(const u_char
*, int);
74 ip6_sopt_print(const u_char
*bp
, int len
)
79 for (i
= 0; i
< len
; i
+= optlen
) {
80 if (bp
[i
] == IP6OPT_PAD1
)
84 optlen
= bp
[i
+ 1] + 2;
96 if (len
- i
< IP6OPT_MINLEN
) {
97 printf(", padn: trunc");
103 if (len
- i
< IP6SOPT_UI_MINLEN
) {
104 printf(", ui: trunc");
107 printf(", ui: 0x%04x ", EXTRACT_16BITS(&bp
[i
+ 2]));
110 if (len
- i
< IP6SOPT_ALTCOA_MINLEN
) {
111 printf(", altcoa: trunc");
114 printf(", alt-CoA: %s", ip6addr_string(&bp
[i
+2]));
117 if (len
- i
< IP6SOPT_AUTH_MINLEN
) {
118 printf(", auth: trunc");
121 printf(", auth spi: 0x%08x", EXTRACT_32BITS(&bp
[i
+ 2]));
124 if (len
- i
< IP6OPT_MINLEN
) {
125 printf(", sopt_type %d: trunc)", bp
[i
]);
128 printf(", sopt_type 0x%02x: len=%d", bp
[i
], bp
[i
+ 1]);
139 ip6_opt_print(const u_char
*bp
, int len
)
144 for (i
= 0; i
< len
; i
+= optlen
) {
145 if (bp
[i
] == IP6OPT_PAD1
)
149 optlen
= bp
[i
+ 1] + 2;
153 if (i
+ optlen
> len
)
161 if (len
- i
< IP6OPT_MINLEN
) {
162 printf("(padn: trunc)");
167 case IP6OPT_ROUTER_ALERT
:
168 if (len
- i
< IP6OPT_RTALERT_LEN
) {
169 printf("(rtalert: trunc)");
172 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
173 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
176 printf("(rtalert: 0x%04x) ", EXTRACT_16BITS(&bp
[i
+ 2]));
179 if (len
- i
< IP6OPT_JUMBO_LEN
) {
180 printf("(jumbo: trunc)");
183 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
184 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
187 printf("(jumbo: %u) ", EXTRACT_32BITS(&bp
[i
+ 2]));
189 case IP6OPT_HOME_ADDRESS
:
190 if (len
- i
< IP6OPT_HOMEADDR_MINLEN
) {
191 printf("(homeaddr: trunc)");
194 if (bp
[i
+ 1] < IP6OPT_HOMEADDR_MINLEN
- 2) {
195 printf("(homeaddr: invalid len %d)", bp
[i
+ 1]);
198 printf("(homeaddr: %s", ip6addr_string(&bp
[i
+ 2]));
199 if (bp
[i
+ 1] > IP6OPT_HOMEADDR_MINLEN
- 2) {
200 ip6_sopt_print(&bp
[i
+ IP6OPT_HOMEADDR_MINLEN
],
201 (optlen
- IP6OPT_HOMEADDR_MINLEN
));
205 case IP6OPT_BINDING_UPDATE
:
206 if (len
- i
< IP6OPT_BU_MINLEN
) {
207 printf("(bu: trunc)");
210 if (bp
[i
+ 1] < IP6OPT_BU_MINLEN
- 2) {
211 printf("(bu: invalid len %d)", bp
[i
+ 1]);
215 if (bp
[i
+ 2] & 0x80)
217 if (bp
[i
+ 2] & 0x40)
219 if (bp
[i
+ 2] & 0x20)
221 if (bp
[i
+ 2] & 0x10)
223 if ((bp
[i
+ 2] & 0x0f) || bp
[i
+ 3] || bp
[i
+ 4])
225 printf(", sequence: %u", bp
[i
+ 5]);
226 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 6]));
228 if (bp
[i
+ 1] > IP6OPT_BU_MINLEN
- 2) {
229 ip6_sopt_print(&bp
[i
+ IP6OPT_BU_MINLEN
],
230 (optlen
- IP6OPT_BU_MINLEN
));
234 case IP6OPT_BINDING_ACK
:
235 if (len
- i
< IP6OPT_BA_MINLEN
) {
236 printf("(ba: trunc)");
239 if (bp
[i
+ 1] < IP6OPT_BA_MINLEN
- 2) {
240 printf("(ba: invalid len %d)", bp
[i
+ 1]);
244 printf("status: %u", bp
[i
+ 2]);
247 printf(", sequence: %u", bp
[i
+ 4]);
248 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 5]));
249 printf(", refresh: %u", EXTRACT_32BITS(&bp
[i
+ 9]));
251 if (bp
[i
+ 1] > IP6OPT_BA_MINLEN
- 2) {
252 ip6_sopt_print(&bp
[i
+ IP6OPT_BA_MINLEN
],
253 (optlen
- IP6OPT_BA_MINLEN
));
257 case IP6OPT_BINDING_REQ
:
258 if (len
- i
< IP6OPT_BR_MINLEN
) {
259 printf("(br: trunc)");
263 if (bp
[i
+ 1] > IP6OPT_BR_MINLEN
- 2) {
264 ip6_sopt_print(&bp
[i
+ IP6OPT_BR_MINLEN
],
265 (optlen
- IP6OPT_BR_MINLEN
));
270 if (len
- i
< IP6OPT_MINLEN
) {
271 printf("(type %d: trunc)", bp
[i
]);
274 printf("(opt_type 0x%02x: len=%d) ", bp
[i
], bp
[i
+ 1]);
289 hbhopt_print(register const u_char
*bp
)
291 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
294 TCHECK(dp
->ip6h_len
);
295 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
296 TCHECK2(*dp
, hbhlen
);
299 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
304 fputs("[|HBH]", stdout
);
309 dstopt_print(register const u_char
*bp
)
311 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
314 TCHECK(dp
->ip6d_len
);
315 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
316 TCHECK2(*dp
, dstoptlen
);
319 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
320 dstoptlen
- sizeof(*dp
));
326 fputs("[|DSTOPT]", stdout
);