Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Print TCP options. Some of them are not decoded yet (e...



details:   https://anonhg.NetBSD.org/src/rev/a3f9565d4eac
branches:  trunk
changeset: 993944:a3f9565d4eac
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Oct 12 05:49:38 2018 +0000

description:
- 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

diffstat:

 sys/kern/uipc_mbufdebug.c |  176 ++++++++++++++++++++++++++++++++-------------
 sys/sys/mbuf.h            |   30 +++++++-
 2 files changed, 150 insertions(+), 56 deletions(-)

diffs (truncated from 417 to 300 lines):

diff -r 83a1e00f6ab0 -r a3f9565d4eac sys/kern/uipc_mbufdebug.c
--- a/sys/kern/uipc_mbufdebug.c Fri Oct 12 05:41:18 2018 +0000
+++ b/sys/kern/uipc_mbufdebug.c Fri Oct 12 05:49:38 2018 +0000
@@ -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_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 @@
 {
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        }
        (*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 @@
                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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
                (*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;



Home | Main Index | Thread Index | Old Index