xref: /freebsd/contrib/tcpdump/print-mobile.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
1b0453382SBill Fenner /*	$NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */
2b0453382SBill Fenner 
3b0453382SBill Fenner /*
4b0453382SBill Fenner  * (c) 1998 The NetBSD Foundation, Inc.
5b0453382SBill Fenner  * All rights reserved.
6b0453382SBill Fenner  *
7b0453382SBill Fenner  * This code is derived from software contributed to The NetBSD Foundation
8b0453382SBill Fenner  * by Heiko W.Rupp <hwr@pilhuhn.de>
9b0453382SBill Fenner  *
10b0453382SBill Fenner  * Redistribution and use in source and binary forms, with or without
11b0453382SBill Fenner  * modification, are permitted provided that the following conditions
12b0453382SBill Fenner  * are met:
13b0453382SBill Fenner  * 1. Redistributions of source code must retain the above copyright
14b0453382SBill Fenner  *    notice, this list of conditions and the following disclaimer.
15b0453382SBill Fenner  * 2. Redistributions in binary form must reproduce the above copyright
16b0453382SBill Fenner  *    notice, this list of conditions and the following disclaimer in the
17b0453382SBill Fenner  *    documentation and/or other materials provided with the distribution.
18b0453382SBill Fenner  * 3. All advertising materials mentioning features or use of this software
19b0453382SBill Fenner  *    must display the following acknowledgement:
20b0453382SBill Fenner  *        This product includes software developed by the NetBSD
21b0453382SBill Fenner  *        Foundation, Inc. and its contributors.
22b0453382SBill Fenner  * 4. Neither the name of The NetBSD Foundation nor the names of its
23b0453382SBill Fenner  *    contributors may be used to endorse or promote products derived
24b0453382SBill Fenner  *    from this software without specific prior written permission.
25b0453382SBill Fenner  *
26b0453382SBill Fenner  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27b0453382SBill Fenner  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28b0453382SBill Fenner  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29b0453382SBill Fenner  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30b0453382SBill Fenner  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31b0453382SBill Fenner  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32b0453382SBill Fenner  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33b0453382SBill Fenner  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34b0453382SBill Fenner  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35b0453382SBill Fenner  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36b0453382SBill Fenner  * POSSIBILITY OF SUCH DAMAGE.
37b0453382SBill Fenner  */
38b0453382SBill Fenner 
393340d773SGleb Smirnoff /* \summary: IPv4 mobility printer */
403340d773SGleb Smirnoff 
41*ee67461eSJoseph Mingrone #include <config.h>
42b0453382SBill Fenner 
43*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
44b0453382SBill Fenner 
453340d773SGleb Smirnoff #include "netdissect.h"
46b0453382SBill Fenner #include "addrtoname.h"
473340d773SGleb Smirnoff #include "extract.h"
48b0453382SBill Fenner 
49b0453382SBill Fenner #define MOBILE_SIZE (8)
50b0453382SBill Fenner 
51b0453382SBill Fenner struct mobile_ip {
52*ee67461eSJoseph Mingrone 	nd_uint16_t proto;
53*ee67461eSJoseph Mingrone 	nd_uint16_t hcheck;
54*ee67461eSJoseph Mingrone 	nd_uint32_t odst;
55*ee67461eSJoseph Mingrone 	nd_uint32_t osrc;
56b0453382SBill Fenner };
57b0453382SBill Fenner 
58b0453382SBill Fenner #define OSRC_PRES	0x0080	/* old source is present */
59b0453382SBill Fenner 
60b0453382SBill Fenner /*
61b0453382SBill Fenner  * Deencapsulate and print a mobile-tunneled IP datagram
62b0453382SBill Fenner  */
63b0453382SBill Fenner void
mobile_print(netdissect_options * ndo,const u_char * bp,u_int length)643c602fabSXin LI mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
65b0453382SBill Fenner {
66b0453382SBill Fenner 	const struct mobile_ip *mob;
67cac3dcd5SXin LI 	struct cksum_vec vec[1];
68b0453382SBill Fenner 	u_short proto,crc;
69b0453382SBill Fenner 	u_char osp =0;			/* old source address present */
70b0453382SBill Fenner 
71*ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "mobile";
72b0453382SBill Fenner 	mob = (const struct mobile_ip *)bp;
73b0453382SBill Fenner 
74*ee67461eSJoseph Mingrone 	if (length < MOBILE_SIZE || !ND_TTEST_SIZE(mob)) {
75*ee67461eSJoseph Mingrone 		nd_print_trunc(ndo);
76b0453382SBill Fenner 		return;
77b0453382SBill Fenner 	}
78*ee67461eSJoseph Mingrone 	ND_PRINT("mobile: ");
79b0453382SBill Fenner 
80*ee67461eSJoseph Mingrone 	proto = GET_BE_U_2(mob->proto);
81*ee67461eSJoseph Mingrone 	crc =  GET_BE_U_2(mob->hcheck);
82b0453382SBill Fenner 	if (proto & OSRC_PRES) {
83b0453382SBill Fenner 		osp=1;
84b0453382SBill Fenner 	}
85b0453382SBill Fenner 
86b0453382SBill Fenner 	if (osp)  {
87*ee67461eSJoseph Mingrone 		ND_PRINT("[S] ");
883c602fabSXin LI 		if (ndo->ndo_vflag)
89*ee67461eSJoseph Mingrone 			ND_PRINT("%s ", GET_IPADDR_STRING(mob->osrc));
90b0453382SBill Fenner 	} else {
91*ee67461eSJoseph Mingrone 		ND_PRINT("[] ");
92b0453382SBill Fenner 	}
933c602fabSXin LI 	if (ndo->ndo_vflag) {
94*ee67461eSJoseph Mingrone 		ND_PRINT("> %s ", GET_IPADDR_STRING(mob->odst));
95*ee67461eSJoseph Mingrone 		ND_PRINT("(oproto=%u)", proto>>8);
96b0453382SBill Fenner 	}
973340d773SGleb Smirnoff 	vec[0].ptr = (const uint8_t *)(const void *)mob;
98cac3dcd5SXin LI 	vec[0].len = osp ? 12 : 8;
99cac3dcd5SXin LI 	if (in_cksum(vec, 1)!=0) {
100*ee67461eSJoseph Mingrone 		ND_PRINT(" (bad checksum %u)", crc);
101b0453382SBill Fenner 	}
102b0453382SBill Fenner }
103