svn commit: r243377 - in user/andre/tcp_workqueue/sys: kern sys

Andre Oppermann andre at FreeBSD.org
Wed Nov 21 19:57:58 UTC 2012


Author: andre
Date: Wed Nov 21 19:57:57 2012
New Revision: 243377
URL: http://svnweb.freebsd.org/changeset/base/243377

Log:
  Extend m_print() to inform about all aspects of an mbuf,
  its header, external storage, packet header, m_tags and
  offloading features.
  
  A function callback is provided for protocols to also
  print parsed mbuf data contents.
  
  Add bit definition for various mbuf related flags for %b
  printing.

Modified:
  user/andre/tcp_workqueue/sys/kern/uipc_mbuf.c
  user/andre/tcp_workqueue/sys/sys/mbuf.h

Modified: user/andre/tcp_workqueue/sys/kern/uipc_mbuf.c
==============================================================================
--- user/andre/tcp_workqueue/sys/kern/uipc_mbuf.c	Wed Nov 21 18:38:56 2012	(r243376)
+++ user/andre/tcp_workqueue/sys/kern/uipc_mbuf.c	Wed Nov 21 19:57:57 2012	(r243377)
@@ -1623,15 +1623,19 @@ m_getptr(struct mbuf *m, int loc, int *o
 	return (NULL);
 }
 
+/*
+ * Print all information on an mbuf.
+ */
 void
