xref: /freebsd/sys/netgraph/qos.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2019 Lutz Donnerhacke <lutz@donnerhacke.de>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _NETGRAPH_QOS_H_
29 #define _NETGRAPH_QOS_H_
30 
31 #include <sys/mbuf.h>
32 
33 /* ABI cookie */
34 #define M_QOS_COOKIE		1571268051
35 #define MTAG_SIZE(X)	( sizeof(struct X) - sizeof(struct m_tag) )
36 
37 /*
38  * Definition of types within this ABI:
39  *  - Choose a type (16bit) by i.e. "echo $((1000+$(date +%s)%64536))"
40  *  - Retry if the type is already in use
41  *  - Define the structure for the type according to mbuf_tags(9)
42  *      struct m_qos_foo {
43  *          struct m_tag    tag;
44  *          ...
45  *      };
46  * Preferred usage:
47  *      struct m_qos_foo *p = (void *)m_tag_locate(m,
48  *          M_QOS_COOKIE, M_QOS_FOO, ...);
49  *    or
50  *      p = (void *)m_tag_alloc(
51  *          M_QOS_COOKIE, M_QOS_FOO, MTAG_SIZE(foo), ...);
52         m_tag_prepend(m, &p->tag);
53  */
54 
55 /* Color marking type */
56 #define M_QOS_COLOR		23568
57 /* Keep colors ordered semantically in order to allow use of "<=" or ">="  */
58 enum qos_color {
59 	QOS_COLOR_GREEN,
60 	QOS_COLOR_YELLOW,
61 	QOS_COLOR_RED
62 };
63 struct m_qos_color {
64 	struct m_tag	tag;
65 	enum qos_color	color;
66 };
67 
68 /*
69  * Priority class
70  *
71  * Processing per priority requires an overhead, which should
72  * be static (i.e. for alloctating queues) and small (for memory)
73  * So keep your chosen range limited.
74  */
75 #define M_QOS_PRIORITY		28858
76 struct m_qos_priority {
77 	struct m_tag	tag;
78 	uint8_t		priority;	/* 0 - lowest */
79 };
80 
81 #endif /* _NETGRAPH_QOS_H_ */
82