]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ip6opts.c
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 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
45 /* items outside of rfc2292bis */
47 #define IP6OPT_MINLEN 2
49 #ifndef IP6OPT_RTALERT_LEN
50 #define IP6OPT_RTALERT_LEN 4
52 #ifndef IP6OPT_JUMBO_LEN
53 #define IP6OPT_JUMBO_LEN 6
55 #define IP6OPT_HOMEADDR_MINLEN 18
56 #define IP6OPT_BU_MINLEN 10
57 #define IP6OPT_BA_MINLEN 13
58 #define IP6OPT_BR_MINLEN 2
59 #define IP6SOPT_UI 0x2
60 #define IP6SOPT_UI_MINLEN 4
61 #define IP6SOPT_ALTCOA 0x3
62 #define IP6SOPT_ALTCOA_MINLEN 18
63 #define IP6SOPT_AUTH 0x4
64 #define IP6SOPT_AUTH_MINLEN 6
66 static void ip6_sopt_print(const u_char
*, int);
69 ip6_sopt_print(const u_char
*bp
, int len
)
74 for (i
= 0; i
< len
; i
+= optlen
) {
75 if (bp
[i
] == IP6OPT_PAD1
)
79 optlen
= bp
[i
+ 1] + 2;
91 if (len
- i
< IP6OPT_MINLEN
) {
92 printf(", padn: trunc");
98 if (len
- i
< IP6SOPT_UI_MINLEN
) {
99 printf(", ui: trunc");
102 printf(", ui: 0x%04x ", EXTRACT_16BITS(&bp
[i
+ 2]));
105 if (len
- i
< IP6SOPT_ALTCOA_MINLEN
) {
106 printf(", altcoa: trunc");
109 printf(", alt-CoA: %s", ip6addr_string(&bp
[i
+2]));
112 if (len
- i
< IP6SOPT_AUTH_MINLEN
) {
113 printf(", auth: trunc");
116 printf(", auth spi: 0x%08x", EXTRACT_32BITS(&bp
[i
+ 2]));
119 if (len
- i
< IP6OPT_MINLEN
) {
120 printf(", sopt_type %d: trunc)", bp
[i
]);
123 printf(", sopt_type 0x%02x: len=%d", bp
[i
], bp
[i
+ 1]);
134 ip6_opt_print(const u_char
*bp
, int len
)
141 for (i
= 0; i
< len
; i
+= optlen
) {
142 if (bp
[i
] == IP6OPT_PAD1
)
146 optlen
= bp
[i
+ 1] + 2;
150 if (i
+ optlen
> len
)
158 if (len
- i
< IP6OPT_MINLEN
) {
159 printf("(padn: trunc)");
164 case IP6OPT_ROUTER_ALERT
:
165 if (len
- i
< IP6OPT_RTALERT_LEN
) {
166 printf("(rtalert: trunc)");
169 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
170 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
173 printf("(rtalert: 0x%04x) ", EXTRACT_16BITS(&bp
[i
+ 2]));
176 if (len
- i
< IP6OPT_JUMBO_LEN
) {
177 printf("(jumbo: trunc)");
180 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
181 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
184 printf("(jumbo: %u) ", EXTRACT_32BITS(&bp
[i
+ 2]));
186 case IP6OPT_HOME_ADDRESS
:
187 if (len
- i
< IP6OPT_HOMEADDR_MINLEN
) {
188 printf("(homeaddr: trunc)");
191 if (bp
[i
+ 1] < IP6OPT_HOMEADDR_MINLEN
- 2) {
192 printf("(homeaddr: invalid len %d)", bp
[i
+ 1]);
195 printf("(homeaddr: %s", ip6addr_string(&bp
[i
+ 2]));
196 if (bp
[i
+ 1] > IP6OPT_HOMEADDR_MINLEN
- 2) {
197 ip6_sopt_print(&bp
[i
+ IP6OPT_HOMEADDR_MINLEN
],
198 (optlen
- IP6OPT_HOMEADDR_MINLEN
));
202 case IP6OPT_BINDING_UPDATE
:
203 if (len
- i
< IP6OPT_BU_MINLEN
) {
204 printf("(bu: trunc)");
207 if (bp
[i
+ 1] < IP6OPT_BU_MINLEN
- 2) {
208 printf("(bu: invalid len %d)", bp
[i
+ 1]);
212 if (bp
[i
+ 2] & 0x80)
214 if (bp
[i
+ 2] & 0x40)
216 if (bp
[i
+ 2] & 0x20)
218 if (bp
[i
+ 2] & 0x10)
220 if ((bp
[i
+ 2] & 0x0f) || bp
[i
+ 3] || bp
[i
+ 4])
222 printf(", sequence: %u", bp
[i
+ 5]);
223 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 6]));
225 if (bp
[i
+ 1] > IP6OPT_BU_MINLEN
- 2) {
226 ip6_sopt_print(&bp
[i
+ IP6OPT_BU_MINLEN
],
227 (optlen
- IP6OPT_BU_MINLEN
));
231 case IP6OPT_BINDING_ACK
:
232 if (len
- i
< IP6OPT_BA_MINLEN
) {
233 printf("(ba: trunc)");
236 if (bp
[i
+ 1] < IP6OPT_BA_MINLEN
- 2) {
237 printf("(ba: invalid len %d)", bp
[i
+ 1]);
241 printf("status: %u", bp
[i
+ 2]);
244 printf(", sequence: %u", bp
[i
+ 4]);
245 printf(", lifetime: %u", EXTRACT_32BITS(&bp
[i
+ 5]));
246 printf(", refresh: %u", EXTRACT_32BITS(&bp
[i
+ 9]));
248 if (bp
[i
+ 1] > IP6OPT_BA_MINLEN
- 2) {
249 ip6_sopt_print(&bp
[i
+ IP6OPT_BA_MINLEN
],
250 (optlen
- IP6OPT_BA_MINLEN
));
254 case IP6OPT_BINDING_REQ
:
255 if (len
- i
< IP6OPT_BR_MINLEN
) {
256 printf("(br: trunc)");
260 if (bp
[i
+ 1] > IP6OPT_BR_MINLEN
- 2) {
261 ip6_sopt_print(&bp
[i
+ IP6OPT_BR_MINLEN
],
262 (optlen
- IP6OPT_BR_MINLEN
));
267 if (len
- i
< IP6OPT_MINLEN
) {
268 printf("(type %d: trunc)", bp
[i
]);
271 printf("(opt_type 0x%02x: len=%d)", bp
[i
], bp
[i
+ 1]);
287 hbhopt_print(register const u_char
*bp
)
289 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
292 TCHECK(dp
->ip6h_len
);
293 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
294 TCHECK2(*dp
, hbhlen
);
297 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
302 fputs("[|HBH]", stdout
);
307 dstopt_print(register const u_char
*bp
)
309 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
312 TCHECK(dp
->ip6d_len
);
313 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
314 TCHECK2(*dp
, dstoptlen
);
317 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
318 dstoptlen
- sizeof(*dp
));
324 fputs("[|DSTOPT]", stdout
);