]>
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.1 2002-06-27 08:22:41 guy 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 #if BYTE_ORDER == BIG_ENDIAN
73 #define IP6M_BINDING_REQUEST 0x0000 /* Binding Refresh Request */
74 #define IP6M_HOME_TEST_INIT 0x0001 /* Home Test Init */
75 #define IP6M_CAREOF_TEST_INIT 0x0002 /* Care-of Test Init */
76 #define IP6M_HOME_TEST 0x0003 /* Home Test */
77 #define IP6M_CAREOF_TEST 0x0004 /* Care-of Test */
78 #define IP6M_BINDING_UPDATE 0x0005 /* Binding Update */
79 #define IP6M_BINDING_ACK 0x0006 /* Binding Acknowledgement */
80 #define IP6M_BINDING_ERROR 0x0007 /* Binding Error */
81 #else /* BYTE_ORDER == LITTLE_ENDIAN */
82 #define IP6M_BINDING_REQUEST 0x0000 /* Binding Refresh Request */
83 #define IP6M_HOME_TEST_INIT 0x0100 /* Home Test Init */
84 #define IP6M_CAREOF_TEST_INIT 0x0200 /* Care-of Test Init */
85 #define IP6M_HOME_TEST 0x0300 /* Home Test */
86 #define IP6M_CAREOF_TEST 0x0400 /* Care-of Test */
87 #define IP6M_BINDING_UPDATE 0x0500 /* Binding Update */
88 #define IP6M_BINDING_ACK 0x0600 /* Binding Acknowledgement */
89 #define IP6M_BINDING_ERROR 0x0700 /* Binding Error */
90 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
92 /* Mobility Header Options */
93 #define IP6MOPT_MINLEN 2
94 #define IP6MOPT_PAD1 0x0
95 #define IP6MOPT_PADN 0x1
96 #define IP6MOPT_UI 0x2
97 #define IP6MOPT_UI_MINLEN 4
98 #define IP6MOPT_ALTCOA 0x3
99 #define IP6MOPT_ALTCOA_MINLEN 18
100 #define IP6MOPT_NONCEID 0x4
101 #define IP6MOPT_NONCEID_MINLEN 6
102 #define IP6MOPT_AUTH 0x5
103 #define IP6MOPT_AUTH_MINLEN 2 /* 2+len */
106 mobility_opt_print(const u_char
*bp
, int len
)
111 for (i
= 0; i
< len
; i
+= optlen
) {
112 if (bp
[i
] == IP6MOPT_PAD1
)
119 if (optlen
< IP6MOPT_MINLEN
)
120 optlen
= IP6MOPT_MINLEN
; /* XXX */
122 if (i
+ optlen
> len
)
130 if (len
- i
< IP6MOPT_MINLEN
) {
131 printf("(padn: trunc)");
137 if (len
- i
< IP6MOPT_UI_MINLEN
) {
138 printf("(ui: trunc)");
141 printf("(ui: 0x%04x)", ntohs(*(u_int16_t
*)&bp
[i
+ 2]));
144 if (len
- i
< IP6MOPT_ALTCOA_MINLEN
) {
145 printf("(altcoa: trunc)");
148 printf("(alt-CoA: %s)", ip6addr_string(&bp
[i
+2]));
150 case IP6MOPT_NONCEID
:
151 if (len
- i
< IP6MOPT_NONCEID_MINLEN
) {
152 printf("(ni: trunc)");
155 printf("(ni: ho=0x%04x ci=0x%04x)",
156 ntohs(*(u_int16_t
*)&bp
[i
+ 2]),
157 ntohs(*(u_int16_t
*)&bp
[i
+ 4]));
160 if (len
- i
< IP6MOPT_AUTH_MINLEN
) {
161 printf("(auth: trunc)");
164 printf("(auth spi: 0x%08x)",
165 (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 2]));
168 if (len
- i
< IP6MOPT_MINLEN
) {
169 printf("(sopt_type %d: trunc)", bp
[i
]);
172 printf("(type-0x%02x: len=%d)", bp
[i
], bp
[i
+ 1]);
186 mobility_print(const u_char
*bp
, const u_char
*bp2
)
188 const struct ip6_mobility
*mh
;
189 const struct ip6_hdr
*ip6
;
193 mh
= (struct ip6_mobility
*)bp
;
194 ip6
= (struct ip6_hdr
*)bp2
;
196 /* 'ep' points to the end of available data. */
199 TCHECK(mh
->ip6m_len
);
200 mhlen
= (int)(mh
->ip6m_len
<< 3);
201 if (mhlen
< IP6M_MINLEN
)
202 mhlen
= IP6M_MINLEN
; /* XXX */
206 TCHECK(mh
->ip6m_type
);
207 switch (mh
->ip6m_type
) {
208 case IP6M_BINDING_REQUEST
:
209 printf("mobility: BRR");
212 case IP6M_HOME_TEST_INIT
:
213 case IP6M_CAREOF_TEST_INIT
:
214 printf("mobility: %soTI",
215 mh
->ip6m_type
== IP6M_HOME_TEST_INIT
? "H" : "C");
217 TCHECK2(*mh
, hlen
+ 4);
218 printf(" cookie=0x%x", ntohl(*(u_int32_t
*)&bp
[hlen
]));
222 case IP6M_CAREOF_TEST
:
223 printf("mobility: %soT",
224 mh
->ip6m_type
== IP6M_HOME_TEST
? "H" : "C");
226 TCHECK2(*mh
, hlen
+ 2);
227 printf(" nonce id=0x%x", ntohs(*(u_int16_t
*)&bp
[hlen
]));
229 /* Reserved (16bits) */
231 TCHECK2(*mh
, hlen
+ 4);
232 printf(" mobile cookie=0x%x", ntohl(*(u_int32_t
*)&bp
[hlen
]));
234 /* Home(Care-of) Cookie (128 bits) */
237 case IP6M_BINDING_UPDATE
:
238 printf("mobility: BU");
239 TCHECK(mh
->ip6m_data8
[0]);
240 if (mh
->ip6m_data8
[0] & 0xf0)
242 if (mh
->ip6m_data8
[0] & 0x80)
244 if (mh
->ip6m_data8
[0] & 0x40)
246 if (mh
->ip6m_data8
[0] & 0x20)
248 if (mh
->ip6m_data8
[0] & 0x10)
251 TCHECK2(*mh
, hlen
+ 2);
252 printf(" seq#=%d", ntohs(*(u_int16_t
*)&bp
[hlen
]));
254 /* Reserved (16bits) */
256 TCHECK2(*mh
, hlen
+ 4);
257 printf(" lifetime=%d", ntohl(*(u_int32_t
*)&bp
[hlen
]));
259 TCHECK2(*mh
, hlen
+ 16);
260 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
263 case IP6M_BINDING_ACK
:
264 printf("mobility: BA");
265 TCHECK(mh
->ip6m_data8
[0]);
266 printf(" status=%d", mh
->ip6m_data8
[0]);
268 TCHECK2(*mh
, hlen
+ 2);
269 printf(" seq#=%d", ntohs(*(u_int16_t
*)&bp
[hlen
]));
271 /* Reserved (16bits) */
273 TCHECK2(*mh
, hlen
+ 4);
274 printf(" lifetime=%d", ntohl(*(u_int32_t
*)&bp
[hlen
]));
276 TCHECK2(*mh
, hlen
+ 4);
277 printf(" refresh=%d", ntohl(*(u_int32_t
*)&bp
[hlen
]));
280 case IP6M_BINDING_ERROR
:
281 printf("mobility: BE");
282 TCHECK(mh
->ip6m_data8
[0]);
283 printf(" status=%d", mh
->ip6m_data8
[0]);
285 TCHECK2(*mh
, hlen
+ 16);
286 printf(" homeaddr %s", ip6addr_string(&bp
[hlen
]));
290 printf("mobility: type-#%d len=%d", ntohs(mh
->ip6m_type
),
296 mobility_opt_print(&bp
[hlen
], mhlen
- hlen
);
301 fputs("[|MOBILITY]", stdout
);