]>
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.2 2002-07-08 08:58:37 fenner Exp $";
40 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
45 #include <netinet/in.h>
50 #include "interface.h"
51 #include "addrtoname.h"
52 #include "extract.h" /* must come after interface.h */
56 u_int8_t ip6m_pproto
; /* following payload protocol (for PG) */
57 u_int8_t ip6m_len
; /* length in units of 8 octets */
58 u_int16_t ip6m_type
; /* message type */
59 u_int16_t ip6m_cksum
; /* sum of IPv6 pseudo-header and MH */
61 u_int16_t ip6m_un_data16
[1]; /* type-specific field */
62 u_int8_t ip6m_un_data8
[2]; /* type-specific fiedl */
66 #define ip6m_data16 ip6m_dataun.ip6m_un_data16
67 #define ip6m_data8 ip6m_dataun.ip6m_un_data8
72 #define IP6M_BINDING_REQUEST 0x0000 /* Binding Refresh Request */
73 #define IP6M_HOME_TEST_INIT 0x0001 /* Home Test Init */
74 #define IP6M_CAREOF_TEST_INIT 0x0002 /* Care-of Test Init */
75 #define IP6M_HOME_TEST 0x0003 /* Home Test */
76 #define IP6M_CAREOF_TEST 0x0004 /* Care-of Test */
77 #define IP6M_BINDING_UPDATE 0x0005 /* Binding Update */
78 #define IP6M_BINDING_ACK 0x0006 /* Binding Acknowledgement */
79 #define IP6M_BINDING_ERROR 0x0007 /* Binding Error */
81 /* Mobility Header Options */
82 #define IP6MOPT_MINLEN 2
83 #define IP6MOPT_PAD1 0x0
84 #define IP6MOPT_PADN 0x1
85 #define IP6MOPT_UI 0x2
86 #define IP6MOPT_UI_MINLEN 4
87 #define IP6MOPT_ALTCOA 0x3
88 #define IP6MOPT_ALTCOA_MINLEN 18
89 #define IP6MOPT_NONCEID 0x4
90 #define IP6MOPT_NONCEID_MINLEN 6
91 #define IP6MOPT_AUTH 0x5
92 #define IP6MOPT_AUTH_MINLEN 2 /* 2+len */
95 mobility_opt_print(const u_char
*bp
, int len
)
100 for (i
= 0; i
< len
; i
+= optlen
) {
101 if (bp
[i
] == IP6MOPT_PAD1
)
108 if (optlen
< IP6MOPT_MINLEN
)
109 optlen
= IP6MOPT_MINLEN
; /* XXX */
111 if (i
+ optlen
> len
)
119 if (len
- i
< IP6MOPT_MINLEN
) {
120 printf("(padn: trunc)");
126 if (len
- i
< IP6MOPT_UI_MINLEN
) {
127 printf("(ui: trunc)");
130 printf("(ui: 0x%04x)", EXTRACT_16BITS(&bp
[i
+2]));
133 if (len
- i
< IP6MOPT_ALTCOA_MINLEN
) {
134 printf("(altcoa: trunc)");
137 printf("(alt-CoA: %s)", ip6addr_string(&bp
[i
+2]));
139 case IP6MOPT_NONCEID
:
140 if (len
- i
< IP6MOPT_NONCEID_MINLEN
) {
141 printf("(ni: trunc)");
144 printf("(ni: ho=0x%04x ci=0x%04x)",
145 EXTRACT_16BITS(&bp
[i
+2]),
146 EXTRACT_16BITS(&bp
[i
+4]));
149 if (len
- i
< IP6MOPT_AUTH_MINLEN
) {
150 printf("(auth: trunc)");
153 printf("(auth spi: 0x%08x)",
154 EXTRACT_32BITS(&bp
[i
+2]));
157 if (len
- i
< IP6MOPT_MINLEN
) {
158 printf("(sopt_type %d: trunc)", bp
[i
]);
161 printf("(type-0x%02x: len=%d)", bp
[i
], bp
[i
+ 1]);
175 mobility_print(const u_char
*bp
, const u_char
*bp2
)
177 const struct ip6_mobility
*mh
;
178 const struct ip6_hdr
*ip6
;
180 int mhlen
, hlen
, type
;
182 mh
= (struct ip6_mobility
*)bp
;
183 ip6
= (struct ip6_hdr
*)bp2
;
185 /* 'ep' points to the end of available data. */
188 TCHECK(mh
->ip6m_len
);
189 mhlen
= (int)(mh
->ip6m_len
<< 3);
190 if (mhlen
< IP6M_MINLEN
)
191 mhlen
= IP6M_MINLEN
; /* XXX */
195 TCHECK(mh
->ip6m_type
);
196 type
= ntohs(mh
->ip6m_type
);
198 case IP6M_BINDING_REQUEST
:
199 printf("mobility: BRR");
202 case IP6M_HOME_TEST_INIT
:
203 case IP6M_CAREOF_TEST_INIT
:
204 printf("mobility: %soTI",
205 type
== IP6M_HOME_TEST_INIT
? "H" : "C");
207 TCHECK2(*mh
, hlen
+ 4);
208 printf(" cookie=0x%x", EXTRACT_32BITS(&bp
[hlen
]));
212 case IP6M_CAREOF_TEST
:
213 printf("mobility: %soT",
214 type
== IP6M_HOME_TEST
? "H" : "C");
216 TCHECK2(*mh
, hlen
+ 2);
217 printf(" nonce id=0x%x", EXTRACT_16BITS(&bp
[hlen
]));
219 /* Reserved (16bits) */
221 TCHECK2(*mh
, hlen
+ 4);
222 printf(" mobile cookie=0x%x", EXTRACT_32BITS(&bp
[hlen
]));
224 /* Home(Care-of) Cookie (128 bits) */
227 case IP6M_BINDING_UPDATE
:
228 printf("mobility: BU");
229 TCHECK(mh
->ip6m_data8
[0]);
230 if (mh
->ip6m_data8
[0] & 0xf0)
232 if (mh
->ip6m_data8
[0] & 0x80)
234 if (mh
->ip6m_data8
[0] & 0x40)
236 if (mh
->ip6m_data8
[0] & 0x20)
238 if (mh
->ip6m_data8
[0] & 0x10)
241 TCHECK2(*mh
, hlen
+ 2);
242 printf(" seq#=%d", EXTRACT_16BITS(&bp
[hlen
]));
244 /* Reserved (16bits) */
246 TCHECK2(*mh
, hlen
+ 4);
247 printf(" lifetime=%d", EXTRACT_32BITS(&bp
[hlen
]));
249 TCHECK2(*mh
, hlen
+ 16);
250 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
253 case IP6M_BINDING_ACK
:
254 printf("mobility: BA");
255 TCHECK(mh
->ip6m_data8
[0]);
256 printf(" status=%d", mh
->ip6m_data8
[0]);
258 TCHECK2(*mh
, hlen
+ 2);
259 printf(" seq#=%d", EXTRACT_16BITS(&bp
[hlen
]));
261 /* Reserved (16bits) */
263 TCHECK2(*mh
, hlen
+ 4);
264 printf(" lifetime=%d", EXTRACT_32BITS(&bp
[hlen
]));
266 TCHECK2(*mh
, hlen
+ 4);
267 printf(" refresh=%d", ntohl(*(u_int32_t
*)&bp
[hlen
]));
270 case IP6M_BINDING_ERROR
:
271 printf("mobility: BE");
272 TCHECK(mh
->ip6m_data8
[0]);
273 printf(" status=%d", mh
->ip6m_data8
[0]);
275 TCHECK2(*mh
, hlen
+ 16);
276 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
280 printf("mobility: type-#%d len=%d", type
, mh
->ip6m_len
);
285 mobility_opt_print(&bp
[hlen
], mhlen
- hlen
);
290 fputs("[|MOBILITY]", stdout
);