111b3aaa1Schristos /* NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp */ 20f74e101Schristos 30f74e101Schristos /* 40f74e101Schristos * (c) 1998 The NetBSD Foundation, Inc. 50f74e101Schristos * All rights reserved. 60f74e101Schristos * 70f74e101Schristos * This code is derived from software contributed to The NetBSD Foundation 80f74e101Schristos * by Heiko W.Rupp <hwr@pilhuhn.de> 90f74e101Schristos * 100f74e101Schristos * Redistribution and use in source and binary forms, with or without 110f74e101Schristos * modification, are permitted provided that the following conditions 120f74e101Schristos * are met: 130f74e101Schristos * 1. Redistributions of source code must retain the above copyright 140f74e101Schristos * notice, this list of conditions and the following disclaimer. 150f74e101Schristos * 2. Redistributions in binary form must reproduce the above copyright 160f74e101Schristos * notice, this list of conditions and the following disclaimer in the 170f74e101Schristos * documentation and/or other materials provided with the distribution. 180f74e101Schristos * 3. All advertising materials mentioning features or use of this software 190f74e101Schristos * must display the following acknowledgement: 200f74e101Schristos * This product includes software developed by the NetBSD 210f74e101Schristos * Foundation, Inc. and its contributors. 220f74e101Schristos * 4. Neither the name of The NetBSD Foundation nor the names of its 230f74e101Schristos * contributors may be used to endorse or promote products derived 240f74e101Schristos * from this software without specific prior written permission. 250f74e101Schristos * 260f74e101Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 270f74e101Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 280f74e101Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 290f74e101Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 300f74e101Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 310f74e101Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 320f74e101Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 330f74e101Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 340f74e101Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 350f74e101Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 360f74e101Schristos * POSSIBILITY OF SUCH DAMAGE. 370f74e101Schristos */ 380f74e101Schristos 39b3a00663Schristos #include <sys/cdefs.h> 40b3a00663Schristos #ifndef lint 41*26ba0b50Schristos __RCSID("$NetBSD: print-mobile.c,v 1.8 2024/09/02 16:15:32 christos Exp $"); 42b3a00663Schristos #endif 43b3a00663Schristos 44dc860a36Sspz /* \summary: IPv4 mobility printer */ 45dc860a36Sspz 46c74ad251Schristos #include <config.h> 470f74e101Schristos 48c74ad251Schristos #include "netdissect-stdinc.h" 490f74e101Schristos 50fdccd7e4Schristos #include "netdissect.h" 510f74e101Schristos #include "addrtoname.h" 52fdccd7e4Schristos #include "extract.h" 530f74e101Schristos 540f74e101Schristos #define MOBILE_SIZE (8) 550f74e101Schristos 560f74e101Schristos struct mobile_ip { 57c74ad251Schristos nd_uint16_t proto; 58c74ad251Schristos nd_uint16_t hcheck; 59c74ad251Schristos nd_uint32_t odst; 60c74ad251Schristos nd_uint32_t osrc; 610f74e101Schristos }; 620f74e101Schristos 630f74e101Schristos #define OSRC_PRES 0x0080 /* old source is present */ 640f74e101Schristos 650f74e101Schristos /* 660f74e101Schristos * Deencapsulate and print a mobile-tunneled IP datagram 670f74e101Schristos */ 680f74e101Schristos void 69b3a00663Schristos mobile_print(netdissect_options *ndo, const u_char *bp, u_int length) 700f74e101Schristos { 710f74e101Schristos const struct mobile_ip *mob; 720e9868baSchristos struct cksum_vec vec[1]; 730f74e101Schristos u_short proto,crc; 740f74e101Schristos u_char osp =0; /* old source address present */ 750f74e101Schristos 76c74ad251Schristos ndo->ndo_protocol = "mobile"; 770f74e101Schristos mob = (const struct mobile_ip *)bp; 780f74e101Schristos 79c74ad251Schristos if (length < MOBILE_SIZE || !ND_TTEST_SIZE(mob)) { 80c74ad251Schristos nd_print_trunc(ndo); 810f74e101Schristos return; 820f74e101Schristos } 83c74ad251Schristos ND_PRINT("mobile: "); 840f74e101Schristos 85c74ad251Schristos proto = GET_BE_U_2(mob->proto); 86c74ad251Schristos crc = GET_BE_U_2(mob->hcheck); 870f74e101Schristos if (proto & OSRC_PRES) { 880f74e101Schristos osp=1; 890f74e101Schristos } 900f74e101Schristos 910f74e101Schristos if (osp) { 92c74ad251Schristos ND_PRINT("[S] "); 93b3a00663Schristos if (ndo->ndo_vflag) 94c74ad251Schristos ND_PRINT("%s ", GET_IPADDR_STRING(mob->osrc)); 950f74e101Schristos } else { 96c74ad251Schristos ND_PRINT("[] "); 970f74e101Schristos } 98b3a00663Schristos if (ndo->ndo_vflag) { 99c74ad251Schristos ND_PRINT("> %s ", GET_IPADDR_STRING(mob->odst)); 100c74ad251Schristos ND_PRINT("(oproto=%u)", proto>>8); 1010f74e101Schristos } 102fdccd7e4Schristos vec[0].ptr = (const uint8_t *)(const void *)mob; 1030e9868baSchristos vec[0].len = osp ? 12 : 8; 1040e9868baSchristos if (in_cksum(vec, 1)!=0) { 105c74ad251Schristos ND_PRINT(" (bad checksum %u)", crc); 1060f74e101Schristos } 1070f74e101Schristos } 108