/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2010 Riccardo Panicucci, Universita` di Pisa4* All rights reserved5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/*29*/3031#ifdef _KERNEL32#include <sys/malloc.h>33#include <sys/socket.h>34#include <sys/socketvar.h>35#include <sys/kernel.h>36#include <sys/lock.h>37#include <sys/mbuf.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>48#ifdef NEW_AQM49#include <netpfil/ipfw/dn_aqm.h>50#endif51#include <netpfil/ipfw/dn_sched.h>52#else53#include <dn_test.h>54#endif5556/*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 stores60* queue size and policy.61* Enqueue and dequeue use the default library functions.62*/63static int64fifo_enqueue(struct dn_sch_inst *si, struct dn_queue *q, struct mbuf *m)65{66/* XXX if called with q != NULL and m=NULL, this is a67* re-enqueue from an existing scheduler, which we should68* handle.69*/70(void)q;71return dn_enqueue((struct dn_queue *)(si+1), m, 0);72}7374static struct mbuf *75fifo_dequeue(struct dn_sch_inst *si)76{77return dn_dequeue((struct dn_queue *)(si + 1));78}7980static int81fifo_new_sched(struct dn_sch_inst *si)82{83/* This scheduler instance contains the queue */84struct dn_queue *q = (struct dn_queue *)(si + 1);8586set_oid(&q->ni.oid, DN_QUEUE, sizeof(*q));87q->_si = si;88q->fs = si->sched->fs;89return 0;90}9192static int93fifo_free_sched(struct dn_sch_inst *si)94{95struct dn_queue *q = (struct dn_queue *)(si + 1);96dn_free_pkts(q->mq.head);97bzero(q, sizeof(*q));98return 0;99}100101/*102* FIFO scheduler descriptor103* contains the type of the scheduler, the name, the size of extra104* data structures, and function pointers.105*/106static struct dn_alg fifo_desc = {107_SI( .type = ) DN_SCHED_FIFO,108_SI( .name = ) "FIFO",109_SI( .flags = ) 0,110111_SI( .schk_datalen = ) 0,112_SI( .si_datalen = ) sizeof(struct dn_queue),113_SI( .q_datalen = ) 0,114115_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,125#ifdef NEW_AQM126_SI( .getconfig = ) NULL,127#endif128};129130DECLARE_DNSCHED_MODULE(dn_fifo, &fifo_desc);131132133