]>
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
35 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
47 u_int8_t ip6m_pproto
; /* following payload protocol (for PG) */
48 u_int8_t ip6m_len
; /* length in units of 8 octets */
49 u_int8_t ip6m_type
; /* message type */
50 u_int8_t reserved
; /* reserved */
51 u_int16_t ip6m_cksum
; /* sum of IPv6 pseudo-header and MH */
53 u_int16_t ip6m_un_data16
[1]; /* type-specific field */
54 u_int8_t ip6m_un_data8
[2]; /* type-specific fiedl */
58 #define ip6m_data16 ip6m_dataun.ip6m_un_data16
59 #define ip6m_data8 ip6m_dataun.ip6m_un_data8
63 /* http://www.iana.org/assignments/mobility-parameters/mobility-parameters.xhtml */
66 #define IP6M_BINDING_REQUEST 0 /* Binding Refresh Request */
67 #define IP6M_HOME_TEST_INIT 1 /* Home Test Init */
68 #define IP6M_CAREOF_TEST_INIT 2 /* Care-of Test Init */
69 #define IP6M_HOME_TEST 3 /* Home Test */
70 #define IP6M_CAREOF_TEST 4 /* Care-of Test */
71 #define IP6M_BINDING_UPDATE 5 /* Binding Update */
72 #define IP6M_BINDING_ACK 6 /* Binding Acknowledgement */
73 #define IP6M_BINDING_ERROR 7 /* Binding Error */
76 #define IP6MOPT_BU_MINLEN 10
77 #define IP6MOPT_BA_MINLEN 13
78 #define IP6MOPT_BR_MINLEN 2
80 /* Mobility Header Options */
81 #define IP6MOPT_MINLEN 2
82 #define IP6MOPT_PAD1 0x0 /* Pad1 */
83 #define IP6MOPT_PADN 0x1 /* PadN */
84 #define IP6MOPT_REFRESH 0x2 /* Binding Refresh Advice */
85 #define IP6MOPT_REFRESH_MINLEN 4
86 #define IP6MOPT_ALTCOA 0x3 /* Alternate Care-of Address */
87 #define IP6MOPT_ALTCOA_MINLEN 18
88 #define IP6MOPT_NONCEID 0x4 /* Nonce Indices */
89 #define IP6MOPT_NONCEID_MINLEN 6
90 #define IP6MOPT_AUTH 0x5 /* Binding Authorization Data */
91 #define IP6MOPT_AUTH_MINLEN 12
94 mobility_opt_print(const u_char
*bp
, const unsigned len
)
98 for (i
= 0; i
< len
; i
+= optlen
) {
99 if (bp
[i
] == IP6MOPT_PAD1
)
103 optlen
= bp
[i
+ 1] + 2;
107 if (i
+ optlen
> len
)
115 if (len
- i
< IP6MOPT_MINLEN
) {
116 printf("(padn: trunc)");
121 case IP6MOPT_REFRESH
:
122 if (len
- i
< IP6MOPT_REFRESH_MINLEN
) {
123 printf("(refresh: trunc)");
126 /* units of 4 secs */
127 printf("(refresh: %u)",
128 EXTRACT_16BITS(&bp
[i
+2]) << 2);
131 if (len
- i
< IP6MOPT_ALTCOA_MINLEN
) {
132 printf("(altcoa: trunc)");
135 printf("(alt-CoA: %s)", ip6addr_string(&bp
[i
+2]));
137 case IP6MOPT_NONCEID
:
138 if (len
- i
< IP6MOPT_NONCEID_MINLEN
) {
139 printf("(ni: trunc)");
142 printf("(ni: ho=0x%04x co=0x%04x)",
143 EXTRACT_16BITS(&bp
[i
+2]),
144 EXTRACT_16BITS(&bp
[i
+4]));
147 if (len
- i
< IP6MOPT_AUTH_MINLEN
) {
148 printf("(auth: trunc)");
154 if (len
- i
< IP6MOPT_MINLEN
) {
155 printf("(sopt_type %u: trunc)", bp
[i
]);
158 printf("(type-0x%02x: len=%u)", bp
[i
], bp
[i
+ 1]);
172 mobility_print(const u_char
*bp
, const u_char
*bp2 _U_
)
174 const struct ip6_mobility
*mh
;
176 unsigned mhlen
, hlen
;
179 mh
= (struct ip6_mobility
*)bp
;
181 /* 'ep' points to the end of available data. */
184 if (!TTEST(mh
->ip6m_len
)) {
186 * There's not enough captured data to include the
187 * mobility header length.
189 * Our caller expects us to return the length, however,
190 * so return a value that will run to the end of the
193 * XXX - "ip6_print()" doesn't do anything with the
194 * returned length, however, as it breaks out of the
195 * header-processing loop.
200 mhlen
= (mh
->ip6m_len
+ 1) << 3;
204 TCHECK(mh
->ip6m_type
);
205 type
= mh
->ip6m_type
;
207 case IP6M_BINDING_REQUEST
:
208 printf("mobility: BRR");
211 case IP6M_HOME_TEST_INIT
:
212 case IP6M_CAREOF_TEST_INIT
:
213 printf("mobility: %soTI",
214 type
== IP6M_HOME_TEST_INIT
? "H" : "C");
217 TCHECK2(*mh
, hlen
+ 8);
218 printf(" %s Init Cookie=%08x:%08x",
219 type
== IP6M_HOME_TEST_INIT
? "Home" : "Care-of",
220 EXTRACT_32BITS(&bp
[hlen
]),
221 EXTRACT_32BITS(&bp
[hlen
+ 4]));
226 case IP6M_CAREOF_TEST
:
227 printf("mobility: %soT",
228 type
== IP6M_HOME_TEST
? "H" : "C");
229 TCHECK(mh
->ip6m_data16
[0]);
230 printf(" nonce id=0x%x", EXTRACT_16BITS(&mh
->ip6m_data16
[0]));
233 TCHECK2(*mh
, hlen
+ 8);
234 printf(" %s Init Cookie=%08x:%08x",
235 type
== IP6M_HOME_TEST
? "Home" : "Care-of",
236 EXTRACT_32BITS(&bp
[hlen
]),
237 EXTRACT_32BITS(&bp
[hlen
+ 4]));
241 TCHECK2(*mh
, hlen
+ 8);
242 printf(" %s Keygen Token=%08x:%08x",
243 type
== IP6M_HOME_TEST
? "Home" : "Care-of",
244 EXTRACT_32BITS(&bp
[hlen
]),
245 EXTRACT_32BITS(&bp
[hlen
+ 4]));
249 case IP6M_BINDING_UPDATE
:
250 printf("mobility: BU");
251 TCHECK(mh
->ip6m_data16
[0]);
252 printf(" seq#=%u", EXTRACT_16BITS(&mh
->ip6m_data16
[0]));
254 TCHECK2(*mh
, hlen
+ 1);
265 /* Reserved (4bits) */
267 /* Reserved (8bits) */
269 TCHECK2(*mh
, hlen
+ 2);
270 /* units of 4 secs */
271 printf(" lifetime=%u", EXTRACT_16BITS(&bp
[hlen
]) << 2);
274 case IP6M_BINDING_ACK
:
275 printf("mobility: BA");
276 TCHECK(mh
->ip6m_data8
[0]);
277 printf(" status=%u", mh
->ip6m_data8
[0]);
278 if (mh
->ip6m_data8
[1] & 0x80)
280 /* Reserved (7bits) */
282 TCHECK2(*mh
, hlen
+ 2);
283 printf(" seq#=%u", EXTRACT_16BITS(&bp
[hlen
]));
285 TCHECK2(*mh
, hlen
+ 2);
286 /* units of 4 secs */
287 printf(" lifetime=%u", EXTRACT_16BITS(&bp
[hlen
]) << 2);
290 case IP6M_BINDING_ERROR
:
291 printf("mobility: BE");
292 TCHECK(mh
->ip6m_data8
[0]);
293 printf(" status=%u", mh
->ip6m_data8
[0]);
296 TCHECK2(*mh
, hlen
+ 16);
297 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
301 printf("mobility: type-#%u len=%u", type
, mh
->ip6m_len
);
306 mobility_opt_print(&bp
[hlen
], mhlen
- hlen
);
311 fputs("[|MOBILITY]", stdout
);