xref: /freebsd/share/dtrace/mbuf.d (revision 8ef24a0d4b28fe230e20637f56869cc4148cd2ca)
1 /*
2  * Copyright (c) 2016 George V. Neville-Neil
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  *
28  * Translators and flags for the mbuf structure.  FreeBSD specific code.
29  *
30  */
31 
32 #pragma D depends_on module kernel
33 
34 /*
35  * mbuf flags of global significance and layer crossing.
36  * Those of only protocol/layer specific significance are to be mapped
37  * to M_PROTO[1-12] and cleared at layer handoff boundaries.
38  * NB: Limited to the lower 24 bits.
39  */
40 
41 #pragma D binding "1.6.3" M_EXT
42 inline int M_EXT =	0x00000001; /* has associated external storage */
43 #pragma D binding "1.6.3" M_PKTHDR
44 inline int M_PKTHDR =	0x00000002; /* start of record */
45 #pragma D binding "1.6.3" M_EOR
46 inline int M_EOR =	0x00000004; /* end of record */
47 #pragma D binding "1.6.3" M_RDONLY
48 inline int M_RDONLY =	0x00000008; /* associated data is marked read-only */
49 #pragma D binding "1.6.3" M_BCAST
50 inline int M_BCAST =	0x00000010; /* send/received as link-level broadcast */
51 #pragma D binding "1.6.3" M_MCAST
52 inline int M_MCAST =	0x00000020; /* send/received as link-level multicast */
53 #pragma D binding "1.6.3" M_PROMISC
54 inline int M_PROMISC =	0x00000040; /* packet was not for us */
55 #pragma D binding "1.6.3" M_VLANTAG
56 inline int M_VLANTAG =	0x00000080; /* ether_vtag is valid */
57 #pragma D binding "1.6.3" M_UNUSED_8
58 inline int M_UNUSED_8 =	0x00000100; /* --available-- */
59 #pragma D binding "1.6.3" M_NOFREE
60 inline int M_NOFREE =	0x00000200; /* do not free mbuf, embedded in cluster */
61 
62 #pragma D binding "1.6.3" M_PROTO1
63 inline int M_PROTO1 =	0x00001000; /* protocol-specific */
64 #pragma D binding "1.6.3" M_PROTO2
65 inline int M_PROTO2 =	0x00002000; /* protocol-specific */
66 #pragma D binding "1.6.3" M_PROTO3
67 inline int M_PROTO3 =	0x00004000; /* protocol-specific */
68 #pragma D binding "1.6.3" M_PROTO4
69 inline int M_PROTO4 =	0x00008000; /* protocol-specific */
70 #pragma D binding "1.6.3" M_PROTO5
71 inline int M_PROTO5 =	0x00010000; /* protocol-specific */
72 #pragma D binding "1.6.3" M_PROTO6
73 inline int M_PROTO6 =	0x00020000; /* protocol-specific */
74 #pragma D binding "1.6.3" M_PROTO7
75 inline int M_PROTO7 =	0x00040000; /* protocol-specific */
76 #pragma D binding "1.6.3" M_PROTO8
77 inline int M_PROTO8 =	0x00080000; /* protocol-specific */
78 #pragma D binding "1.6.3" M_PROTO9
79 inline int M_PROTO9 =	0x00100000; /* protocol-specific */
80 #pragma D binding "1.6.3" M_PROTO10
81 inline int M_PROTO10 =	0x00200000; /* protocol-specific */
82 #pragma D binding "1.6.3" M_PROTO11
83 inline int M_PROTO11 =	0x00400000; /* protocol-specific */
84 #pragma D binding "1.6.3" M_PROTO12
85 inline int M_PROTO12 =	0x00800000; /* protocol-specific */
86 
87 #pragma D binding "1.6.3" mbufflags_string
88 inline string mbufflags_string[uint32_t flags] =
89     flags & M_EXT ? "M_EXT" :
90     flags & M_PKTHDR ? "M_PKTHDR" :
91     flags & M_EOR  ? "M_EOR" :
92     flags & M_RDONLY  ? "M_RDONLY" :
93     flags & M_BCAST  ? "M_BCAST" :
94     flags & M_MCAST 	? "M_MCAST" :
95     flags & M_PROMISC 	? "M_PROMISC" :
96     flags & M_VLANTAG 	? "M_VLANTAG" :
97     flags & M_UNUSED_8 	? "M_UNUSED_8" :
98     flags & M_NOFREE  ? "M_NOFREE" :
99     flags & M_PROTO1  ? "M_PROTO1" :
100     flags & M_PROTO2 ? "M_PROTO2" :
101     flags & M_PROTO3 ? "M_PROTO3" :
102     flags & M_PROTO4 ? "M_PROTO4" :
103     flags & M_PROTO5 ? "M_PROTO5" :
104     flags & M_PROTO6 ? "M_PROTO6" :
105     flags & M_PROTO7 ? "M_PROTO7" :
106     flags & M_PROTO8 ? "M_PROTO8" :
107     flags & M_PROTO9 ? "M_PROTO9" :
108     flags & M_PROTO10 ? "M_PROTO10" :
109     flags & M_PROTO11 ? "M_PROTO11" :
110     flags & M_PROTO12 ? "M_PROTO12" :
111     "none" ;
112 
113 /*
114  * Packet tag structure (see below for details).
115  */
116 typedef struct m_tag {
117 	u_int16_t		m_tag_id;	/* Tag ID */
118 	u_int16_t		m_tag_len;	/* Length of data */
119 	u_int32_t		m_tag_cookie;	/* ABI/Module ID */
120 } m_tag_t;
121 
122 /*
123  * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set.
124  * Size ILP32: 48
125  *	 LP64: 56
126  * Compile-time assertions in uipc_mbuf.c test these values to ensure that
127  * they are correct.
128  */
129 typedef struct pkthdr {
130 /*	struct ifnet	*rcvif;	*/	/* rcv interface */
131 	int32_t		 len;		/* total packet length */
132 
133 	/* Layer crossing persistent information. */
134 	uint32_t	 flowid;	/* packet's 4-tuple system */
135 	uint64_t	 csum_flags;	/* checksum and offload features */
136 	uint16_t	 fibnum;	/* this packet should use this fib */
137 	uint8_t		 cosqos;	/* class/quality of service */
138 	uint8_t		 rsstype;	/* hash type */
139 } pkthdr_t;
140 
141 /*
142  * Description of external storage mapped into mbuf; valid only if M_EXT is
143  * set.
144  * Size ILP32: 28
145  *	 LP64: 48
146  * Compile-time assertions in uipc_mbuf.c test these values to ensure that
147  * they are correct.
148  */
149 typedef struct m_ext {
150 	volatile u_int	*ext_cnt;	/* pointer to ref count info */
151 	caddr_t		 ext_buf;	/* start of buffer */
152 	uint32_t	 ext_size;	/* size of buffer, for ext_free */
153 	uint32_t	 ext_type:8,	/* type of external storage */
154 			 ext_flags:24;	/* external storage mbuf flags */
155 	void		*ext_arg1;	/* optional argument pointer */
156 	void		*ext_arg2;	/* optional argument pointer */
157 } m_ext_t;
158 
159 /*
160  * The core of the mbuf object along with some shortcut defines for practical
161  * purposes.
162  */
163 struct mbuf {
164 	uintptr_t mbuf_addr;
165 	/*
166 	 * Header present at the beginning of every mbuf.
167 	 * Size ILP32: 24
168 	 *      LP64: 32
169 	 * Compile-time assertions in uipc_mbuf.c test these values to ensure
170 	 * that they are correct.
171 	 */
172 	caddr_t		 m_data;	/* location of data */
173 	int32_t		 m_len;		/* amount of data in this mbuf */
174 	uint32_t	 m_type:8,	/* type of data in this mbuf */
175 			 m_flags:24;	/* flags; see below */
176 	/*
177 	 * A set of optional headers (packet header, external storage header)
178 	 * and internal data storage.  Historically, these arrays were sized
179 	 * to MHLEN (space left after a packet header) and MLEN (space left
180 	 * after only a regular mbuf header); they are now variable size in
181 	 * order to support future work on variable-size mbufs.
182 	 */
183 	/* union { */
184  	/* 	struct { */
185 	/* 		struct pkthdr	m_pkthdr; */
186 	/* 		union { */
187 	/* 			struct m_ext	m_ext; */
188 	/* 			char		m_pktdat[0]; */
189 	/* 		}; */
190 	/* 	}; */
191 	/* 	char	m_dat[0];		 */
192 	/* }; */
193 	char *m_dat;
194 };
195 
196 typedef struct mbufinfo {
197 	uintptr_t mbuf_addr;
198 	caddr_t m_data;
199 	int32_t m_len;
200 	uint8_t m_type;
201 	uint32_t m_flags;
202 } mbufinfo_t;
203 
204 translator mbufinfo_t < struct mbuf *p > {
205 	mbuf_addr = (uintptr_t)p;
206 	m_data = p->m_data;
207 	m_len = p->m_len;
208 	m_type = p->m_type & 0xff000000;
209 	m_flags = p->m_type & 0x00ffffff;
210 };
211