-m_print(const struct mbuf *m, int maxlen)
+m_print(const struct mbuf *m, int maxlen, void (*func)(const struct mbuf *))
 {
 	int len;
 	int pdata;
 	const struct mbuf *m2;
+	struct m_tag *mt;
 
 	if (m == NULL) {
-		printf("mbuf: %p\n", m);
+		printf("mbuf = %p\n", m);
 		return;
 	}
 
@@ -1639,23 +1643,86 @@ m_print(const struct mbuf *m, int maxlen
 		len = m->m_pkthdr.len;
 	else
 		len = -1;
-	m2 = m;
-	while (m2 != NULL && (len == -1 || len)) {
+
+	for (m2 = m; m2 != NULL && (len == -1 || len); m2 = m2->m_next) {
 		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");
+
+		printf("mbuf = 0x%p\n"
+			"\t m_next = 0x%p\n"
+			"\t m_data = 0x%p\n"
+			"\t  m_len = %u\n"
+			"\tm_flags = 0x%8X\n"
+			"\tm_flags = %b\n"
+			"\t m_type = %u\n",
+		    m2, m2->m_next, m2->m_data, m2->m_len, m2->m_flags,
+		    (m2->m_flags & 0xFFFFFF), M_FLAG_BITS, m2->m_type);
+
+		if (m2->m_flags & M_EXT) {
+			printf(" m_ext:\n"
+				"\t ext_buf = 0x%p\n"
+				"\text_free = 0x%p\n"
+				"\text_arg1 = 0x%p\n"
+				"\text_arg2 = 0x%p\n"
+				"\text_size = %u\n"
+				"\t ref_cnt = %u (0x%p)\n"
+				"\text_type = %X %b\n",
+			    m2->m_ext.ext_buf, m2->m_ext.ext_free,
+			    m2->m_ext.ext_arg1, m2->m_ext.ext_arg2,
+			    m2->m_ext.ext_size, (*m2->m_ext.ref_cnt),
+			    m2->m_ext.ref_cnt, (m2->m_type & 0xFF),
+			    (m2->m_type & 0xF00), M_EXT_TYPE_BITS);
+		}
+
+		if (m2->m_flags & M_PKTHDR) {
+			printf(" m_pkthdr:\n"
+				"\t      rcvif = 0x%p"
+				"\t     header = 0x%p\n"
+				"\t        len = %u\n"
+				"\t     flowid = 0x%X\n"
+				"\t csum_flags = 0x%8X\n"
+				"\t csum_flags = %b\n"
+				"\tcsum_l2hlen = %u\n"
+				"\tcsum_l3hlen = %u\n"
+				"\tcsum_l4hlen = %u\n"
+				"\t  tso_segsz = %u\n"
+				"\t ether_vtag = 0x%X\n"
+				"\t  hash_type = 0x%X\n",
+			    m2->m_pkthdr.rcvif, m2->m_pkthdr.header,
+			    m2->m_pkthdr.len, m2->m_pkthdr.flowid,
+			    m2->m_pkthdr.csum_flags,
+			    m2->m_pkthdr.csum_flags, M_CSUM_FLAG_BITS,
+			    m2->m_pkthdr.csum_l2hlen, m2->m_pkthdr.csum_l3hlen,
+			    m2->m_pkthdr.csum_l4hlen, m2->m_pkthdr.tso_segsz,
+			    m2->m_pkthdr.ether_vtag, M_HASHTYPE_GET(m2));
+
+			for (mt = SLIST_FIRST(&m2->m_pkthdr.tags); mt != NULL;
+			     mt = SLIST_NEXT(mt, m_tag_link)) {
+				printf(" m_tag:\n"
+					"\t    m_tag_id = %u %b\n"
+					"\t   m_tag_len = %u\n"
+					"\tm_tag_cookie = 0x%X\n"
+					"\t  m_tag_free = 0x%p\n",
+				    (mt->m_tag_id & 0xFF),
+				    (mt->m_tag_id & 0xF00), MTAG_FLAG_BITS,
+				    mt->m_tag_len, mt->m_tag_cookie,
+				    mt->m_tag_free);
+				printf("\tm_tag data:\n");
+				printf("\t %*D\n",
+				    mt->m_tag_len, (u_char *)(mt + 1), " ");
+			}
+		}
+
 		if (pdata)
-			printf(", %*D\n", pdata, (u_char *)m2->m_data, "-");
+			printf(", %*D\n", pdata, (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);
+	if (func != NULL)
+		(*func)(m);
 	return;
 }
 

Modified: user/andre/tcp_workqueue/sys/sys/mbuf.h
==============================================================================
--- user/andre/tcp_workqueue/sys/sys/mbuf.h	Wed Nov 21 18:38:56 2012	(r243376)
+++ user/andre/tcp_workqueue/sys/sys/mbuf.h	Wed Nov 21 19:57:57 2012	(r243377)
@@ -216,6 +216,12 @@ struct mbuf {
 #define	M_FLOWID	0x00400000 /* deprecated: flowid is valid */
 #define	M_HASHTYPEBITS	0x0F000000 /* mask of bits holding flowid hash type */
 
+#define M_FLAG_BITS \
+    "\20\27FLOWID\26PROTO8\25PROTO7\24PROTO6\23NOFREE\22PROMISC" \
+    "\21VLANTAG\20FREELIST\17SKIP_FIREWALL\16LASTFRAG\15FIRSTFRAG"  \
+    "\14FRAG\13MCAST\12BCAST\11PROTO5\10PROTO4\7PROTO3\6PROTO2" \
+    "\5PROTO1\4RDONLY\3EOR\2PKTHDR\1EXT"	/* for use with m_print */
+
 /*
  * For RELENG_{6,7} steal these flags for limited multiple routing table
  * support. In RELENG_8 and beyond, use just one flag and a tag.
@@ -284,6 +290,9 @@ struct mbuf {
 #define	EXT_DISPOSABLE	300	/* can throw this buffer away w/page flipping */
 #define	EXT_EXTREF	400	/* has externally maintained ref_cnt ptr */
 
+#define M_EXT_TYPE_BITS \
+    "\20\16ext_EXTREF\15ext_DISPOSABLE\14ext_MOD_TYPE\13ext_NET_DRV"
+
 /*
  * Flags indicating hw checksum support and sw checksum requirements.  This
  * field can be directly tested against if_data.ifi_hwassist.
@@ -376,6 +385,13 @@ struct mbuf {
 #define	CSUM_IP6_TSO	0x00440000	/* IPv6/TSO		*/
 #define	CSUM_IP6_SCO	0x00880000	/* SCTP chunk offload	*/
 
+#define M_CSUM_FLAG_BITS \
+    "\20\40csum_L4_VALID\37csum_L4_CALC\36csum_L3_VALID\35csum_L3_CALC" \
+    "\30csum_IP6_SCO\27csum_IP6_TSO\26csum_IP6_UFO\25csum_IP6_FRAG0"    \
+    "\24csum_IP6_SCTP\23csum_IP6_TCP\22csum_IP6_UDP\21csum_IP6"         \
+    "\14csum_IP_SCO\13csum_IP_TSO\12csum_IP_UFO\11csum_IP_FRAG0"        \
+    "\10csum_IP_SCTP\7csum_IP_TCP\6csum_IP_UDP\5csum_IP"
+
 /* Definition compatiblity with < 20121118, goes away after tree pruning */
 #define	CSUM_UDP	CSUM_IP_UDP
 #define	CSUM_TCP	CSUM_IP_TCP
@@ -1006,7 +1022,8 @@ u_int		 m_length(struct mbuf *, struct m
 int		 m_mbuftouio(struct uio *, struct mbuf *, int);
 void		 m_move_pkthdr(struct mbuf *, struct mbuf *);
 struct mbuf	*m_prepend(struct mbuf *, int, int);
-void		 m_print(const struct mbuf *, int);
+void		 m_print(const struct mbuf *, int,
+		    void (*)(const struct mbuf *));
 struct mbuf	*m_pulldown(struct mbuf *, int, int, int *);
 struct mbuf	*m_pullup(struct mbuf *, int);
 int		m_sanity(struct mbuf *, int);
@@ -1065,6 +1082,9 @@ struct mbuf	*m_unshare(struct mbuf *, in
  */
 #define	MTAG_PERSISTENT				0x800
 
+#define MTAG_FLAG_BITS \
+    "\20\14mtag_PERSISTENT"
+
 #define	PACKET_TAG_NONE				0  /* Nadda */
 
 /* Packet tags for use with PACKET_ABI_COMPAT. */


More information about the svn-src-user mailing list