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