1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1998-2010 Luigi Rizzo, Universita` di Pisa 5 * Portions Copyright (c) 2000 Akamba Corp. 6 * All rights reserved 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef _IP_DUMMYNET_H 31 #define _IP_DUMMYNET_H 32 #define NEW_AQM 33 /* 34 * Definition of the kernel-userland API for dummynet. 35 * 36 * Setsockopt() and getsockopt() pass a batch of objects, each 37 * of them starting with a "struct dn_id" which should fully identify 38 * the object and its relation with others in the sequence. 39 * The first object in each request should have 40 * type= DN_CMD_*, id = DN_API_VERSION. 41 * For other objects, type and subtype specify the object, len indicates 42 * the total length including the header, and 'id' identifies the specific 43 * object. 44 * 45 * Most objects are numbered with an identifier in the range 1..65535. 46 * DN_MAX_ID indicates the first value outside the range. 47 */ 48 49 #define DN_API_VERSION 12500000 50 #define DN_MAX_ID 0x10000 51 52 struct dn_id { 53 uint16_t len; /* total obj len including this header */ 54 uint8_t type; 55 uint8_t subtype; 56 uint32_t id; /* generic id */ 57 }; 58 59 /* 60 * These values are in the type field of struct dn_id. 61 * To preserve the ABI, never rearrange the list or delete 62 * entries with the exception of DN_LAST 63 */ 64 enum { 65 DN_NONE = 0, 66 DN_LINK = 1, 67 DN_FS, 68 DN_SCH, 69 DN_SCH_I, 70 DN_QUEUE, 71 DN_DELAY_LINE, 72 DN_PROFILE, 73 DN_FLOW, /* struct dn_flow */ 74 DN_TEXT, /* opaque text is the object */ 75 76 DN_CMD_CONFIG = 0x80, /* objects follow */ 77 DN_CMD_DELETE, /* subtype + list of entries */ 78 DN_CMD_GET, /* subtype + list of entries */ 79 DN_CMD_FLUSH, 80 /* for compatibility with FreeBSD 7.2/8 */ 81 DN_COMPAT_PIPE, 82 DN_COMPAT_QUEUE, 83 DN_GET_COMPAT, 84 85 /* special commands for emulation of sysctl variables */ 86 DN_SYSCTL_GET, 87 DN_SYSCTL_SET, 88 #ifdef NEW_AQM 89 /* subtypes used for setting/getting extra parameters. 90 * these subtypes used with IP_DUMMYNET3 command (get) 91 * and DN_TEXT (set). */ 92 DN_AQM_PARAMS, /* AQM extra params */ 93 DN_SCH_PARAMS, /* scheduler extra params */ 94 #endif 95 DN_LAST, 96 }; 97 98 enum { /* subtype for schedulers, flowset and the like */ 99 DN_SCHED_UNKNOWN = 0, 100 DN_SCHED_FIFO = 1, 101 DN_SCHED_WF2QP = 2, 102 /* others are in individual modules */ 103 }; 104 105 enum { /* user flags */ 106 DN_HAVE_MASK = 0x0001, /* fs or sched has a mask */ 107 DN_NOERROR = 0x0002, /* do not report errors */ 108 DN_QHT_HASH = 0x0004, /* qht is a hash table */ 109 DN_QSIZE_BYTES = 0x0008, /* queue size is in bytes */ 110 DN_HAS_PROFILE = 0x0010, /* a link has a profile */ 111 DN_IS_RED = 0x0020, 112 DN_IS_GENTLE_RED= 0x0040, 113 DN_IS_ECN = 0x0080, 114 #ifdef NEW_AQM 115 DN_IS_AQM = 0x0100, /* AQMs: e.g Codel & PIE */ 116 #endif 117 DN_PIPE_CMD = 0x1000, /* pipe config... */ 118 }; 119 120 /* 121 * link template. 122 */ 123 struct dn_link { 124 struct dn_id oid; 125 126 /* 127 * Userland sets bw and delay in bits/s and milliseconds. 128 * The kernel converts this back and forth to bits/tick and ticks. 129 * XXX what about burst ? 130 */ 131 int32_t link_nr; 132 uint32_t bandwidth; /* bit/s or bits/tick. */ 133 int delay; /* ms and ticks */ 134 uint64_t burst; /* scaled. bits*Hz XXX */ 135 }; 136 137 /* 138 * A flowset, which is a template for flows. Contains parameters 139 * from the command line: id, target scheduler, queue sizes, plr, 140 * flow masks, buckets for the flow hash, and possibly scheduler- 141 * specific parameters (weight, quantum and so on). 142 */ 143 struct dn_fs { 144 struct dn_id oid; 145 uint32_t fs_nr; /* the flowset number */ 146 uint32_t flags; /* userland flags */ 147 int qsize; /* queue size in slots or bytes */ 148 int32_t plr; /* PLR, pkt loss rate (2^31-1 means 100%) */ 149 uint32_t buckets; /* buckets used for the queue hash table */ 150 151 struct ipfw_flow_id flow_mask; 152 uint32_t sched_nr; /* the scheduler we attach to */ 153 /* generic scheduler parameters. Leave them at -1 if unset. 154 * Now we use 0: weight, 1: lmax, 2: priority 155 */ 156 int par[4]; 157 158 /* RED/GRED parameters. 159 * weight and probabilities are in the range 0..1 represented 160 * in fixed point arithmetic with SCALE_RED decimal bits. 161 */ 162 #define SCALE_RED 16 163 #define SCALE(x) ( (x) << SCALE_RED ) 164 #define SCALE_VAL(x) ( (x) >> SCALE_RED ) 165 #define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED ) 166 int w_q ; /* queue weight (scaled) */ 167 int max_th ; /* maximum threshold for queue (scaled) */ 168 int min_th ; /* minimum threshold for queue (scaled) */ 169 int max_p ; /* maximum value for p_b (scaled) */ 170 171 }; 172 173 /* 174 * dn_flow collects flow_id and stats for queues and scheduler 175 * instances, and is used to pass these info to userland. 176 * oid.type/oid.subtype describe the object, oid.id is number 177 * of the parent object. 178 */ 179 struct dn_flow { 180 struct dn_id oid; 181 struct ipfw_flow_id fid; 182 uint64_t tot_pkts; /* statistics counters */ 183 uint64_t tot_bytes; 184 uint32_t length; /* Queue length, in packets */ 185 uint32_t len_bytes; /* Queue length, in bytes */ 186 uint32_t drops; 187 }; 188 189 /* 190 * Scheduler template, mostly indicating the name, number, 191 * sched_mask and buckets. 192 */ 193 struct dn_sch { 194 struct dn_id oid; 195 uint32_t sched_nr; /* N, scheduler number */ 196 uint32_t buckets; /* number of buckets for the instances */ 197 uint32_t flags; /* have_mask, ... */ 198 199 char name[16]; /* null terminated */ 200 /* mask to select the appropriate scheduler instance */ 201 struct ipfw_flow_id sched_mask; /* M */ 202 }; 203 204 /* A delay profile is attached to a link. 205 * Note that a profile, as any other object, cannot be longer than 2^16 206 */ 207 #define ED_MAX_SAMPLES_NO 1024 208 struct dn_profile { 209 struct dn_id oid; 210 /* fields to simulate a delay profile */ 211 #define ED_MAX_NAME_LEN 32 212 char name[ED_MAX_NAME_LEN]; 213 int link_nr; 214 int loss_level; 215 uint32_t bandwidth; // XXX use link bandwidth? 216 int samples_no; /* actual len of samples[] */ 217 int samples[ED_MAX_SAMPLES_NO]; /* may be shorter */ 218 }; 219 220 #ifdef NEW_AQM 221 /* Extra parameters for AQM and scheduler. 222 * This struct is used to pass and retrieve parameters (configurations) 223 * to/from AQM and Scheduler. 224 */ 225 struct dn_extra_parms { 226 struct dn_id oid; 227 char name[16]; 228 uint32_t nr; 229 #define DN_MAX_EXTRA_PARM 10 230 int64_t par[DN_MAX_EXTRA_PARM]; 231 }; 232 #endif 233 234 /* 235 * Overall structure of dummynet 236 237 In dummynet, packets are selected with the firewall rules, and passed 238 to two different objects: PIPE or QUEUE (bad name). 239 240 A QUEUE defines a classifier, which groups packets into flows 241 according to a 'mask', puts them into independent queues (one 242 per flow) with configurable size and queue management policy, 243 and passes flows to a scheduler: 244 245 (flow_mask|sched_mask) sched_mask 246 +---------+ weight Wx +-------------+ 247 | |->-[flow]-->--| |-+ 248 -->--| QUEUE x | ... | | | 249 | |->-[flow]-->--| SCHEDuler N | | 250 +---------+ | | | 251 ... | +--[LINK N]-->-- 252 +---------+ weight Wy | | +--[LINK N]-->-- 253 | |->-[flow]-->--| | | 254 -->--| QUEUE y | ... | | | 255 | |->-[flow]-->--| | | 256 +---------+ +-------------+ | 257 +-------------+ 258 259 Many QUEUE objects can connect to the same scheduler, each 260 QUEUE object can have its own set of parameters. 261 262 In turn, the SCHEDuler 'forks' multiple instances according 263 to a 'sched_mask', each instance manages its own set of queues 264 and transmits on a private instance of a configurable LINK. 265 266 A PIPE is a simplified version of the above, where there 267 is no flow_mask, and each scheduler instance handles a single queue. 268 269 The following data structures (visible from userland) describe 270 the objects used by dummynet: 271 272 + dn_link, contains the main configuration parameters related 273 to delay and bandwidth; 274 + dn_profile describes a delay profile; 275 + dn_flow describes the flow status (flow id, statistics) 276 277 + dn_sch describes a scheduler 278 + dn_fs describes a flowset (msk, weight, queue parameters) 279 280 * 281 */ 282 283 #endif /* _IP_DUMMYNET_H */ 284