Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add /d(dump) and /v(verbose) modifiers to DDB's "show mbuf" ...
details: https://anonhg.NetBSD.org/src/rev/2aa8700c9177
branches: trunk
changeset: 320731:2aa8700c9177
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Tue Jul 17 05:52:07 2018 +0000
description:
Add /d(dump) and /v(verbose) modifiers to DDB's "show mbuf" command. Mainly
written by Hiroki SUENAGA. Currently, /v supports Ethernet, PPP, PPPoE, ARP,
IPv4, ICMP, IPv6, ICMPv6, TCP and UDP.
diffstat:
share/man/man4/ddb.4 | 20 +-
sys/kern/files.kern | 3 +-
sys/kern/uipc_mbuf.c | 36 +-
sys/kern/uipc_mbufdebug.c | 959 ++++++++++++++++++++++++++++++++++++++++++++++
sys/sys/mbuf.h | 6 +-
sys/sys/socket.h | 6 +-
6 files changed, 1017 insertions(+), 13 deletions(-)
diffs (truncated from 1152 to 300 lines):
diff -r bad5b3a4a318 -r 2aa8700c9177 share/man/man4/ddb.4
--- a/share/man/man4/ddb.4 Tue Jul 17 05:29:07 2018 +0000
+++ b/share/man/man4/ddb.4 Tue Jul 17 05:52:07 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ddb.4,v 1.178 2018/03/19 08:41:21 ozaki-r Exp $
+.\" $NetBSD: ddb.4,v 1.179 2018/07/17 05:52:07 msaitoh Exp $
.\"
.\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -56,7 +56,7 @@
.\" any improvements or extensions that they make and grant Carnegie Mellon
.\" the rights to redistribute these changes.
.\"
-.Dd March 19, 2018
+.Dd July 17, 2018
.Dt DDB 4
.Os
.Sh NAME
@@ -673,12 +673,20 @@
If
.Cm /f
is specified, the complete vnode list is printed.
-.It Ic show mbuf Ns Oo Cm /c Oc Ar address
+.It Ic show mbuf Ns Oo Cm /cdv Oc Ar address
Print the mbuf structure at
.Ar address .
-If
-.Cm /c
-is specified, the mbufs in the chain are followed.
+Valid modifiers:
+.Bl -tag -width 4n -compact
+.It Cm /c
+The mbufs in the chain are followed.
+.It Cm /d
+The data is dumped.
+.It Cm /v
+Decode the mbuf chain as a packet.
+It currently supports Ethernet, PPP, PPPoE, ARP, IPv4, ICMP, IPv6, ICMP6, TCP
+and UDP.
+.El
.It Ic show ncache Ar address
Dump the namecache list associated with vnode at
.Ar address .
diff -r bad5b3a4a318 -r 2aa8700c9177 sys/kern/files.kern
--- a/sys/kern/files.kern Tue Jul 17 05:29:07 2018 +0000
+++ b/sys/kern/files.kern Tue Jul 17 05:52:07 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.kern,v 1.18 2018/07/12 10:46:48 maxv Exp $
+# $NetBSD: files.kern,v 1.19 2018/07/17 05:52:07 msaitoh Exp $
#
# kernel sources
@@ -175,6 +175,7 @@
file kern/uipc_domain.c kern
file kern/uipc_mbuf.c kern
file kern/uipc_mbuf2.c kern
+file kern/uipc_mbufdebug.c kern
file net/link_proto.c kern # XXX
file kern/uipc_proto.c kern
file kern/uipc_sem.c kern
diff -r bad5b3a4a318 -r 2aa8700c9177 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Tue Jul 17 05:29:07 2018 +0000
+++ b/sys/kern/uipc_mbuf.c Tue Jul 17 05:52:07 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.215 2018/05/07 09:57:37 maxv Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.216 2018/07/17 05:52:07 msaitoh Exp $ */
/*
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.215 2018/05/07 09:57:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.216 2018/07/17 05:52:07 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@@ -1646,7 +1646,11 @@
m_print(const struct mbuf *m, const char *modif, void (*pr)(const char *, ...))
{
char ch;
+ const struct mbuf *m0 = NULL;
bool opt_c = false;
+ bool opt_d = false;
+ bool opt_v = false;
+ int no = 0;
char buf[512];
while ((ch = *(modif++)) != '\0') {
@@ -1654,14 +1658,35 @@
case 'c':
opt_c = true;
break;
+ case 'd':
+ opt_d = true;
+ break;
+ case 'v':
+ opt_v = true;
+ m0 = m;
+ break;
}
}
nextchain:
- (*pr)("MBUF %p\n", m);
+ (*pr)("MBUF(%d) %p\n", no, m);
snprintb(buf, sizeof(buf), M_FLAGS_BITS, (u_int)m->m_flags);
(*pr)(" data=%p, len=%d, type=%d, flags=%s\n",
m->m_data, m->m_len, m->m_type, buf);
+ if (opt_d) {
+ int i;
+ unsigned char *p = m->m_data;
+
+ (*pr)(" data:");
+
+ for (i = 0; i < m->m_len; i++) {
+ if (i % 16 == 0)
+ (*pr)("\n");
+ (*pr)(" %02x", p[i]);
+ }
+
+ (*pr)("\n");
+ }
(*pr)(" owner=%p, next=%p, nextpkt=%p\n", m->m_owner, m->m_next,
m->m_nextpkt);
(*pr)(" leadingspace=%u, trailingspace=%u, readonly=%u\n",
@@ -1697,9 +1722,14 @@
if (opt_c) {
m = m->m_next;
if (m != NULL) {
+ no++;
goto nextchain;
}
}
+
+ if (opt_v && m0) {
+ m_examine(m0, AF_ETHER, modif, pr);
+ }
}
#endif /* defined(DDB) */
diff -r bad5b3a4a318 -r 2aa8700c9177 sys/kern/uipc_mbufdebug.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/uipc_mbufdebug.c Tue Jul 17 05:52:07 2018 +0000
@@ -0,0 +1,959 @@
+/* $NetBSD: uipc_mbufdebug.c,v 1.1 2018/07/17 05:52:07 msaitoh Exp $ */
+
+/*
+ * Copyright (C) 2017 Internet Initiative Japan Inc.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$SEIL: uipc_mbufseil.c$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+
+#include <net/if.h>
+#include <net/if_ether.h>
+#include <net/ppp_defs.h>
+#include <net/if_arp.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+#include <netinet/if_inarp.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+
+#define EXAMINE_HEX_LIMIT 128
+#define EXAMINE_HEX_COL 4
+
+/* mbuf operations without change of mbuf chain */
+static int m_peek_data(const struct mbuf *, int, int, void *);
+static unsigned int m_peek_len(const struct mbuf *, const char *);
+
+/* utility */
+static char *str_ethaddr(const uint8_t *);
+static char *str_ipaddr(const struct in_addr *);
+static char *str_ip6addr(const struct in6_addr *);
+static const char *str_ipproto(const uint8_t);
+
+/* parsers for m_examine() */
+static void m_examine_ether(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_pppoe(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_ppp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_arp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_ip(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_icmp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_ip6(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_icmp6(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_tcp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_udp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+static void m_examine_hex(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...));
+
+/* header structure for some protocol */
+struct pppoehdr {
+ uint8_t vertype;
+ uint8_t code;
+ uint16_t session;
+ uint16_t plen;
+} __attribute__((__packed__));
+
+struct pppoetag {
+ uint16_t tag;
+ uint16_t len;
+} __attribute__((__packed__));
+
+#define PPPOE_TAG_EOL 0x0000
+#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
+#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
+#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
+#define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
+#define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
+
+struct ppp_header {
+ uint8_t address;
+ uint8_t control;
+ uint16_t protocol;
+} __attribute__((__packed__));
+
+#define CISCO_MULTICAST 0x8f /* Cisco multicast address */
+#define CISCO_UNICAST 0x0f /* Cisco unicast address */
+#define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
+
+#ifndef NELEMS
+#define NELEMS(elem) ((sizeof(elem))/(sizeof((elem)[0])))
+#endif
+
+static int
+m_peek_data(const struct mbuf *m, int off, int len, void *vp)
+{
+ unsigned int count;
+ char *cp = vp;
+
+ if (off < 0 || len < 0)
+ return -1;
+
+ while (off > 0) {
+ if (m == 0)
+ return -1;
+ if (off < m->m_len)
+ break;
+ off -= m->m_len;
+ m = m->m_next;
+ }
+ while (len > 0) {
+ if (m == 0)
+ return -1;
+ count = min(m->m_len - off, len);
+ memcpy(cp, mtod(m, char *) + off, count);
+ len -= count;
+ cp += count;
+ off = 0;
+ m = m->m_next;
+ }
+
+ return 0;
+}
+
Home |
Main Index |
Thread Index |
Old Index