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 #pragma D depends_on provider mbuf 34 35 /* 36 * mbuf flags of global significance and layer crossing. 37 * Those of only protocol/layer specific significance are to be mapped 38 * to M_PROTO[1-12] and cleared at layer handoff boundaries. 39 * NB: Limited to the lower 24 bits. 40 */ 41 42 #pragma D binding "1.6.3" M_EXT 43 inline int M_EXT = 0x00000001; /* has associated external storage */ 44 #pragma D binding "1.6.3" M_PKTHDR 45 inline int M_PKTHDR = 0x00000002; /* start of record */ 46 #pragma D binding "1.6.3" M_EOR 47 inline int M_EOR = 0x00000004; /* end of record */ 48 #pragma D binding "1.6.3" M_RDONLY 49 inline int M_RDONLY = 0x00000008; /* associated data is marked read-only */ 50 #pragma D binding "1.6.3" M_BCAST 51 inline int M_BCAST = 0x00000010; /* send/received as link-level broadcast */ 52 #pragma D binding "1.6.3" M_MCAST 53 inline int M_MCAST = 0x00000020; /* send/received as link-level multicast */ 54 #pragma D binding "1.6.3" M_PROMISC 55 inline int M_PROMISC = 0x00000040; /* packet was not for us */ 56 #pragma D binding "1.6.3" M_VLANTAG 57 inline int M_VLANTAG = 0x00000080; /* ether_vtag is valid */ 58 #pragma D binding "1.6.3" M_UNUSED_8 59 inline int M_UNUSED_8 = 0x00000100; /* --available-- */ 60 #pragma D binding "1.6.3" M_NOFREE 61 inline int M_NOFREE = 0x00000200; /* do not free mbuf, embedded in cluster */ 62 63 #pragma D binding "1.6.3" M_PROTO1 64 inline int M_PROTO1 = 0x00001000; /* protocol-specific */ 65 #pragma D binding "1.6.3" M_PROTO2 66 inline int M_PROTO2 = 0x00002000; /* protocol-specific */ 67 #pragma D binding "1.6.3" M_PROTO3 68 inline int M_PROTO3 = 0x00004000; /* protocol-specific */ 69 #pragma D binding "1.6.3" M_PROTO4 70 inline int M_PROTO4 = 0x00008000; /* protocol-specific */ 71 #pragma D binding "1.6.3" M_PROTO5 72 inline int M_PROTO5 = 0x00010000; /* protocol-specific */ 73 #pragma D binding "1.6.3" M_PROTO6 74 inline int M_PROTO6 = 0x00020000; /* protocol-specific */ 75 #pragma D binding "1.6.3" M_PROTO7 76 inline int M_PROTO7 = 0x00040000; /* protocol-specific */ 77 #pragma D binding "1.6.3" M_PROTO8 78 inline int M_PROTO8 = 0x00080000; /* protocol-specific */ 79 #pragma D binding "1.6.3" M_PROTO9 80 inline int M_PROTO9 = 0x00100000; /* protocol-specific */ 81 #pragma D binding "1.6.3" M_PROTO10 82 inline int M_PROTO10 = 0x00200000; /* protocol-specific */ 83 #pragma D binding "1.6.3" M_PROTO11 84 inline int M_PROTO11 = 0x00400000; /* protocol-specific */ 85 #pragma D binding "1.6.3" M_PROTO12 86 inline int M_PROTO12 = 0x00800000; /* protocol-specific */ 87 88 #pragma D binding "1.6.3" mbufflags_string 89 inline string mbufflags_string[uint32_t flags] = 90 flags & M_EXT ? "M_EXT" : 91 flags & M_PKTHDR ? "M_PKTHDR" : 92 flags & M_EOR ? "M_EOR" : 93 flags & M_RDONLY ? "M_RDONLY" : 94 flags & M_BCAST ? "M_BCAST" : 95 flags & M_MCAST ? "M_MCAST" : 96 flags & M_PROMISC ? "M_PROMISC" : 97 flags & M_VLANTAG ? "M_VLANTAG" : 98 flags & M_UNUSED_8 ? "M_UNUSED_8" : 99 flags & M_NOFREE ? "M_NOFREE" : 100 flags & M_PROTO1 ? "M_PROTO1" : 101 flags & M_PROTO2 ? "M_PROTO2" : 102 flags & M_PROTO3 ? "M_PROTO3" : 103 flags & M_PROTO4 ? "M_PROTO4" : 104 flags & M_PROTO5 ? "M_PROTO5" : 105 flags & M_PROTO6 ? "M_PROTO6" : 106 flags & M_PROTO7 ? "M_PROTO7" : 107 flags & M_PROTO8 ? "M_PROTO8" : 108 flags & M_PROTO9 ? "M_PROTO9" : 109 flags & M_PROTO10 ? "M_PROTO10" : 110 flags & M_PROTO11 ? "M_PROTO11" : 111 flags & M_PROTO12 ? "M_PROTO12" : 112 "none" ; 113 114 /* 115 * Packet tag structure (see below for details). 116 */ 117 typedef struct m_tag { 118 u_int16_t m_tag_id; /* Tag ID */ 119 u_int16_t m_tag_len; /* Length of data */ 120 u_int32_t m_tag_cookie; /* ABI/Module ID */ 121 } m_tag_t; 122 123 /* 124 * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. 125 * Size ILP32: 48 126 * LP64: 56 127 * Compile-time assertions in uipc_mbuf.c test these values to ensure that 128 * they are correct. 129 */ 130 typedef struct pkthdr { 131 /* struct ifnet *rcvif; */ /* rcv interface */ 132 int32_t len; /* total packet length */ 133 134 /* Layer crossing persistent information. */ 135 uint32_t flowid; /* packet's 4-tuple system */ 136 uint64_t csum_flags; /* checksum and offload features */ 137 uint16_t fibnum; /* this packet should use this fib */ 138 uint8_t cosqos; /* class/quality of service */ 139 uint8_t rsstype; /* hash type */ 140 } pkthdr_t; 141 142 /* 143 * Description of external storage mapped into mbuf; valid only if M_EXT is 144 * set. 145 * Size ILP32: 28 146 * LP64: 48 147 * Compile-time assertions in uipc_mbuf.c test these values to ensure that 148 * they are correct. 149 */ 150 typedef struct m_ext { 151 volatile u_int *ext_cnt; /* pointer to ref count info */ 152 caddr_t ext_buf; /* start of buffer */ 153 uint32_t ext_size; /* size of buffer, for ext_free */ 154 uint32_t ext_type:8, /* type of external storage */ 155 ext_flags:24; /* external storage mbuf flags */ 156 void *ext_arg1; /* optional argument pointer */ 157 void *ext_arg2; /* optional argument pointer */ 158 } m_ext_t; 159 160 /* 161 * The core of the mbuf object along with some shortcut defines for practical 162 * purposes. 163 */ 164 struct mbuf { 165 uintptr_t mbuf_addr; 166 /* 167 * Header present at the beginning of every mbuf. 168 * Size ILP32: 24 169 * LP64: 32 170 * Compile-time assertions in uipc_mbuf.c test these values to ensure 171 * that they are correct. 172 */ 173 caddr_t m_data; /* location of data */ 174 int32_t m_len; /* amount of data in this mbuf */ 175 uint32_t m_type:8, /* type of data in this mbuf */ 176 m_flags:24; /* flags; see below */ 177 /* 178 * A set of optional headers (packet header, external storage header) 179 * and internal data storage. Historically, these arrays were sized 180 * to MHLEN (space left after a packet header) and MLEN (space left 181 * after only a regular mbuf header); they are now variable size in 182 * order to support future work on variable-size mbufs. 183 */ 184 /* union { */ 185 /* struct { */ 186 /* struct pkthdr m_pkthdr; */ 187 /* union { */ 188 /* struct m_ext m_ext; */ 189 /* char m_pktdat[0]; */ 190 /* }; */ 191 /* }; */ 192 /* char m_dat[0]; */ 193 /* }; */ 194 char *m_dat; 195 }; 196 197 typedef struct mbufinfo { 198 uintptr_t mbuf_addr; 199 caddr_t m_data; 200 int32_t m_len; 201 uint8_t m_type; 202 uint32_t m_flags; 203 } mbufinfo_t; 204 205 translator mbufinfo_t < struct mbuf *p > { 206 mbuf_addr = (uintptr_t)p; 207 m_data = p->m_data; 208 m_len = p->m_len; 209 m_type = p->m_type & 0xff000000; 210 m_flags = p->m_type & 0x00ffffff; 211 }; 212