Module Name: src
Committed By: msaitoh
Date: Fri Oct 12 05:49:38 UTC 2018
Modified Files:
src/sys/kern: uipc_mbufdebug.c
src/sys/sys: mbuf.h
Log Message:
- Print TCP options. Some of them are not decoded yet (e.g. SACK).
- Print IP checksum and TCP checksum.
- When a packet length is shorter than a required size of the protocol, print
both sizes.
- Make m_examine_xxx() functions global.
- Use bool instead of boolean_t.
- s/TRUE/true/, s/FALSE/false/
- KNF
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/kern/uipc_mbufdebug.c
cvs rdiff -u -r1.210 -r1.211 src/sys/sys/mbuf.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/uipc_mbufdebug.c
diff -u src/sys/kern/uipc_mbufdebug.c:1.5 src/sys/kern/uipc_mbufdebug.c:1.6
--- src/sys/kern/uipc_mbufdebug.c:1.5 Thu Oct 11 11:17:07 2018
+++ src/sys/kern/uipc_mbufdebug.c Fri Oct 12 05:49:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbufdebug.c,v 1.5 2018/10/11 11:17:07 msaitoh Exp $ */
+/* $NetBSD: uipc_mbufdebug.c,v 1.6 2018/10/12 05:49:38 msaitoh Exp $ */
/*
* Copyright (C) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbufdebug.c,v 1.5 2018/10/11 11:17:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbufdebug.c,v 1.6 2018/10/12 05:49:38 msaitoh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -63,30 +63,6 @@ static char *str_ipaddr(const struct in_
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;
@@ -157,18 +133,18 @@ m_peek_len(const struct mbuf *m, const c
{
const struct mbuf *m0;
unsigned int pktlen;
- boolean_t opt_c = FALSE;
+ bool opt_c = false;
unsigned char ch;
- while ( modif && (ch = *(modif++)) != '\0') {
+ while (modif && (ch = *(modif++)) != '\0') {
switch (ch) {
case 'c':
- opt_c = TRUE;
+ opt_c = true;
break;
}
}
- if (opt_c == TRUE) {
+ if (opt_c == true) {
return m->m_len;
}
@@ -242,7 +218,7 @@ str_ipproto(const uint8_t proto)
return NULL;
}
-static void
+void
m_examine_ether(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -251,7 +227,8 @@ m_examine_ether(const struct mbuf *m, in
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(eh)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(eh));
return m_examine_hex(m, off, modif, pr);
}
@@ -290,7 +267,7 @@ m_examine_ether(const struct mbuf *m, in
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_pppoe(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -301,7 +278,8 @@ m_examine_pppoe(const struct mbuf *m, in
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(ph)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u, %u)\n", __func__,
+ pktlen, sizeof(ph));
return m_examine_hex(m, off, modif, pr);
}
@@ -371,7 +349,7 @@ m_examine_pppoe(const struct mbuf *m, in
return m_examine_ppp(m, off, modif, pr);
}
-static void
+void
m_examine_ppp(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -381,7 +359,8 @@ m_examine_ppp(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(h)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(h));
return m_examine_hex(m, off, modif, pr);
}
@@ -462,7 +441,7 @@ m_examine_ppp(const struct mbuf *m, int
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_arp(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -474,7 +453,8 @@ m_examine_arp(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(ar)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(ar));
return m_examine_hex(m, off, modif, pr);
}
@@ -561,7 +541,7 @@ m_examine_arp(const struct mbuf *m, int
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_ip(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -571,7 +551,8 @@ m_examine_ip(const struct mbuf *m, int o
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(ip)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(ip));
return m_examine_hex(m, off, modif, pr);
}
@@ -602,6 +583,7 @@ m_examine_ip(const struct mbuf *m, int o
}
(*pr)("IP: TTL = %u\n", ip.ip_ttl);
(*pr)("IP: protocol = %u(%s)\n", ip.ip_p, str_ipproto(ip.ip_p));
+ (*pr)("IP: checksum = 0x%04x\n", ntohs(ip.ip_sum));
(*pr)("IP: Src = %s\n", str_ipaddr(&ip.ip_src));
(*pr)("IP: Dst = %s\n", str_ipaddr(&ip.ip_dst));
@@ -620,11 +602,10 @@ m_examine_ip(const struct mbuf *m, int o
break;
}
-
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_icmp(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -633,7 +614,8 @@ m_examine_icmp(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(icmphdr)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(icmphdr));
return m_examine_hex(m, off, modif, pr);
}
@@ -669,7 +651,7 @@ m_examine_icmp(const struct mbuf *m, int
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_ip6(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -683,7 +665,8 @@ m_examine_ip6(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(ip6)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(ip6));
return m_examine_hex(m, off, modif, pr);
}
@@ -735,7 +718,7 @@ m_examine_ip6(const struct mbuf *m, int
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_icmp6(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -744,7 +727,8 @@ m_examine_icmp6(const struct mbuf *m, in
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(icmp6)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(icmp6));
return m_examine_hex(m, off, modif, pr);
}
@@ -810,7 +794,7 @@ m_examine_icmp6(const struct mbuf *m, in
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_tcp(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -819,7 +803,8 @@ m_examine_tcp(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(tcp)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(tcp));
return m_examine_hex(m, off, modif, pr);
}
@@ -853,12 +838,96 @@ m_examine_tcp(const struct mbuf *m, int
(*pr)("\n");
}
(*pr)("TCP: Windows Size = %u\n", ntohs(tcp.th_win));
+ (*pr)("TCP: checksum = 0x%04x\n", ntohs(tcp.th_sum));
(*pr)("TCP: Urgent Pointer = %u\n", ntohs(tcp.th_urp));
- return m_examine_hex(m, off, modif, pr);
+ int len;
+ len = (tcp.th_off << 2) - sizeof(struct tcphdr);
+ if (len > 0) {
+ uint8_t *bufp, *op, opt, optlen;
+
+ bufp = malloc(len, M_TEMP, M_DONTWAIT);
+ if ((bufp == NULL) || (m_peek_data(m, off, len, bufp) < 0)) {
+ (*pr)("%s: cannot read TCP option\n", __func__);
+ if (bufp != NULL)
+ free(bufp, M_TEMP);
+ return m_examine_hex(m, off, modif, pr);
+ }
+ off += len;
+ op = bufp;
+
+ while (len > 0) {
+ opt = op[0];
+ if (opt == TCPOPT_EOL)
+ break;
+ if (opt == TCPOPT_NOP) {
+ (*pr)("TCP: OPTION: NOP\n");
+ op++;
+ len--;
+ continue;
+ }
+ if (opt == TCPOPT_PAD) {
+ (*pr)("TCP: OPTION: PAD\n");
+ op++;
+ len--;
+ continue;
+ }
+ optlen = op[1];
+ if (optlen == 0)
+ break;
+
+ if (opt == TCPOPT_MAXSEG && optlen == TCPOLEN_MAXSEG) {
+ uint16_t mss;
+
+ bcopy(op + 2, &mss, sizeof(mss));
+ (*pr)("TCP: OPTION: MSS = %d\n",
+ ntohs(mss));
+
+ op += optlen;
+ len -= optlen;
+ continue;
+ } else if (opt == TCPOPT_WINDOW
+ && optlen == TCPOLEN_WINDOW) {
+ (*pr)("TCP: OPTION: wscale = %d\n", op[2]);
+ op += optlen;
+ len -= optlen;
+ continue;
+ } else if (opt == TCPOPT_SACK_PERMITTED
+ && optlen == TCPOLEN_SACK_PERMITTED) {
+ (*pr)("TCP: OPTION: SACK OK\n");
+ op += optlen;
+ len -= optlen;
+ continue;
+ } else if (opt == TCPOPT_TIMESTAMP
+ && optlen == TCPOLEN_TIMESTAMP) {
+ uint32_t ts_val, ts_ecr;
+
+ memcpy(&ts_val, op + 2, sizeof(ts_val));
+ memcpy(&ts_ecr, op + 6, sizeof(ts_ecr));
+ (*pr)("TCP: OPTION: TIMESTAMP = %u, "
+ "ECR = %u\n",
+ ntohl(ts_val), ntohl(ts_ecr));
+ op += optlen;
+ len -= optlen;
+ continue;
+ } else {
+ (*pr)("TCP: OPTION: unknown (%d, len = %d)\n",
+ opt, optlen);
+ op += optlen;
+ len -= optlen;
+ continue;
+ }
+ }
+ free(bufp, M_TEMP);
+ }
+
+ if (off < pktlen)
+ m_examine_hex(m, off, modif, pr);
+
+ return;
}
-static void
+void
m_examine_udp(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
@@ -867,7 +936,8 @@ m_examine_udp(const struct mbuf *m, int
pktlen = m_peek_len(m, modif) - off;
if (pktlen < sizeof(udp)) {
- (*pr)("%s: too short mbuf chain\n", __func__);
+ (*pr)("%s: too short mbuf chain (%u < %u)\n", __func__,
+ pktlen, sizeof(udp));
return m_examine_hex(m, off, modif, pr);
}
@@ -884,7 +954,7 @@ m_examine_udp(const struct mbuf *m, int
return m_examine_hex(m, off, modif, pr);
}
-static void
+void
m_examine_hex(const struct mbuf *m, int off, const char *modif,
void (*pr)(const char *, ...))
{
Index: src/sys/sys/mbuf.h
diff -u src/sys/sys/mbuf.h:1.210 src/sys/sys/mbuf.h:1.211
--- src/sys/sys/mbuf.h:1.210 Wed Aug 22 01:05:24 2018
+++ src/sys/sys/mbuf.h Fri Oct 12 05:49:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.210 2018/08/22 01:05:24 msaitoh Exp $ */
+/* $NetBSD: mbuf.h,v 1.211 2018/10/12 05:49:38 msaitoh Exp $ */
/*
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -888,8 +888,32 @@ void m_print(const struct mbuf *, const
__printflike(1, 2));
/* from uipc_mbufdebug.c */
-void m_examine(const struct mbuf *, int, const char *, void (*)(const char *, ...)
- __printflike(1, 2));
+void m_examine(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+
+/* parsers for m_examine() */
+void m_examine_ether(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_pppoe(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_ppp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_arp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_ip(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_icmp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_ip6(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_icmp6(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_tcp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_udp(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
+void m_examine_hex(const struct mbuf *, int, const char *,
+ void (*)(const char *, ...) __printflike(1, 2));
/*
* Get rcvif of a mbuf.