1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 28 */ 29 30 #ifndef _NETGRAPH_QOS_H_ 31 #define _NETGRAPH_QOS_H_ 32 33 #include <sys/mbuf.h> 34 35 /* ABI cookie */ 36 #define M_QOS_COOKIE 1571268051 37 #define MTAG_SIZE(X) ( sizeof(struct X) - sizeof(struct m_tag) ) 38 39 /* 40 * Definition of types within this ABI: 41 * - Choose a type (16bit) by i.e. "echo $((1000+$(date +%s)%64536))" 42 * - Retry if the type is already in use 43 * - Define the structure for the type according to mbuf_tags(9) 44 * struct m_qos_foo { 45 * struct m_tag tag; 46 * ... 47 * }; 48 * Preferred usage: 49 * struct m_qos_foo *p = (void *)m_tag_locate(m, 50 * M_QOS_COOKIE, M_QOS_FOO, ...); 51 * or 52 * p = (void *)m_tag_alloc( 53 * M_QOS_COOKIE, M_QOS_FOO, MTAG_SIZE(foo), ...); 54 m_tag_prepend(m, &p->tag); 55 */ 56 57 /* Color marking type */ 58 #define M_QOS_COLOR 23568 59 /* Keep colors ordered semantically in order to allow use of "<=" or ">=" */ 60 enum qos_color { 61 QOS_COLOR_GREEN, 62 QOS_COLOR_YELLOW, 63 QOS_COLOR_RED 64 }; 65 struct m_qos_color { 66 struct m_tag tag; 67 enum qos_color color; 68 }; 69 70 /* 71 * Priority class 72 * 73 * Processing per priority requires an overhead, which should 74 * be static (i.e. for alloctating queues) and small (for memory) 75 * So keep your chosen range limited. 76 */ 77 #define M_QOS_PRIORITY 28858 78 struct m_qos_priority { 79 struct m_tag tag; 80 uint8_t priority; /* 0 - lowest */ 81 }; 82 83 #endif /* _NETGRAPH_QOS_H_ */ 84