2 * Copyright (c) 2010 Riccardo Panicucci, Universita` di Pisa
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/malloc.h>
33 #include <sys/socket.h>
34 #include <sys/socketvar.h>
35 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/rwlock.h>
40 #include <net/if.h> /* IFNAMSIZ */
41 #include <netinet/in.h>
42 #include <netinet/ip_var.h> /* ipfw_rule_ref */
43 #include <netinet/ip_fw.h> /* flow_id */
44 #include <netinet/ip_dummynet.h>
45 #include <netpfil/ipfw/ip_fw_private.h>
46 #include <netpfil/ipfw/dn_heap.h>
47 #include <netpfil/ipfw/ip_dn_private.h>
49 #include <netpfil/ipfw/dn_aqm.h>
51 #include <netpfil/ipfw/dn_sched.h>
57 * This file implements a FIFO scheduler for a single queue.
58 * The queue is allocated as part of the scheduler instance,
59 * and there is a single flowset is in the template which stores
60 * queue size and policy.
61 * Enqueue and dequeue use the default library functions.
64 fifo_enqueue(struct dn_sch_inst *si, struct dn_queue *q, struct mbuf *m)
66 /* XXX if called with q != NULL and m=NULL, this is a
67 * re-enqueue from an existing scheduler, which we should
71 return dn_enqueue((struct dn_queue *)(si+1), m, 0);
75 fifo_dequeue(struct dn_sch_inst *si)
77 return dn_dequeue((struct dn_queue *)(si + 1));
81 fifo_new_sched(struct dn_sch_inst *si)
83 /* This scheduler instance contains the queue */
84 struct dn_queue *q = (struct dn_queue *)(si + 1);
86 set_oid(&q->ni.oid, DN_QUEUE, sizeof(*q));
88 q->fs = si->sched->fs;
93 fifo_free_sched(struct dn_sch_inst *si)
95 struct dn_queue *q = (struct dn_queue *)(si + 1);
96 dn_free_pkts(q->mq.head);
102 * FIFO scheduler descriptor
103 * contains the type of the scheduler, the name, the size of extra
104 * data structures, and function pointers.
106 static struct dn_alg fifo_desc = {
107 _SI( .type = ) DN_SCHED_FIFO,
108 _SI( .name = ) "FIFO",
111 _SI( .schk_datalen = ) 0,
112 _SI( .si_datalen = ) sizeof(struct dn_queue),
113 _SI( .q_datalen = ) 0,
115 _SI( .enqueue = ) fifo_enqueue,
116 _SI( .dequeue = ) fifo_dequeue,
117 _SI( .config = ) NULL,
118 _SI( .destroy = ) NULL,
119 _SI( .new_sched = ) fifo_new_sched,
120 _SI( .free_sched = ) fifo_free_sched,
121 _SI( .new_fsk = ) NULL,
122 _SI( .free_fsk = ) NULL,
123 _SI( .new_queue = ) NULL,
124 _SI( .free_queue = ) NULL,
126 _SI( .getconfig = ) NULL,
130 DECLARE_DNSCHED_MODULE(dn_fifo, &fifo_desc);