]>
The Tcpdump Group git mirrors - tcpdump/blob - print-mobility.c
2 * Copyright (C) 2002 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
34 #include <netdissect-stdinc.h>
37 #include "netdissect.h"
38 #include "addrtoname.h"
43 uint8_t ip6m_pproto
; /* following payload protocol (for PG) */
44 uint8_t ip6m_len
; /* length in units of 8 octets */
45 uint8_t ip6m_type
; /* message type */
46 uint8_t reserved
; /* reserved */
47 uint16_t ip6m_cksum
; /* sum of IPv6 pseudo-header and MH */
49 uint16_t ip6m_un_data16
[1]; /* type-specific field */
50 uint8_t ip6m_un_data8
[2]; /* type-specific field */
54 #define ip6m_data16 ip6m_dataun.ip6m_un_data16
55 #define ip6m_data8 ip6m_dataun.ip6m_un_data8
59 /* http://www.iana.org/assignments/mobility-parameters/mobility-parameters.xhtml */
62 #define IP6M_BINDING_REQUEST 0 /* Binding Refresh Request */
63 #define IP6M_HOME_TEST_INIT 1 /* Home Test Init */
64 #define IP6M_CAREOF_TEST_INIT 2 /* Care-of Test Init */
65 #define IP6M_HOME_TEST 3 /* Home Test */
66 #define IP6M_CAREOF_TEST 4 /* Care-of Test */
67 #define IP6M_BINDING_UPDATE 5 /* Binding Update */
68 #define IP6M_BINDING_ACK 6 /* Binding Acknowledgement */
69 #define IP6M_BINDING_ERROR 7 /* Binding Error */
72 static const struct tok ip6m_str
[] = {
73 { IP6M_BINDING_REQUEST
, "BRR" },
74 { IP6M_HOME_TEST_INIT
, "HoTI" },
75 { IP6M_CAREOF_TEST_INIT
, "CoTI" },
76 { IP6M_HOME_TEST
, "HoT" },
77 { IP6M_CAREOF_TEST
, "CoT" },
78 { IP6M_BINDING_UPDATE
, "BU" },
79 { IP6M_BINDING_ACK
, "BA" },
80 { IP6M_BINDING_ERROR
, "BE" },
84 static const unsigned ip6m_hdrlen
[IP6M_MAX
+ 1] = {
85 IP6M_MINLEN
, /* IP6M_BINDING_REQUEST */
86 IP6M_MINLEN
+ 8, /* IP6M_HOME_TEST_INIT */
87 IP6M_MINLEN
+ 8, /* IP6M_CAREOF_TEST_INIT */
88 IP6M_MINLEN
+ 16, /* IP6M_HOME_TEST */
89 IP6M_MINLEN
+ 16, /* IP6M_CAREOF_TEST */
90 IP6M_MINLEN
+ 4, /* IP6M_BINDING_UPDATE */
91 IP6M_MINLEN
+ 4, /* IP6M_BINDING_ACK */
92 IP6M_MINLEN
+ 16, /* IP6M_BINDING_ERROR */
95 /* Mobility Header Options */
96 #define IP6MOPT_MINLEN 2
97 #define IP6MOPT_PAD1 0x0 /* Pad1 */
98 #define IP6MOPT_PADN 0x1 /* PadN */
99 #define IP6MOPT_REFRESH 0x2 /* Binding Refresh Advice */
100 #define IP6MOPT_REFRESH_MINLEN 4
101 #define IP6MOPT_ALTCOA 0x3 /* Alternate Care-of Address */
102 #define IP6MOPT_ALTCOA_MINLEN 18
103 #define IP6MOPT_NONCEID 0x4 /* Nonce Indices */
104 #define IP6MOPT_NONCEID_MINLEN 6
105 #define IP6MOPT_AUTH 0x5 /* Binding Authorization Data */
106 #define IP6MOPT_AUTH_MINLEN 12
109 mobility_opt_print(netdissect_options
*ndo
,
110 const u_char
*bp
, const unsigned len
)
114 for (i
= 0; i
< len
; i
+= optlen
) {
116 if (bp
[i
] == IP6MOPT_PAD1
)
120 ND_TCHECK(bp
[i
+ 1]);
121 optlen
= bp
[i
+ 1] + 2;
126 if (i
+ optlen
> len
)
128 ND_TCHECK(bp
[i
+ optlen
]);
132 ND_PRINT((ndo
, "(pad1)"));
135 if (len
- i
< IP6MOPT_MINLEN
) {
136 ND_PRINT((ndo
, "(padn: trunc)"));
139 ND_PRINT((ndo
, "(padn)"));
141 case IP6MOPT_REFRESH
:
142 if (len
- i
< IP6MOPT_REFRESH_MINLEN
) {
143 ND_PRINT((ndo
, "(refresh: trunc)"));
146 /* units of 4 secs */
147 ND_PRINT((ndo
, "(refresh: %u)",
148 EXTRACT_16BITS(&bp
[i
+2]) << 2));
151 if (len
- i
< IP6MOPT_ALTCOA_MINLEN
) {
152 ND_PRINT((ndo
, "(altcoa: trunc)"));
155 ND_PRINT((ndo
, "(alt-CoA: %s)", ip6addr_string(ndo
, &bp
[i
+2])));
157 case IP6MOPT_NONCEID
:
158 if (len
- i
< IP6MOPT_NONCEID_MINLEN
) {
159 ND_PRINT((ndo
, "(ni: trunc)"));
162 ND_PRINT((ndo
, "(ni: ho=0x%04x co=0x%04x)",
163 EXTRACT_16BITS(&bp
[i
+2]),
164 EXTRACT_16BITS(&bp
[i
+4])));
167 if (len
- i
< IP6MOPT_AUTH_MINLEN
) {
168 ND_PRINT((ndo
, "(auth: trunc)"));
171 ND_PRINT((ndo
, "(auth)"));
174 if (len
- i
< IP6MOPT_MINLEN
) {
175 ND_PRINT((ndo
, "(sopt_type %u: trunc)", bp
[i
]));
178 ND_PRINT((ndo
, "(type-0x%02x: len=%u)", bp
[i
], bp
[i
+ 1]));
185 ND_PRINT((ndo
, "[trunc] "));
192 mobility_print(netdissect_options
*ndo
,
193 const u_char
*bp
, const u_char
*bp2 _U_
)
195 const struct ip6_mobility
*mh
;
197 unsigned mhlen
, hlen
;
200 mh
= (const struct ip6_mobility
*)bp
;
202 /* 'ep' points to the end of available data. */
203 ep
= ndo
->ndo_snapend
;
205 if (!ND_TTEST(mh
->ip6m_len
)) {
207 * There's not enough captured data to include the
208 * mobility header length.
210 * Our caller expects us to return the length, however,
211 * so return a value that will run to the end of the
214 * XXX - "ip6_print()" doesn't do anything with the
215 * returned length, however, as it breaks out of the
216 * header-processing loop.
221 mhlen
= (mh
->ip6m_len
+ 1) << 3;
225 ND_TCHECK(mh
->ip6m_type
);
226 type
= mh
->ip6m_type
;
227 if (type
<= IP6M_MAX
&& mhlen
< ip6m_hdrlen
[type
]) {
228 ND_PRINT((ndo
, "(header length %u is too small for type %u)", mhlen
, type
));
231 ND_PRINT((ndo
, "mobility: %s", tok2str(ip6m_str
, "type-#%u", type
)));
233 case IP6M_BINDING_REQUEST
:
236 case IP6M_HOME_TEST_INIT
:
237 case IP6M_CAREOF_TEST_INIT
:
239 if (ndo
->ndo_vflag
) {
240 ND_TCHECK2(*mh
, hlen
+ 8);
241 ND_PRINT((ndo
, " %s Init Cookie=%08x:%08x",
242 type
== IP6M_HOME_TEST_INIT
? "Home" : "Care-of",
243 EXTRACT_32BITS(&bp
[hlen
]),
244 EXTRACT_32BITS(&bp
[hlen
+ 4])));
249 case IP6M_CAREOF_TEST
:
250 ND_TCHECK(mh
->ip6m_data16
[0]);
251 ND_PRINT((ndo
, " nonce id=0x%x", EXTRACT_16BITS(&mh
->ip6m_data16
[0])));
253 if (ndo
->ndo_vflag
) {
254 ND_TCHECK2(*mh
, hlen
+ 8);
255 ND_PRINT((ndo
, " %s Init Cookie=%08x:%08x",
256 type
== IP6M_HOME_TEST
? "Home" : "Care-of",
257 EXTRACT_32BITS(&bp
[hlen
]),
258 EXTRACT_32BITS(&bp
[hlen
+ 4])));
261 if (ndo
->ndo_vflag
) {
262 ND_TCHECK2(*mh
, hlen
+ 8);
263 ND_PRINT((ndo
, " %s Keygen Token=%08x:%08x",
264 type
== IP6M_HOME_TEST
? "Home" : "Care-of",
265 EXTRACT_32BITS(&bp
[hlen
]),
266 EXTRACT_32BITS(&bp
[hlen
+ 4])));
270 case IP6M_BINDING_UPDATE
:
271 ND_TCHECK(mh
->ip6m_data16
[0]);
272 ND_PRINT((ndo
, " seq#=%u", EXTRACT_16BITS(&mh
->ip6m_data16
[0])));
274 ND_TCHECK2(*mh
, hlen
+ 1);
276 ND_PRINT((ndo
, " "));
278 ND_PRINT((ndo
, "A"));
280 ND_PRINT((ndo
, "H"));
282 ND_PRINT((ndo
, "L"));
284 ND_PRINT((ndo
, "K"));
285 /* Reserved (4bits) */
287 /* Reserved (8bits) */
289 ND_TCHECK2(*mh
, hlen
+ 2);
290 /* units of 4 secs */
291 ND_PRINT((ndo
, " lifetime=%u", EXTRACT_16BITS(&bp
[hlen
]) << 2));
294 case IP6M_BINDING_ACK
:
295 ND_TCHECK(mh
->ip6m_data8
[0]);
296 ND_PRINT((ndo
, " status=%u", mh
->ip6m_data8
[0]));
297 if (mh
->ip6m_data8
[1] & 0x80)
298 ND_PRINT((ndo
, " K"));
299 /* Reserved (7bits) */
301 ND_TCHECK2(*mh
, hlen
+ 2);
302 ND_PRINT((ndo
, " seq#=%u", EXTRACT_16BITS(&bp
[hlen
])));
304 ND_TCHECK2(*mh
, hlen
+ 2);
305 /* units of 4 secs */
306 ND_PRINT((ndo
, " lifetime=%u", EXTRACT_16BITS(&bp
[hlen
]) << 2));
309 case IP6M_BINDING_ERROR
:
310 ND_TCHECK(mh
->ip6m_data8
[0]);
311 ND_PRINT((ndo
, " status=%u", mh
->ip6m_data8
[0]));
314 ND_TCHECK2(*mh
, hlen
+ 16);
315 ND_PRINT((ndo
, " homeaddr %s", ip6addr_string(ndo
, &bp
[hlen
])));
319 ND_PRINT((ndo
, " len=%u", mh
->ip6m_len
));
324 mobility_opt_print(ndo
, &bp
[hlen
], mhlen
- hlen
);
329 ND_PRINT((ndo
, "[|MOBILITY]"));