summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2000-01-16 11:20:15 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2000-01-16 11:20:15 +0000
commit8864887c13971cbce8835d4e5a74294d0de7c8fa (patch)
tree34bdaf6bf6843839309fe2d3394bff124646b419 /usr.sbin
parente0ad2399cfb10bb4b9903e44ee7db3953cb11eec (diff)
Mobile IP support (from KAME/NetBSD)
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tcpdump/Makefile4
-rw-r--r--usr.sbin/tcpdump/interface.h3
-rw-r--r--usr.sbin/tcpdump/print-ip.c17
-rw-r--r--usr.sbin/tcpdump/print-mobile.c142
4 files changed, 162 insertions, 4 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile
index f80c97d819a..93a52797540 100644
--- a/usr.sbin/tcpdump/Makefile
+++ b/usr.sbin/tcpdump/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.17 2000/01/16 10:54:58 jakob Exp $
+# $OpenBSD: Makefile,v 1.18 2000/01/16 11:20:14 jakob Exp $
#
# Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
# The Regents of the University of California. All rights reserved.
@@ -41,7 +41,7 @@ SRCS= tcpdump.c addrtoname.c \
print-atm.c print-dvmrp.c print-krb.c print-pim.c print-netbios.c \
util.c bpf_dump.c parsenfsfh.c version.c machdep.c print-igrp.c \
print-gre.c print-radius.c print-enc.c print-cnfp.c \
- print-ipsec.c print-ike.c print-raw.c print-l2tp.c \
+ print-ipsec.c print-ike.c print-raw.c print-l2tp.c print-mobile.c \
gmt2local.c savestr.c setsignal.c
AWKS = atime.awk packetdat.awk send-ack.awk stime.awk
diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h
index 8dd191a33dd..b188707786b 100644
--- a/usr.sbin/tcpdump/interface.h
+++ b/usr.sbin/tcpdump/interface.h
@@ -18,7 +18,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.13 2000/01/16 10:54:58 jakob Exp $ (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.14 2000/01/16 11:20:14 jakob Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
@@ -196,6 +196,7 @@ extern void ns_print(const u_char *, u_int);
extern void ntp_print(const u_char *, u_int);
extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
extern void ospf_print(const u_char *, u_int, const u_char *);
+extern void mobile_print(const u_char *, u_int);
extern void pim_print(const u_char *, u_int);
extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
extern void raw_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c
index fa16f49a21a..f7fa0f230b9 100644
--- a/usr.sbin/tcpdump/print-ip.c
+++ b/usr.sbin/tcpdump/print-ip.c
@@ -21,7 +21,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.8 1999/10/06 01:46:40 deraadt Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.9 2000/01/16 11:20:14 jakob Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -486,6 +486,21 @@ ip_print(register const u_char *bp, register u_int length)
ah_print(cp, len, (const u_char *)ip);
break;
+#ifndef IPPROTO_MOBILE
+#define IPPROTO_MOBILE 55
+#endif
+ case IPPROTO_MOBILE:
+ if (vflag)
+ (void)printf("mobile %s > %s: ",
+ ipaddr_string(&ip->ip_src),
+ ipaddr_string(&ip->ip_dst));
+ mobile_print(cp, len);
+ if (! vflag) {
+ printf(" (mobile encap)");
+ return;
+ }
+ break;
+
default:
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
diff --git a/usr.sbin/tcpdump/print-mobile.c b/usr.sbin/tcpdump/print-mobile.c
new file mode 100644
index 00000000000..33b35e7a268
--- /dev/null
+++ b/usr.sbin/tcpdump/print-mobile.c
@@ -0,0 +1,142 @@
+/* $OpenBSD: print-mobile.c,v 1.1 2000/01/16 11:20:14 jakob Exp $ */
+/* $NetBSD: print-mobile.c,v 1.3 1999/07/26 06:11:57 itojun Exp $ */
+
+/*
+ * (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Heiko W.Rupp <hwr@pilhuhn.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: print-mobile.c,v 1.3 1999/07/26 06:11:57 itojun Exp $");
+#endif
+#endif
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+
+#include <netdb.h>
+#include <stdio.h>
+
+#include "interface.h"
+#include "addrtoname.h"
+#include "extract.h" /* must come after interface.h */
+
+#define MOBILE_SIZE (8)
+
+struct mobile_ip {
+ u_int16_t proto;
+ u_int16_t hcheck;
+ u_int32_t odst;
+ u_int32_t osrc;
+};
+
+#define OSRC_PRES 0x0080 /* old source is present */
+
+static u_int16_t mob_in_cksum(u_short *p, int len);
+
+/*
+ * Deencapsulate and print a mobile-tunneled IP datagram
+ */
+void
+mobile_print(const u_char *bp, u_int length)
+{
+ const u_char *cp = bp +8 ;
+ const struct mobile_ip *mob;
+ u_short proto,crc;
+ u_char osp =0; /* old source address present */
+
+ mob = (const struct mobile_ip *)bp;
+
+ if (length < MOBILE_SIZE) {
+ fputs("[|mobile]", stdout);
+ return;
+ }
+
+ proto = EXTRACT_16BITS(&mob->proto);
+ crc = EXTRACT_16BITS(&mob->hcheck);
+ if (proto & OSRC_PRES) {
+ osp=1;
+ cp +=4 ;
+ }
+
+ if (osp) {
+ fputs("[S] ",stdout);
+ if (vflag)
+ (void)printf("%s ",ipaddr_string(&mob->osrc));
+ } else {
+ fputs("[] ",stdout);
+ }
+ if (vflag) {
+ (void)printf("> %s ",ipaddr_string(&mob->odst));
+ (void)printf("(oproto=%d)",proto>>8);
+ }
+ if (mob_in_cksum((u_short *)mob, osp ? 12 : 8)!=0) {
+ (void)printf(" (bad checksum %d)",crc);
+ }
+
+ return;
+}
+
+static u_int16_t mob_in_cksum(u_short *p, int len)
+{
+ u_int32_t sum = 0;
+ int nwords = len >> 1;
+
+ while (nwords-- != 0)
+ sum += *p++;
+
+ if (len & 1) {
+ union {
+ u_int16_t w;
+ u_int32_t c[2];
+ } u;
+ u.c[0] = *(u_char *)p;
+ u.c[1] = 0;
+ sum += u.w;
+ }
+
+ /* end-around-carry */
+ sum = (sum >> 16) + (sum & 0xffff);
+ sum += (sum >> 16);
+ return (~sum);
+}
+