1114402Sru/*
2151497Sru * Copyright (c) 2016 George V. Neville-Neil
3114402Sru * All rights reserved.
4114402Sru *
5114402Sru * Redistribution and use in source and binary forms, with or without
6114402Sru * modification, are permitted provided that the following conditions
7114402Sru * are met:
8114402Sru * 1. Redistributions of source code must retain the above copyright
9114402Sru *    notice, this list of conditions and the following disclaimer.
10114402Sru * 2. Redistributions in binary form must reproduce the above copyright
11114402Sru *    notice, this list of conditions and the following disclaimer in the
12114402Sru *    documentation and/or other materials provided with the distribution.
13114402Sru *
14114402Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15114402Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16114402Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17114402Sru * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18114402Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19114402Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20151497Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21114402Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22114402Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23114402Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24114402Sru * SUCH DAMAGE.
25114402Sru *
26114402Sru * Translators and flags for the mbuf structure.  FreeBSD specific code.
27114402Sru */
28114402Sru
29114402Sru#pragma D depends_on module kernel
30114402Sru
31114402Sru/*
32114402Sru * mbuf flags of global significance and layer crossing.
33114402Sru * Those of only protocol/layer specific significance are to be mapped
34114402Sru * to M_PROTO[1-12] and cleared at layer handoff boundaries.
35114402Sru * NB: Limited to the lower 24 bits.
36114402Sru */
37114402Sru
38114402Sru#pragma D binding "1.6.3" M_EXT
39114402Sruinline int M_EXT =	0x00000001; /* has associated external storage */
40114402Sru#pragma D binding "1.6.3" M_PKTHDR
41114402Sruinline int M_PKTHDR =	0x00000002; /* start of record */
42114402Sru#pragma D binding "1.6.3" M_EOR
43114402Sruinline int M_EOR =	0x00000004; /* end of record */
44114402Sru#pragma D binding "1.6.3" M_RDONLY
45114402Sruinline int M_RDONLY =	0x00000008; /* associated data is marked read-only */
46114402Sru#pragma D binding "1.6.3" M_BCAST
47114402Sruinline int M_BCAST =	0x00000010; /* send/received as link-level broadcast */
48114402Sru#pragma D binding "1.6.3" M_MCAST
49114402Sruinline int M_MCAST =	0x00000020; /* send/received as link-level multicast */
50114402Sru#pragma D binding "1.6.3" M_PROMISC
51114402Sruinline int M_PROMISC =	0x00000040; /* packet was not for us */
52114402Sru#pragma D binding "1.6.3" M_VLANTAG
53114402Sruinline int M_VLANTAG =	0x00000080; /* ether_vtag is valid */
54114402Sru#pragma D binding "1.13" M_EXTPG
55114402Sruinline int M_EXTPG =	0x00000100; /* has array of unmapped pages and TLS */
56114402Sru#pragma D binding "1.6.3" M_NOFREE
57114402Sruinline int M_NOFREE =	0x00000200; /* do not free mbuf, embedded in cluster */
58114402Sru#pragma D binding "1.13" M_TSTMP
59114402Sruinline int M_TSTMP =	0x00000400; /* rcv_tstmp field is valid */
60114402Sru#pragma D binding "1.13" M_TSTMP_HPREC
61114402Sruinline int M_TSTMP_HPREC = 0x00000800; /* rcv_tstmp is high-prec */
62114402Sru#pragma D binding "1.13" M_TSTMP_LRO
63114402Sruinline int M_TSTMP_LRO = 0x00001000; /* Time LRO pushed in pkt is valid */
64114402Sru
65114402Sru#pragma D binding "1.13" M_PROTO1
66114402Sruinline int M_PROTO1 =	0x00002000; /* protocol-specific */
67114402Sru#pragma D binding "1.13" M_PROTO2
68114402Sruinline int M_PROTO2 =	0x00004000; /* protocol-specific */
69114402Sru#pragma D binding "1.13" M_PROTO3
70114402Sruinline int M_PROTO3 =	0x00008000; /* protocol-specific */
71114402Sru#pragma D binding "1.13" M_PROTO4
72114402Sruinline int M_PROTO4 =	0x00010000; /* protocol-specific */
73114402Sru#pragma D binding "1.13" M_PROTO5
74114402Sruinline int M_PROTO5 =	0x00020000; /* protocol-specific */
75114402Sru#pragma D binding "1.13" M_PROTO6
76114402Sruinline int M_PROTO6 =	0x00040000; /* protocol-specific */
77114402Sru#pragma D binding "1.13" M_PROTO7
78114402Sruinline int M_PROTO7 =	0x00080000; /* protocol-specific */
79114402Sru#pragma D binding "1.13" M_PROTO8
80114402Sruinline int M_PROTO8 =	0x00100000; /* protocol-specific */
81114402Sru#pragma D binding "1.13" M_PROTO9
82114402Sruinline int M_PROTO9 =	0x00200000; /* protocol-specific */
83114402Sru#pragma D binding "1.13" M_PROTO10
84114402Sruinline int M_PROTO10 =	0x00400000; /* protocol-specific */
85114402Sru#pragma D binding "1.13" M_PROTO11
86114402Sruinline int M_PROTO11 =	0x00800000; /* protocol-specific */
87114402Sru
88114402Sru#pragma D binding "1.13" mbufflags_string
89114402Sruinline string mbufflags_string[uint32_t flags] =
90114402Sru    flags & M_EXT ? "M_EXT" :
91114402Sru    flags & M_PKTHDR ? "M_PKTHDR" :
92114402Sru    flags & M_EOR  ? "M_EOR" :
93114402Sru    flags & M_RDONLY  ? "M_RDONLY" :
94114402Sru    flags & M_BCAST  ? "M_BCAST" :
95114402Sru    flags & M_MCAST 	? "M_MCAST" :
96114402Sru    flags & M_PROMISC 	? "M_PROMISC" :
97114402Sru    flags & M_VLANTAG 	? "M_VLANTAG" :
98114402Sru    flags & M_EXTPG 	? "M_EXTPG" :
99114402Sru    flags & M_NOFREE	? "M_NOFREE" :
100114402Sru    flags & M_TSTMP	? "M_TSTMP" :
101114402Sru    flags & M_TSTMP_HPREC ? "M_TSTMP_HPREC" :
102114402Sru    flags & M_TSTMP_LRO ? "M_TSTMP_LRO" :
103114402Sru    flags & M_PROTO1  ? "M_PROTO1" :
104114402Sru    flags & M_PROTO2 ? "M_PROTO2" :
105114402Sru    flags & M_PROTO3 ? "M_PROTO3" :
106114402Sru    flags & M_PROTO4 ? "M_PROTO4" :
107114402Sru    flags & M_PROTO5 ? "M_PROTO5" :
108114402Sru    flags & M_PROTO6 ? "M_PROTO6" :
109114402Sru    flags & M_PROTO7 ? "M_PROTO7" :
110114402Sru    flags & M_PROTO8 ? "M_PROTO8" :
111114402Sru    flags & M_PROTO9 ? "M_PROTO9" :
112114402Sru    flags & M_PROTO10 ? "M_PROTO10" :
113114402Sru    flags & M_PROTO11 ? "M_PROTO11" :
114114402Sru    "none" ;
115114402Sru
116114402Srutypedef struct mbufinfo {
117114402Sru	uintptr_t mbuf_addr;
118114402Sru	caddr_t m_data;
119114402Sru	int32_t m_len;
120114402Sru	uint8_t m_type;
121114402Sru	uint32_t m_flags;
122114402Sru} mbufinfo_t;
123114402Sru
124114402Srutranslator mbufinfo_t < struct mbuf *p > {
125114402Sru	mbuf_addr = (uintptr_t)p;
126114402Sru	m_data = p->m_data;
127114402Sru	m_len = p->m_len;
128114402Sru	m_type = p->m_type & 0xff000000;
129114402Sru	m_flags = p->m_type & 0x00ffffff;
130114402Sru};
131114402Sru