summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjmg <jmg@FreeBSD.org>2004-09-28 18:40:18 +0000
committerjmg <jmg@FreeBSD.org>2004-09-28 18:40:18 +0000
commit0d1f936e786e73bd039b6c59438d854bdbe9be0c (patch)
tree1f81477be87de6e5071e81d84c523f851be8d253 /sys
parent2f2f7359cc2aba3a3344e8b341e920fdcb52a1e1 (diff)
downloadFreeBSD-src-0d1f936e786e73bd039b6c59438d854bdbe9be0c.zip
FreeBSD-src-0d1f936e786e73bd039b6c59438d854bdbe9be0c.tar.gz
improve the mbuf m_print function.. Only pull length from pkthdr if there
is one, detect mbuf loops and stop, add an extra arg so you can only print the first x bytes of the data per mbuf (print all if arg is -1), print flags using %b (bitmask)... No code in the tree appears to use m_print, and it's just a maner of adding -1 as an additional arg to m_print to restore original behavior.. MFC after: 4 days
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/uipc_mbuf.c25
-rw-r--r--sys/sys/mbuf.h2
2 files changed, 21 insertions, 6 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index a1449d8..1c2e410 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -995,18 +995,33 @@ m_getptr(struct mbuf *m, int loc, int *off)
}
void
-m_print(const struct mbuf *m)
+m_print(const struct mbuf *m, int maxlen)
{
int len;
+ int pdata;
const struct mbuf *m2;
- len = m->m_pkthdr.len;
+ if (m->m_flags & M_PKTHDR)
+ len = m->m_pkthdr.len;
+ else
+ len = -1;
m2 = m;
- while (len) {
- printf("%p %*D\n", m2, m2->m_len, (u_char *)m2->m_data, "-");
- len -= m2->m_len;
+ while (m2 != NULL && (len == -1 || len)) {
+ pdata = m2->m_len;
+ if (maxlen != -1 && pdata > maxlen)
+ pdata = maxlen;
+ printf("mbuf: %p len: %d, next: %p, %b%s", m2, m2->m_len,
+ m2->m_next, m2->m_flags, "\20\20freelist\17skipfw"
+ "\11proto5\10proto4\7proto3\6proto2\5proto1\4rdonly"
+ "\3eor\2pkthdr\1ext", pdata ? "" : "\n");
+ if (pdata)
+ printf(", %*D\n", m2->m_len, (u_char *)m2->m_data, "-");
+ if (len != -1)
+ len -= m2->m_len;
m2 = m2->m_next;
}
+ if (len > 0)
+ printf("%d bytes unaccounted for.\n", len);
return;
}
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 0c65b8e..78053e9 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -556,7 +556,7 @@ struct mbuf *m_getptr(struct mbuf *, int, int *);
u_int m_length(struct mbuf *, struct mbuf **);
void m_move_pkthdr(struct mbuf *, struct mbuf *);
struct mbuf *m_prepend(struct mbuf *, int, int);
-void m_print(const struct mbuf *);
+void m_print(const struct mbuf *, int);
struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
struct mbuf *m_pullup(struct mbuf *, int);
struct mbuf *m_split(struct mbuf *, int, int);
OpenPOWER on IntegriCloud