dn_sched_fifo.c revision 301772
1/*
2 * Copyright (c) 2010 Riccardo Panicucci, Universita` di Pisa
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 */
26
27/*
28 * $FreeBSD: stable/10/sys/netpfil/ipfw/dn_sched_fifo.c 301772 2016-06-10 00:00:25Z truckman $
29 */
30
31#ifdef _KERNEL
32#include <sys/malloc.h>
33#include <sys/socket.h>
34#include <sys/socketvar.h>
35#include <sys/kernel.h>
36#include <sys/mbuf.h>
37#include <sys/module.h>
38#include <net/if.h>	/* IFNAMSIZ */
39#include <netinet/in.h>
40#include <netinet/ip_var.h>		/* ipfw_rule_ref */
41#include <netinet/ip_fw.h>	/* flow_id */
42#include <netinet/ip_dummynet.h>
43#include <netpfil/ipfw/dn_heap.h>
44#include <netpfil/ipfw/ip_dn_private.h>
45#ifdef NEW_AQM
46#include <netpfil/ipfw/dn_aqm.h>
47#endif
48#include <netpfil/ipfw/dn_sched.h>
49#else
50#include <dn_test.h>
51#endif
52
53/*
54 * This file implements a FIFO scheduler for a single queue.
55 * The queue is allocated as part of the scheduler instance,
56 * and there is a single flowset is in the template which stores
57 * queue size and policy.
58 * Enqueue and dequeue use the default library functions.
59 */
60static int
61fifo_enqueue(struct dn_sch_inst *si, struct dn_queue *q, struct mbuf *m)
62{
63	/* XXX if called with q != NULL and m=NULL, this is a
64	 * re-enqueue from an existing scheduler, which we should
65	 * handle.
66	 */
67	return dn_enqueue((struct dn_queue *)(si+1), m, 0);
68}
69
70static struct mbuf *
71fifo_dequeue(struct dn_sch_inst *si)
72{
73	return dn_dequeue((struct dn_queue *)(si + 1));
74}
75
76static int
77fifo_new_sched(struct dn_sch_inst *si)
78{
79	/* This scheduler instance contains the queue */
80	struct dn_queue *q = (struct dn_queue *)(si + 1);
81
82        set_oid(&q->ni.oid, DN_QUEUE, sizeof(*q));
83	q->_si = si;
84	q->fs = si->sched->fs;
85	return 0;
86}
87
88static int
89fifo_free_sched(struct dn_sch_inst *si)
90{
91	struct dn_queue *q = (struct dn_queue *)(si + 1);
92	dn_free_pkts(q->mq.head);
93	bzero(q, sizeof(*q));
94	return 0;
95}
96
97/*
98 * FIFO scheduler descriptor
99 * contains the type of the scheduler, the name, the size of extra
100 * data structures, and function pointers.
101 */
102static struct dn_alg fifo_desc = {
103	_SI( .type = )  DN_SCHED_FIFO,
104	_SI( .name = )  "FIFO",
105	_SI( .flags = ) 0,
106
107	_SI( .schk_datalen = ) 0,
108	_SI( .si_datalen = )  sizeof(struct dn_queue),
109	_SI( .q_datalen = )  0,
110
111	_SI( .enqueue = )  fifo_enqueue,
112	_SI( .dequeue = )  fifo_dequeue,
113	_SI( .config = )  NULL,
114	_SI( .destroy = )  NULL,
115	_SI( .new_sched = )  fifo_new_sched,
116	_SI( .free_sched = )  fifo_free_sched,
117	_SI( .new_fsk = )  NULL,
118	_SI( .free_fsk = )  NULL,
119	_SI( .new_queue = )  NULL,
120	_SI( .free_queue = )  NULL,
121#ifdef NEW_AQM
122	_SI( .getconfig = )  NULL,
123#endif
124};
125
126DECLARE_DNSCHED_MODULE(dn_fifo, &fifo_desc);
127