- 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
This commit is contained in:
parent
4212d42b89
commit
9a1c9345c3
|
@ -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_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;
|
||||
|
@ -157,18 +133,18 @@ m_peek_len(const struct mbuf *m, const char *modif)
|
|||
{
|
||||
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, int off, const char *modif,
|
|||
|
||||
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, int off, const char *modif,
|
|||
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, int off, const char *modif,
|
|||
|
||||
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, int off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
}
|
||||
(*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 off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
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, int off, const char *modif,
|
|||
|
||||
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, int off, const char *modif,
|
|||
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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
(*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 off, const char *modif,
|
|||
|
||||
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 off, const char *modif,
|
|||
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 *, ...))
|
||||
{
|
||||
|
|
|
@ -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 char *, void (*)(const char *, ...)
|
|||
__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.
|
||||
|
|
Loading…
Reference in New Issue