]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/ip_dummynet.h
xnu-1699.24.8.tar.gz
[apple/xnu.git] / bsd / netinet / ip_dummynet.h
CommitLineData
1c79356b 1/*
c910b4d9 2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
91447636
A
29 * Copyright (c) 1998-2002 Luigi Rizzo, Universita` di Pisa
30 * Portions Copyright (c) 2000 Akamba Corp.
31 * All rights reserved
1c79356b 32 *
91447636
A
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
1c79356b 41 *
91447636
A
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
1c79356b 53 *
91447636 54 * $FreeBSD: src/sys/netinet/ip_dummynet.h,v 1.32 2004/08/17 22:05:54 andre Exp $
1c79356b
A
55 */
56
57#ifndef _IP_DUMMYNET_H
58#define _IP_DUMMYNET_H
2d21ac55 59
9bccf70c 60#include <sys/appleapiopts.h>
1c79356b 61
91447636 62#ifdef PRIVATE
1c79356b 63/*
9bccf70c
A
64 * Definition of dummynet data structures. In the structures, I decided
65 * not to use the macros in <sys/queue.h> in the hope of making the code
66 * easier to port to other architectures. The type of lists and queue we
67 * use here is pretty simple anyways.
68 */
69
70/*
71 * We start with a heap, which is used in the scheduler to decide when
72 * to transmit packets etc.
1c79356b 73 *
9bccf70c 74 * The key for the heap is used for two different values:
1c79356b 75 *
9bccf70c
A
76 * 1. timer ticks- max 10K/second, so 32 bits are enough;
77 *
78 * 2. virtual times. These increase in steps of len/x, where len is the
79 * packet length, and x is either the weight of the flow, or the
80 * sum of all weights.
81 * If we limit to max 1000 flows and a max weight of 100, then
82 * x needs 17 bits. The packet size is 16 bits, so we can easily
83 * overflow if we do not allow errors.
84 * So we use a key "dn_key" which is 64 bits. Some macros are used to
85 * compare key values and handle wraparounds.
86 * MAX64 returns the largest of two key values.
87 * MY_M is used as a shift count when doing fixed point arithmetic
88 * (a better name would be useful...).
89 */
90typedef u_int64_t dn_key ; /* sorting key */
91#define DN_KEY_LT(a,b) ((int64_t)((a)-(b)) < 0)
92#define DN_KEY_LEQ(a,b) ((int64_t)((a)-(b)) <= 0)
93#define DN_KEY_GT(a,b) ((int64_t)((a)-(b)) > 0)
94#define DN_KEY_GEQ(a,b) ((int64_t)((a)-(b)) >= 0)
95#define MAX64(x,y) (( (int64_t) ( (y)-(x) )) > 0 ) ? (y) : (x)
96#define MY_M 16 /* number of left shift to obtain a larger precision */
97
98/*
99 * XXX With this scaling, max 1000 flows, max weight 100, 1Gbit/s, the
100 * virtual time wraps every 15 days.
101 */
102
103/*
104 * The OFFSET_OF macro is used to return the offset of a field within
105 * a structure. It is used by the heap management routines.
106 */
107#define OFFSET_OF(type, field) ((int)&( ((type *)0)->field) )
108
91447636
A
109/*
110 * The maximum hash table size for queues. This value must be a power
111 * of 2.
112 */
113#define DN_MAX_HASH_SIZE 65536
114
9bccf70c
A
115/*
116 * A heap entry is made of a key and a pointer to the actual
117 * object stored in the heap.
118 * The heap is an array of dn_heap_entry entries, dynamically allocated.
119 * Current size is "size", with "elements" actually in use.
120 * The heap normally supports only ordered insert and extract from the top.
121 * If we want to extract an object from the middle of the heap, we
122 * have to know where the object itself is located in the heap (or we
123 * need to scan the whole array). To this purpose, an object has a
124 * field (int) which contains the index of the object itself into the
125 * heap. When the object is moved, the field must also be updated.
126 * The offset of the index in the object is stored in the 'offset'
127 * field in the heap descriptor. The assumption is that this offset
128 * is non-zero if we want to support extract from the middle.
129 */
130struct dn_heap_entry {
131 dn_key key ; /* sorting key. Topmost element is smallest one */
132 void *object ; /* object pointer */
133} ;
134
135struct dn_heap {
136 int size ;
137 int elements ;
138 int offset ; /* XXX if > 0 this is the offset of direct ptr to obj */
139 struct dn_heap_entry *p ; /* really an array of "size" entries */
140} ;
141
142/*
91447636
A
143 * Packets processed by dummynet have an mbuf tag associated with
144 * them that carries their dummynet state. This is used within
145 * the dummynet code as well as outside when checking for special
146 * processing requirements.
1c79356b 147 */
91447636 148#ifdef KERNEL
c910b4d9
A
149#include <netinet/ip_var.h> /* for ip_out_args */
150
91447636
A
151struct dn_pkt_tag {
152 struct ip_fw *rule; /* matching rule */
153 int dn_dir; /* action when packet comes out. */
9bccf70c
A
154#define DN_TO_IP_OUT 1
155#define DN_TO_IP_IN 2
156#define DN_TO_BDG_FWD 3
157
91447636
A
158 dn_key output_time; /* when the pkt is due for delivery */
159 struct ifnet *ifp; /* interface, for ip_output */
6d2010ae 160 struct sockaddr_in dn_dst ;
91447636
A
161 struct route ro; /* route, for ip_output. MUST COPY */
162 int flags ; /* flags, for ip_output (IPv6 ?) */
c910b4d9 163 struct ip_out_args ipoa; /* output args, for ip_output. MUST COPY */
1c79356b 164};
91447636
A
165#else
166struct dn_pkt;
167#endif /* KERNEL */
1c79356b 168
9bccf70c
A
169/*
170 * Overall structure of dummynet (with WF2Q+):
171
172In dummynet, packets are selected with the firewall rules, and passed
173to two different objects: PIPE or QUEUE.
174
175A QUEUE is just a queue with configurable size and queue management
176policy. It is also associated with a mask (to discriminate among
177different flows), a weight (used to give different shares of the
178bandwidth to different flows) and a "pipe", which essentially
179supplies the transmit clock for all queues associated with that
180pipe.
181
182A PIPE emulates a fixed-bandwidth link, whose bandwidth is
183configurable. The "clock" for a pipe can come from either an
184internal timer, or from the transmit interrupt of an interface.
185A pipe is also associated with one (or more, if masks are used)
186queue, where all packets for that pipe are stored.
187
188The bandwidth available on the pipe is shared by the queues
189associated with that pipe (only one in case the packet is sent
190to a PIPE) according to the WF2Q+ scheduling algorithm and the
191configured weights.
192
193In general, incoming packets are stored in the appropriate queue,
194which is then placed into one of a few heaps managed by a scheduler
195to decide when the packet should be extracted.
196The scheduler (a function called dummynet()) is run at every timer
197tick, and grabs queues from the head of the heaps when they are
198ready for processing.
199
200There are three data structures definining a pipe and associated queues:
201
202 + dn_pipe, which contains the main configuration parameters related
203 to delay and bandwidth;
204 + dn_flow_set, which contains WF2Q+ configuration, flow
205 masks, plr and RED configuration;
206 + dn_flow_queue, which is the per-flow queue (containing the packets)
207
208Multiple dn_flow_set can be linked to the same pipe, and multiple
209dn_flow_queue can be linked to the same dn_flow_set.
210All data structures are linked in a linear list which is used for
211housekeeping purposes.
212
213During configuration, we create and initialize the dn_flow_set
214and dn_pipe structures (a dn_pipe also contains a dn_flow_set).
215
216At runtime: packets are sent to the appropriate dn_flow_set (either
217WFQ ones, or the one embedded in the dn_pipe for fixed-rate flows),
218which in turn dispatches them to the appropriate dn_flow_queue
219(created dynamically according to the masks).
220
221The transmit clock for fixed rate flows (ready_event()) selects the
222dn_flow_queue to be used to transmit the next packet. For WF2Q,
223wfq_ready_event() extract a pipe which in turn selects the right
224flow using a number of heaps defined into the pipe itself.
225
226 *
227 */
228
229/*
230 * per flow queue. This contains the flow identifier, the queue
231 * of packets, counters, and parameters used to support both RED and
232 * WF2Q+.
91447636
A
233 *
234 * A dn_flow_queue is created and initialized whenever a packet for
235 * a new flow arrives.
9bccf70c
A
236 */
237struct dn_flow_queue {
238 struct dn_flow_queue *next ;
239 struct ipfw_flow_id id ;
91447636
A
240
241 struct mbuf *head, *tail ; /* queue of packets */
9bccf70c
A
242 u_int len ;
243 u_int len_bytes ;
b0d623f7 244 u_int32_t numbytes ; /* credit for transmission (dynamic queues) */
9bccf70c
A
245
246 u_int64_t tot_pkts ; /* statistics counters */
247 u_int64_t tot_bytes ;
248 u_int32_t drops ;
91447636
A
249
250 int hash_slot ; /* debugging/diagnostic */
9bccf70c
A
251
252 /* RED parameters */
253 int avg ; /* average queue length est. (scaled) */
254 int count ; /* arrivals since last RED drop */
255 int random ; /* random value (scaled) */
256 u_int32_t q_time ; /* start of queue idle time */
257
258 /* WF2Q+ support */
91447636
A
259 struct dn_flow_set *fs ; /* parent flow set */
260 int heap_pos ; /* position (index) of struct in heap */
261 dn_key sched_time ; /* current time when queue enters ready_heap */
9bccf70c 262
91447636
A
263 dn_key S,F ; /* start time, finish time */
264 /*
265 * Setting F < S means the timestamp is invalid. We only need
9bccf70c
A
266 * to test this when the queue is empty.
267 */
1c79356b
A
268} ;
269
270/*
9bccf70c
A
271 * flow_set descriptor. Contains the "template" parameters for the
272 * queue configuration, and pointers to the hash table of dn_flow_queue's.
273 *
274 * The hash table is an array of lists -- we identify the slot by
275 * hashing the flow-id, then scan the list looking for a match.
276 * The size of the hash table (buckets) is configurable on a per-queue
277 * basis.
91447636
A
278 *
279 * A dn_flow_set is created whenever a new queue or pipe is created (in the
280 * latter case, the structure is located inside the struct dn_pipe).
9bccf70c
A
281 */
282struct dn_flow_set {
b0d623f7 283 SLIST_ENTRY(dn_flow_set) next; /* linked list in a hash slot */
9bccf70c
A
284
285 u_short fs_nr ; /* flow_set number */
286 u_short flags_fs;
287#define DN_HAVE_FLOW_MASK 0x0001
9bccf70c
A
288#define DN_IS_RED 0x0002
289#define DN_IS_GENTLE_RED 0x0004
91447636
A
290#define DN_QSIZE_IS_BYTES 0x0008 /* queue size is measured in bytes */
291#define DN_NOERROR 0x0010 /* do not report ENOBUFS on drops */
292#define DN_IS_PIPE 0x4000
293#define DN_IS_QUEUE 0x8000
9bccf70c 294
91447636 295 struct dn_pipe *pipe ; /* pointer to parent pipe */
9bccf70c
A
296 u_short parent_nr ; /* parent pipe#, 0 if local to a pipe */
297
91447636
A
298 int weight ; /* WFQ queue weight */
299 int qsize ; /* queue size in slots or bytes */
300 int plr ; /* pkt loss rate (2^31-1 means 100%) */
9bccf70c
A
301
302 struct ipfw_flow_id flow_mask ;
91447636 303
9bccf70c
A
304 /* hash table of queues onto this flow_set */
305 int rq_size ; /* number of slots */
306 int rq_elements ; /* active elements */
307 struct dn_flow_queue **rq; /* array of rq_size entries */
91447636 308
9bccf70c 309 u_int32_t last_expired ; /* do not expire too frequently */
9bccf70c
A
310 int backlogged ; /* #active queues for this flowset */
311
312 /* RED parameters */
313#define SCALE_RED 16
314#define SCALE(x) ( (x) << SCALE_RED )
315#define SCALE_VAL(x) ( (x) >> SCALE_RED )
316#define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED )
91447636
A
317 int w_q ; /* queue weight (scaled) */
318 int max_th ; /* maximum threshold for queue (scaled) */
319 int min_th ; /* minimum threshold for queue (scaled) */
320 int max_p ; /* maximum value for p_b (scaled) */
321 u_int c_1 ; /* max_p/(max_th-min_th) (scaled) */
322 u_int c_2 ; /* max_p*min_th/(max_th-min_th) (scaled) */
323 u_int c_3 ; /* for GRED, (1-max_p)/max_th (scaled) */
324 u_int c_4 ; /* for GRED, 1 - 2*max_p (scaled) */
325 u_int * w_q_lookup ; /* lookup table for computing (1-w_q)^t */
326 u_int lookup_depth ; /* depth of lookup table */
327 int lookup_step ; /* granularity inside the lookup table */
328 int lookup_weight ; /* equal to (1-w_q)^t / (1-w_q)^(t+1) */
329 int avg_pkt_size ; /* medium packet size */
330 int max_pkt_size ; /* max packet size */
9bccf70c
A
331} ;
332
b0d623f7
A
333SLIST_HEAD(dn_flow_set_head, dn_flow_set);
334
9bccf70c
A
335/*
336 * Pipe descriptor. Contains global parameters, delay-line queue,
337 * and the flow_set used for fixed-rate queues.
91447636
A
338 *
339 * For WF2Q+ support it also has 3 heaps holding dn_flow_queue:
9bccf70c
A
340 * not_eligible_heap, for queues whose start time is higher
341 * than the virtual time. Sorted by start time.
342 * scheduler_heap, for queues eligible for scheduling. Sorted by
343 * finish time.
9bccf70c
A
344 * idle_heap, all flows that are idle and can be removed. We
345 * do that on each tick so we do not slow down too much
346 * operations during forwarding.
347 *
1c79356b 348 */
91447636 349struct dn_pipe { /* a pipe */
b0d623f7 350 SLIST_ENTRY(dn_pipe) next; /* linked list in a hash slot */
1c79356b 351
9bccf70c 352 int pipe_nr ; /* number */
91447636
A
353 int bandwidth; /* really, bytes/tick. */
354 int delay ; /* really, ticks */
1c79356b 355
91447636 356 struct mbuf *head, *tail ; /* packets in delay line */
1c79356b 357
9bccf70c
A
358 /* WF2Q+ */
359 struct dn_heap scheduler_heap ; /* top extract - key Finish time*/
360 struct dn_heap not_eligible_heap; /* top extract- key Start time */
361 struct dn_heap idle_heap ; /* random extract - key Start=Finish time */
362
91447636
A
363 dn_key V ; /* virtual time */
364 int sum; /* sum of weights of all active sessions */
365 int numbytes; /* bits I can transmit (more or less). */
9bccf70c 366
91447636 367 dn_key sched_time ; /* time pipe was scheduled in ready_heap */
1c79356b 368
91447636
A
369 /*
370 * When the tx clock come from an interface (if_name[0] != '\0'), its name
371 * is stored below, whereas the ifp is filled when the rule is configured.
9bccf70c 372 */
91447636 373 char if_name[IFNAMSIZ];
9bccf70c
A
374 struct ifnet *ifp ;
375 int ready ; /* set if ifp != NULL and we got a signal from it */
376
377 struct dn_flow_set fs ; /* used with fixed-rate flows */
378};
379
b0d623f7
A
380SLIST_HEAD(dn_pipe_head, dn_pipe);
381
9bccf70c 382#ifdef KERNEL
1c79356b 383
91447636 384void ip_dn_init(void); /* called from raw_ip.c:load_ipfw() */
1c79356b 385
91447636
A
386typedef int ip_dn_ctl_t(struct sockopt *); /* raw_ip.c */
387typedef void ip_dn_ruledel_t(void *); /* ip_fw.c */
388typedef int ip_dn_io_t(struct mbuf *m, int pipe_nr, int dir,
389 struct ip_fw_args *fwa);
390extern ip_dn_ctl_t *ip_dn_ctl_ptr;
391extern ip_dn_ruledel_t *ip_dn_ruledel_ptr;
392extern ip_dn_io_t *ip_dn_io_ptr;
393#define DUMMYNET_LOADED (ip_dn_io_ptr != NULL)
1c79356b 394
b0d623f7
A
395#pragma pack(4)
396
397struct dn_heap_32 {
398 int size ;
399 int elements ;
400 int offset ; /* XXX if > 0 this is the offset of direct ptr to obj */
401 user32_addr_t p ; /* really an array of "size" entries */
402} ;
403
404struct dn_flow_queue_32 {
405 user32_addr_t next ;
406 struct ipfw_flow_id id ;
407
408 user32_addr_t head, tail ; /* queue of packets */
409 u_int len ;
410 u_int len_bytes ;
411 u_int32_t numbytes ; /* credit for transmission (dynamic queues) */
412
413 u_int64_t tot_pkts ; /* statistics counters */
414 u_int64_t tot_bytes ;
415 u_int32_t drops ;
416
417 int hash_slot ; /* debugging/diagnostic */
418
419 /* RED parameters */
420 int avg ; /* average queue length est. (scaled) */
421 int count ; /* arrivals since last RED drop */
422 int random ; /* random value (scaled) */
423 u_int32_t q_time ; /* start of queue idle time */
424
425 /* WF2Q+ support */
426 user32_addr_t fs ; /* parent flow set */
427 int heap_pos ; /* position (index) of struct in heap */
428 dn_key sched_time ; /* current time when queue enters ready_heap */
429
430 dn_key S,F ; /* start time, finish time */
431 /*
432 * Setting F < S means the timestamp is invalid. We only need
433 * to test this when the queue is empty.
434 */
435} ;
436
437struct dn_flow_set_32 {
438 user32_addr_t next; /* next flow set in all_flow_sets list */
439
440 u_short fs_nr ; /* flow_set number */
441 u_short flags_fs;
442#define DN_HAVE_FLOW_MASK 0x0001
443#define DN_IS_RED 0x0002
444#define DN_IS_GENTLE_RED 0x0004
445#define DN_QSIZE_IS_BYTES 0x0008 /* queue size is measured in bytes */
446#define DN_NOERROR 0x0010 /* do not report ENOBUFS on drops */
447#define DN_IS_PIPE 0x4000
448#define DN_IS_QUEUE 0x8000
449
450 user32_addr_t pipe ; /* pointer to parent pipe */
451 u_short parent_nr ; /* parent pipe#, 0 if local to a pipe */
452
453 int weight ; /* WFQ queue weight */
454 int qsize ; /* queue size in slots or bytes */
455 int plr ; /* pkt loss rate (2^31-1 means 100%) */
456
457 struct ipfw_flow_id flow_mask ;
458
459 /* hash table of queues onto this flow_set */
460 int rq_size ; /* number of slots */
461 int rq_elements ; /* active elements */
462 user32_addr_t rq; /* array of rq_size entries */
463
464 u_int32_t last_expired ; /* do not expire too frequently */
465 int backlogged ; /* #active queues for this flowset */
466
467 /* RED parameters */
468#define SCALE_RED 16
469#define SCALE(x) ( (x) << SCALE_RED )
470#define SCALE_VAL(x) ( (x) >> SCALE_RED )
471#define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED )
472 int w_q ; /* queue weight (scaled) */
473 int max_th ; /* maximum threshold for queue (scaled) */
474 int min_th ; /* minimum threshold for queue (scaled) */
475 int max_p ; /* maximum value for p_b (scaled) */
476 u_int c_1 ; /* max_p/(max_th-min_th) (scaled) */
477 u_int c_2 ; /* max_p*min_th/(max_th-min_th) (scaled) */
478 u_int c_3 ; /* for GRED, (1-max_p)/max_th (scaled) */
479 u_int c_4 ; /* for GRED, 1 - 2*max_p (scaled) */
480 user32_addr_t w_q_lookup ; /* lookup table for computing (1-w_q)^t */
481 u_int lookup_depth ; /* depth of lookup table */
482 int lookup_step ; /* granularity inside the lookup table */
483 int lookup_weight ; /* equal to (1-w_q)^t / (1-w_q)^(t+1) */
484 int avg_pkt_size ; /* medium packet size */
485 int max_pkt_size ; /* max packet size */
486} ;
487
488struct dn_pipe_32 { /* a pipe */
489 user32_addr_t next ;
490
491 int pipe_nr ; /* number */
492 int bandwidth; /* really, bytes/tick. */
493 int delay ; /* really, ticks */
494
495 user32_addr_t head, tail ; /* packets in delay line */
496
497 /* WF2Q+ */
498 struct dn_heap_32 scheduler_heap ; /* top extract - key Finish time*/
499 struct dn_heap_32 not_eligible_heap; /* top extract- key Start time */
500 struct dn_heap_32 idle_heap ; /* random extract - key Start=Finish time */
501
502 dn_key V ; /* virtual time */
503 int sum; /* sum of weights of all active sessions */
504 int numbytes; /* bits I can transmit (more or less). */
505
506 dn_key sched_time ; /* time pipe was scheduled in ready_heap */
507
508 /*
509 * When the tx clock come from an interface (if_name[0] != '\0'), its name
510 * is stored below, whereas the ifp is filled when the rule is configured.
511 */
512 char if_name[IFNAMSIZ];
513 user32_addr_t ifp ;
514 int ready ; /* set if ifp != NULL and we got a signal from it */
515
516 struct dn_flow_set_32 fs ; /* used with fixed-rate flows */
517};
518#pragma pack()
519
520
521struct dn_heap_64 {
522 int size ;
523 int elements ;
524 int offset ; /* XXX if > 0 this is the offset of direct ptr to obj */
525 user64_addr_t p ; /* really an array of "size" entries */
526} ;
527
528
529struct dn_flow_queue_64 {
530 user64_addr_t next ;
531 struct ipfw_flow_id id ;
532
533 user64_addr_t head, tail ; /* queue of packets */
534 u_int len ;
535 u_int len_bytes ;
536 u_int32_t numbytes ; /* credit for transmission (dynamic queues) */
537
538 u_int64_t tot_pkts ; /* statistics counters */
539 u_int64_t tot_bytes ;
540 u_int32_t drops ;
541
542 int hash_slot ; /* debugging/diagnostic */
543
544 /* RED parameters */
545 int avg ; /* average queue length est. (scaled) */
546 int count ; /* arrivals since last RED drop */
547 int random ; /* random value (scaled) */
548 u_int32_t q_time ; /* start of queue idle time */
549
550 /* WF2Q+ support */
551 user64_addr_t fs ; /* parent flow set */
552 int heap_pos ; /* position (index) of struct in heap */
553 dn_key sched_time ; /* current time when queue enters ready_heap */
554
555 dn_key S,F ; /* start time, finish time */
556 /*
557 * Setting F < S means the timestamp is invalid. We only need
558 * to test this when the queue is empty.
559 */
560} ;
561
562struct dn_flow_set_64 {
563 user64_addr_t next; /* next flow set in all_flow_sets list */
564
565 u_short fs_nr ; /* flow_set number */
566 u_short flags_fs;
567#define DN_HAVE_FLOW_MASK 0x0001
568#define DN_IS_RED 0x0002
569#define DN_IS_GENTLE_RED 0x0004
570#define DN_QSIZE_IS_BYTES 0x0008 /* queue size is measured in bytes */
571#define DN_NOERROR 0x0010 /* do not report ENOBUFS on drops */
572#define DN_IS_PIPE 0x4000
573#define DN_IS_QUEUE 0x8000
574
575 user64_addr_t pipe ; /* pointer to parent pipe */
576 u_short parent_nr ; /* parent pipe#, 0 if local to a pipe */
577
578 int weight ; /* WFQ queue weight */
579 int qsize ; /* queue size in slots or bytes */
580 int plr ; /* pkt loss rate (2^31-1 means 100%) */
581
582 struct ipfw_flow_id flow_mask ;
583
584 /* hash table of queues onto this flow_set */
585 int rq_size ; /* number of slots */
586 int rq_elements ; /* active elements */
587 user64_addr_t rq; /* array of rq_size entries */
588
589 u_int32_t last_expired ; /* do not expire too frequently */
590 int backlogged ; /* #active queues for this flowset */
591
592 /* RED parameters */
593#define SCALE_RED 16
594#define SCALE(x) ( (x) << SCALE_RED )
595#define SCALE_VAL(x) ( (x) >> SCALE_RED )
596#define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED )
597 int w_q ; /* queue weight (scaled) */
598 int max_th ; /* maximum threshold for queue (scaled) */
599 int min_th ; /* minimum threshold for queue (scaled) */
600 int max_p ; /* maximum value for p_b (scaled) */
601 u_int c_1 ; /* max_p/(max_th-min_th) (scaled) */
602 u_int c_2 ; /* max_p*min_th/(max_th-min_th) (scaled) */
603 u_int c_3 ; /* for GRED, (1-max_p)/max_th (scaled) */
604 u_int c_4 ; /* for GRED, 1 - 2*max_p (scaled) */
605 user64_addr_t w_q_lookup ; /* lookup table for computing (1-w_q)^t */
606 u_int lookup_depth ; /* depth of lookup table */
607 int lookup_step ; /* granularity inside the lookup table */
608 int lookup_weight ; /* equal to (1-w_q)^t / (1-w_q)^(t+1) */
609 int avg_pkt_size ; /* medium packet size */
610 int max_pkt_size ; /* max packet size */
611} ;
612
613struct dn_pipe_64 { /* a pipe */
614 user64_addr_t next ;
615
616 int pipe_nr ; /* number */
617 int bandwidth; /* really, bytes/tick. */
618 int delay ; /* really, ticks */
619
620 user64_addr_t head, tail ; /* packets in delay line */
621
622 /* WF2Q+ */
623 struct dn_heap_64 scheduler_heap ; /* top extract - key Finish time*/
624 struct dn_heap_64 not_eligible_heap; /* top extract- key Start time */
625 struct dn_heap_64 idle_heap ; /* random extract - key Start=Finish time */
626
627 dn_key V ; /* virtual time */
628 int sum; /* sum of weights of all active sessions */
629 int numbytes; /* bits I can transmit (more or less). */
630
631 dn_key sched_time ; /* time pipe was scheduled in ready_heap */
632
633 /*
634 * When the tx clock come from an interface (if_name[0] != '\0'), its name
635 * is stored below, whereas the ifp is filled when the rule is configured.
636 */
637 char if_name[IFNAMSIZ];
638 user64_addr_t ifp ;
639 int ready ; /* set if ifp != NULL and we got a signal from it */
640
641 struct dn_flow_set_64 fs ; /* used with fixed-rate flows */
642};
643
644
645
91447636
A
646/*
647 * Return the IPFW rule associated with the dummynet tag; if any.
648 * Make sure that the dummynet tag is not reused by lower layers.
649 */
650static __inline struct ip_fw *
651ip_dn_claim_rule(struct mbuf *m)
652{
653 struct m_tag *mtag = m_tag_locate(m, KERNEL_MODULE_TAG_ID,
654 KERNEL_TAG_TYPE_DUMMYNET, NULL);
655 if (mtag != NULL) {
656 mtag->m_tag_type = KERNEL_TAG_TYPE_NONE;
657 return (((struct dn_pkt_tag *)(mtag+1))->rule);
658 } else
659 return (NULL);
660}
661#endif /* KERNEL */
662
663#endif /* PRIVATE */
1c79356b 664#endif /* _IP_DUMMYNET_H */