]>
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 static const char rcsid
[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-mobility.c,v 1.5 2002-09-05 00:52:30 guy Exp $";
40 #include <tcpdump-stdinc.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
52 u_int8_t ip6m_pproto
; /* following payload protocol (for PG) */
53 u_int8_t ip6m_len
; /* length in units of 8 octets */
54 u_int16_t ip6m_type
; /* message type */
55 u_int16_t ip6m_cksum
; /* sum of IPv6 pseudo-header and MH */
57 u_int16_t ip6m_un_data16
[1]; /* type-specific field */
58 u_int8_t ip6m_un_data8
[2]; /* type-specific fiedl */
62 #define ip6m_data16 ip6m_dataun.ip6m_un_data16
63 #define ip6m_data8 ip6m_dataun.ip6m_un_data8
68 #define IP6M_BINDING_REQUEST 0x0000 /* Binding Refresh Request */
69 #define IP6M_HOME_TEST_INIT 0x0001 /* Home Test Init */
70 #define IP6M_CAREOF_TEST_INIT 0x0002 /* Care-of Test Init */
71 #define IP6M_HOME_TEST 0x0003 /* Home Test */
72 #define IP6M_CAREOF_TEST 0x0004 /* Care-of Test */
73 #define IP6M_BINDING_UPDATE 0x0005 /* Binding Update */
74 #define IP6M_BINDING_ACK 0x0006 /* Binding Acknowledgement */
75 #define IP6M_BINDING_ERROR 0x0007 /* Binding Error */
77 /* Mobility Header Options */
78 #define IP6MOPT_MINLEN 2
79 #define IP6MOPT_PAD1 0x0
80 #define IP6MOPT_PADN 0x1
81 #define IP6MOPT_UI 0x2
82 #define IP6MOPT_UI_MINLEN 4
83 #define IP6MOPT_ALTCOA 0x3
84 #define IP6MOPT_ALTCOA_MINLEN 18
85 #define IP6MOPT_NONCEID 0x4
86 #define IP6MOPT_NONCEID_MINLEN 6
87 #define IP6MOPT_AUTH 0x5
88 #define IP6MOPT_AUTH_MINLEN 2 /* 2+len */
89 #define IP6MOPT_REFRESH 0x7
90 #define IP6MOPT_REFRESH_MINLEN 4
93 mobility_opt_print(const u_char
*bp
, int 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)");
122 if (len
- i
< IP6MOPT_UI_MINLEN
) {
123 printf("(ui: trunc)");
126 printf("(ui: 0x%04x)", EXTRACT_16BITS(&bp
[i
+2]));
129 if (len
- i
< IP6MOPT_ALTCOA_MINLEN
) {
130 printf("(altcoa: trunc)");
133 printf("(alt-CoA: %s)", ip6addr_string(&bp
[i
+2]));
135 case IP6MOPT_NONCEID
:
136 if (len
- i
< IP6MOPT_NONCEID_MINLEN
) {
137 printf("(ni: trunc)");
140 printf("(ni: ho=0x%04x ci=0x%04x)",
141 EXTRACT_16BITS(&bp
[i
+2]),
142 EXTRACT_16BITS(&bp
[i
+4]));
145 if (len
- i
< IP6MOPT_AUTH_MINLEN
) {
146 printf("(auth: trunc)");
151 case IP6MOPT_REFRESH
:
152 if (len
- i
< IP6MOPT_REFRESH_MINLEN
) {
153 printf("(refresh: trunc)");
156 /* units of 4 secs */
157 printf("(refresh: %d)",
158 EXTRACT_16BITS(&bp
[i
+2]) << 2);
161 if (len
- i
< IP6MOPT_MINLEN
) {
162 printf("(sopt_type %d: trunc)", bp
[i
]);
165 printf("(type-0x%02x: len=%d)", bp
[i
], bp
[i
+ 1]);
179 mobility_print(const u_char
*bp
, const u_char
*bp2
)
181 const struct ip6_mobility
*mh
;
182 const struct ip6_hdr
*ip6
;
184 int mhlen
, hlen
, type
;
186 mh
= (struct ip6_mobility
*)bp
;
187 ip6
= (struct ip6_hdr
*)bp2
;
189 /* 'ep' points to the end of available data. */
192 if (!TTEST(mh
->ip6m_len
)) {
194 * There's not enough captured data to include the
195 * mobility header length.
197 * Our caller expects us to return the length, however,
198 * so return a value that will run to the end of the
201 * XXX - "ip6_print()" doesn't do anything with the
202 * returned length, however, as it breaks out of the
203 * header-processing loop.
208 mhlen
= (int)(mh
->ip6m_len
<< 3);
209 if (mhlen
< IP6M_MINLEN
)
210 mhlen
= IP6M_MINLEN
; /* XXX */
214 TCHECK(mh
->ip6m_type
);
215 type
= ntohs(mh
->ip6m_type
);
217 case IP6M_BINDING_REQUEST
:
218 printf("mobility: BRR");
221 case IP6M_HOME_TEST_INIT
:
222 case IP6M_CAREOF_TEST_INIT
:
223 printf("mobility: %soTI",
224 type
== IP6M_HOME_TEST_INIT
? "H" : "C");
227 TCHECK2(*mh
, hlen
+ 8);
228 printf(" %soT cookie=%08x:%08x",
229 type
== IP6M_HOME_TEST_INIT
? "H" : "C",
230 EXTRACT_32BITS(&bp
[hlen
]),
231 EXTRACT_32BITS(&bp
[hlen
+ 4]));
236 case IP6M_CAREOF_TEST
:
237 printf("mobility: %soT",
238 type
== IP6M_HOME_TEST
? "H" : "C");
239 TCHECK(mh
->ip6m_data16
[0]);
240 printf(" nonce id=0x%x", EXTRACT_16BITS(&mh
->ip6m_data16
[0]));
243 TCHECK2(*mh
, hlen
+ 8);
244 printf(" %soT cookie=%08x:%08x",
245 type
== IP6M_HOME_TEST
? "H" : "C",
246 EXTRACT_32BITS(&bp
[hlen
]),
247 EXTRACT_32BITS(&bp
[hlen
+ 4]));
251 TCHECK2(*mh
, hlen
+ 8);
252 printf(" %s cookie=%08x:%08x",
253 type
== IP6M_HOME_TEST
? "Home" : "Care-of",
254 EXTRACT_32BITS(&bp
[hlen
]),
255 EXTRACT_32BITS(&bp
[hlen
+ 4]));
259 case IP6M_BINDING_UPDATE
:
260 printf("mobility: BU");
261 TCHECK(mh
->ip6m_data16
[0]);
262 printf(" seq#=%d", EXTRACT_16BITS(&mh
->ip6m_data16
[0]));
264 TCHECK2(*mh
, hlen
+ 1);
277 /* Reserved (3bits) */
279 /* Reserved (8bits) */
281 TCHECK2(*mh
, hlen
+ 2);
282 /* units of 4 secs */
283 printf(" lifetime=%d", EXTRACT_16BITS(&bp
[hlen
]) << 2);
286 case IP6M_BINDING_ACK
:
287 printf("mobility: BA");
288 TCHECK(mh
->ip6m_data8
[0]);
289 printf(" status=%d", mh
->ip6m_data8
[0]);
291 TCHECK2(*mh
, hlen
+ 2);
292 printf(" seq#=%d", EXTRACT_16BITS(&bp
[hlen
]));
294 TCHECK2(*mh
, hlen
+ 2);
295 /* units of 4 secs */
296 printf(" lifetime=%d", EXTRACT_16BITS(&bp
[hlen
]) << 2);
299 case IP6M_BINDING_ERROR
:
300 printf("mobility: BE");
301 TCHECK(mh
->ip6m_data8
[0]);
302 printf(" status=%d", mh
->ip6m_data8
[0]);
304 TCHECK2(*mh
, hlen
+ 16);
305 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
309 printf("mobility: type-#%d len=%d", type
, mh
->ip6m_len
);
314 mobility_opt_print(&bp
[hlen
], mhlen
- hlen
);
319 fputs("[|MOBILITY]", stdout
);