Add skeleton build dirs for pf userland:

libexec/ftp-proxy	- ftp proxy for pf
 sbin/pfctl		- equivalent to sbin/ipf
 sbin/pflogd		- deamon logging packets via if_pflog in pcap format
 usr.sbin/authpf	- authentification shell to modify pf rulesets

Bring along some altq headers used to satisfy pfctl/authpf compile. This
helps to keep the diff down and will make it easy to have a altq-patchset
use the full powers of pf.

Also make sure that the pf headers are installed.

This does not link anything to the build. There will be a NO_PF switch for
make.conf once pf userland is linked.

Approved by:	bms(mentor)
This commit is contained in:
mlaier 2004-02-28 21:50:50 +00:00
parent 4ca59f461b
commit 9c3431aab1
16 changed files with 2344 additions and 0 deletions

View File

@ -113,6 +113,9 @@ copies:
cd ${.CURDIR}/../sys/contrib/ipfilter/netinet; \
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/netinet
cd ${.CURDIR}/../sys/contrib/pf/net; \
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/net
cd ${.CURDIR}/../sys/opencrypto; \
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/crypto
@ -150,6 +153,11 @@ symlinks:
ln -fs ../../../sys/contrib/ipfilter/netinet/$$h \
${DESTDIR}${INCLUDEDIR}/netinet; \
done
cd ${.CURDIR}/../sys/contrib/pf/net; \
for h in *.h; do \
ln -fs ../../../sys/contrib/pf/net/$$h \
${DESTDIR}${INCLUDEDIR}/net; \
done
cd ${.CURDIR}/../sys/opencrypto; \
for h in *.h; do \
ln -fs ../../../sys/opencrypto/$$h \

View File

@ -0,0 +1,12 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../contrib/pf/ftp-proxy
PROG= ftp-proxy
MAN= ftp-proxy.8
SRCS= ftp-proxy.c getline.c util.c
CFLAGS+= -Wall -Werror
.include <bsd.prog.mk>

25
sbin/pfctl/Makefile Normal file
View File

@ -0,0 +1,25 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../contrib/pf/pfctl
.PATH: ${.CURDIR}/../../contrib/pf/man
PROG= pfctl
BINDIR= ${PREFIX}/sbin
MAN= pfctl.8 pf.4 pflog.4 pfsync.4 pf.conf.5 pf.os.5
SRCS = pfctl.c parse.y pfctl_parser.c pf_print_state.c pfctl_altq.c
SRCS+= pfctl_osfp.c pfctl_radix.c pfctl_table.c pfctl_qstats.c
CFLAGS+= -Wall -Wmissing-prototypes -Wno-uninitialized
CFLAGS+= -Wstrict-prototypes -I${.CURDIR}/../../contrib/pf/pfctl
# XXX ALTQ
#CFLAGS+= -DENABLE_ALTQ
CFLAGS+= -I${.CURDIR}/missing
YFLAGS=
LDADD+= -lm -lmd
DPADD+= ${LIBM}
.include <bsd.prog.mk>

View File

@ -0,0 +1,204 @@
/* $FreeBSD$ */
/* $KAME: altq.h,v 1.10 2003/07/10 12:07:47 kjc Exp $ */
/*
* Copyright (C) 1998-2003
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_H_
#define _ALTQ_ALTQ_H_
#if 0
/*
* allow altq-3 (altqd(8) and /dev/altq) to coexist with the new pf-based altq.
* altq3 is mainly for research experiments. pf-based altq is for daily use.
*/
#define ALTQ3_COMPAT /* for compatibility with altq-3 */
#define ALTQ3_CLFIER_COMPAT /* for compatibility with altq-3 classifier */
#endif
#ifdef ALTQ3_COMPAT
#include <sys/param.h>
#include <sys/ioccom.h>
#include <sys/queue.h>
#include <netinet/in.h>
#ifndef IFNAMSIZ
#define IFNAMSIZ 16
#endif
#endif /* ALTQ3_COMPAT */
/* altq discipline type */
#define ALTQT_NONE 0 /* reserved */
#define ALTQT_CBQ 1 /* cbq */
#define ALTQT_WFQ 2 /* wfq */
#define ALTQT_AFMAP 3 /* afmap */
#define ALTQT_FIFOQ 4 /* fifoq */
#define ALTQT_RED 5 /* red */
#define ALTQT_RIO 6 /* rio */
#define ALTQT_LOCALQ 7 /* local use */
#define ALTQT_HFSC 8 /* hfsc */
#define ALTQT_CDNR 9 /* traffic conditioner */
#define ALTQT_BLUE 10 /* blue */
#define ALTQT_PRIQ 11 /* priority queue */
#define ALTQT_JOBS 12 /* JoBS */
#define ALTQT_MAX 13 /* should be max discipline type + 1 */
#ifdef ALTQ3_COMPAT
struct altqreq {
char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */
u_long arg; /* request-specific argument */
};
#endif
/* simple token backet meter profile */
struct tb_profile {
u_int rate; /* rate in bit-per-sec */
u_int depth; /* depth in bytes */
};
#ifdef ALTQ3_COMPAT
struct tbrreq {
char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */
struct tb_profile tb_prof; /* token bucket profile */
};
#ifdef ALTQ3_CLFIER_COMPAT
/*
* common network flow info structure
*/
struct flowinfo {
u_char fi_len; /* total length */
u_char fi_family; /* address family */
u_int8_t fi_data[46]; /* actually longer; address family
specific flow info. */
};
/*
* flow info structure for internet protocol family.
* (currently this is the only protocol family supported)
*/
struct flowinfo_in {
u_char fi_len; /* sizeof(struct flowinfo_in) */
u_char fi_family; /* AF_INET */
u_int8_t fi_proto; /* IPPROTO_XXX */
u_int8_t fi_tos; /* type-of-service */
struct in_addr fi_dst; /* dest address */
struct in_addr fi_src; /* src address */
u_int16_t fi_dport; /* dest port */
u_int16_t fi_sport; /* src port */
u_int32_t fi_gpi; /* generalized port id for ipsec */
u_int8_t _pad[28]; /* make the size equal to
flowinfo_in6 */
};
#ifdef SIN6_LEN
struct flowinfo_in6 {
u_char fi6_len; /* sizeof(struct flowinfo_in6) */
u_char fi6_family; /* AF_INET6 */
u_int8_t fi6_proto; /* IPPROTO_XXX */
u_int8_t fi6_tclass; /* traffic class */
u_int32_t fi6_flowlabel; /* ipv6 flowlabel */
u_int16_t fi6_dport; /* dest port */
u_int16_t fi6_sport; /* src port */
u_int32_t fi6_gpi; /* generalized port id */
struct in6_addr fi6_dst; /* dest address */
struct in6_addr fi6_src; /* src address */
};
#endif /* INET6 */
/*
* flow filters for AF_INET and AF_INET6
*/
struct flow_filter {
int ff_ruleno;
struct flowinfo_in ff_flow;
struct {
struct in_addr mask_dst;
struct in_addr mask_src;
u_int8_t mask_tos;
u_int8_t _pad[3];
} ff_mask;
u_int8_t _pad2[24]; /* make the size equal to flow_filter6 */
};
#ifdef SIN6_LEN
struct flow_filter6 {
int ff_ruleno;
struct flowinfo_in6 ff_flow6;
struct {
struct in6_addr mask6_dst;
struct in6_addr mask6_src;
u_int8_t mask6_tclass;
u_int8_t _pad[3];
} ff_mask6;
};
#endif /* INET6 */
#endif /* ALTQ3_CLFIER_COMPAT */
#endif /* ALTQ3_COMPAT */
/*
* generic packet counter
*/
struct pktcntr {
u_int64_t packets;
u_int64_t bytes;
};
#define PKTCNTR_ADD(cntr, len) \
do { (cntr)->packets++; (cntr)->bytes += len; } while (/*CONSTCOND*/ 0)
#ifdef ALTQ3_COMPAT
/*
* altq related ioctls
*/
#define ALTQGTYPE _IOWR('q', 0, struct altqreq) /* get queue type */
#if 0
/*
* these ioctls are currently discipline-specific but could be shared
* in the future.
*/
#define ALTQATTACH _IOW('q', 1, struct altqreq) /* attach discipline */
#define ALTQDETACH _IOW('q', 2, struct altqreq) /* detach discipline */
#define ALTQENABLE _IOW('q', 3, struct altqreq) /* enable discipline */
#define ALTQDISABLE _IOW('q', 4, struct altqreq) /* disable discipline*/
#define ALTQCLEAR _IOW('q', 5, struct altqreq) /* (re)initialize */
#define ALTQCONFIG _IOWR('q', 6, struct altqreq) /* set config params */
#define ALTQADDCLASS _IOWR('q', 7, struct altqreq) /* add a class */
#define ALTQMODCLASS _IOWR('q', 8, struct altqreq) /* modify a class */
#define ALTQDELCLASS _IOWR('q', 9, struct altqreq) /* delete a class */
#define ALTQADDFILTER _IOWR('q', 10, struct altqreq) /* add a filter */
#define ALTQDELFILTER _IOWR('q', 11, struct altqreq) /* delete a filter */
#define ALTQGETSTATS _IOWR('q', 12, struct altqreq) /* get statistics */
#define ALTQGETCNTR _IOWR('q', 13, struct altqreq) /* get a pkt counter */
#endif /* 0 */
#define ALTQTBRSET _IOW('q', 14, struct tbrreq) /* set tb regulator */
#define ALTQTBRGET _IOWR('q', 15, struct tbrreq) /* get tb regulator */
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
#include <altq/altq_var.h>
#endif
#endif /* _ALTQ_ALTQ_H_ */

View File

@ -0,0 +1,232 @@
/* $FreeBSD$ */
/* $KAME: altq_cbq.h,v 1.10 2003/08/20 23:30:23 itojun Exp $ */
/*
* Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the SMCC Technology
* Development Group at Sun Microsystems, Inc.
*
* 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
* SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is
* provided "as is" without express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this software.
*/
#ifndef _ALTQ_ALTQ_CBQ_H_
#define _ALTQ_ALTQ_CBQ_H_
#include <altq/altq.h>
#include <altq/altq_rmclass.h>
#include <altq/altq_red.h>
#include <altq/altq_rio.h>
/* #pragma ident "@(#)cbq.h 1.18 98/05/13 SMI" */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Define a well known class handles
*/
#define NULL_CLASS_HANDLE 0xffffffff
#define ROOT_CLASS_HANDLE 0xfffffffe
#define DEFAULT_CLASS_HANDLE 0xfffffffd
#ifdef ALTQ3_COMPAT
#define CTL_CLASS_HANDLE 0xfffffffc
#endif
/* class flags shoud be same as class flags in rm_class.h */
#define CBQCLF_RED 0x0001 /* use RED */
#define CBQCLF_ECN 0x0002 /* use RED/ECN */
#define CBQCLF_RIO 0x0004 /* use RIO */
#define CBQCLF_FLOWVALVE 0x0008 /* use flowvalve (aka penalty-box) */
#define CBQCLF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
#define CBQCLF_BORROW 0x0020 /* borrow from parent */
/* class flags only for root class */
#define CBQCLF_WRR 0x0100 /* weighted-round robin */
#define CBQCLF_EFFICIENT 0x0200 /* work-conserving */
/* class flags for special classes */
#define CBQCLF_ROOTCLASS 0x1000 /* root class */
#define CBQCLF_DEFCLASS 0x2000 /* default class */
#ifdef ALTQ3_COMPAT
#define CBQCLF_CTLCLASS 0x4000 /* control class */
#endif
#define CBQCLF_CLASSMASK 0xf000 /* class mask */
#define CBQ_MAXQSIZE 200
#define CBQ_MAXPRI RM_MAXPRIO
typedef struct _cbq_class_stats_ {
u_int32_t handle;
u_int depth;
struct pktcntr xmit_cnt; /* packets sent in this class */
struct pktcntr drop_cnt; /* dropped packets */
u_int over; /* # times went over limit */
u_int borrows; /* # times tried to borrow */
u_int overactions; /* # times invoked overlimit action */
u_int delays; /* # times invoked delay actions */
/* other static class parameters useful for debugging */
int priority;
int maxidle;
int minidle;
int offtime;
int qmax;
int ns_per_byte;
int wrr_allot;
int qcnt; /* # packets in queue */
int avgidle;
/* red and rio related info */
int qtype;
struct redstats red[3];
} class_stats_t;
#ifdef ALTQ3_COMPAT
/*
* Define structures associated with IOCTLS for cbq.
*/
/*
* Define the CBQ interface structure. This must be included in all
* IOCTL's such that the CBQ driver may find the appropriate CBQ module
* associated with the network interface to be affected.
*/
struct cbq_interface {
char cbq_ifacename[IFNAMSIZ];
};
typedef struct cbq_class_spec {
u_int priority;
u_int nano_sec_per_byte;
u_int maxq;
u_int maxidle;
int minidle;
u_int offtime;
u_int32_t parent_class_handle;
u_int32_t borrow_class_handle;
u_int pktsize;
int flags;
} cbq_class_spec_t;
struct cbq_add_class {
struct cbq_interface cbq_iface;
cbq_class_spec_t cbq_class;
u_int32_t cbq_class_handle;
};
struct cbq_delete_class {
struct cbq_interface cbq_iface;
u_int32_t cbq_class_handle;
};
struct cbq_modify_class {
struct cbq_interface cbq_iface;
cbq_class_spec_t cbq_class;
u_int32_t cbq_class_handle;
};
struct cbq_add_filter {
struct cbq_interface cbq_iface;
u_int32_t cbq_class_handle;
struct flow_filter cbq_filter;
u_long cbq_filter_handle;
};
struct cbq_delete_filter {
struct cbq_interface cbq_iface;
u_long cbq_filter_handle;
};
/* number of classes are returned in nclasses field */
struct cbq_getstats {
struct cbq_interface iface;
int nclasses;
class_stats_t *stats;
};
/*
* Define IOCTLs for CBQ.
*/
#define CBQ_IF_ATTACH _IOW('Q', 1, struct cbq_interface)
#define CBQ_IF_DETACH _IOW('Q', 2, struct cbq_interface)
#define CBQ_ENABLE _IOW('Q', 3, struct cbq_interface)
#define CBQ_DISABLE _IOW('Q', 4, struct cbq_interface)
#define CBQ_CLEAR_HIERARCHY _IOW('Q', 5, struct cbq_interface)
#define CBQ_ADD_CLASS _IOWR('Q', 7, struct cbq_add_class)
#define CBQ_DEL_CLASS _IOW('Q', 8, struct cbq_delete_class)
#define CBQ_MODIFY_CLASS _IOWR('Q', 9, struct cbq_modify_class)
#define CBQ_ADD_FILTER _IOWR('Q', 10, struct cbq_add_filter)
#define CBQ_DEL_FILTER _IOW('Q', 11, struct cbq_delete_filter)
#define CBQ_GETSTATS _IOWR('Q', 12, struct cbq_getstats)
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
/*
* Define macros only good for kernel drivers and modules.
*/
#define CBQ_WATCHDOG (hz / 20)
#define CBQ_TIMEOUT 10
#define CBQ_LS_TIMEOUT (20 * hz / 1000)
#define CBQ_MAX_CLASSES 256
#ifdef ALTQ3_COMPAT
#define CBQ_MAX_FILTERS 256
#define DISABLE 0x00
#define ENABLE 0x01
#endif /* ALTQ3_COMPAT */
/*
* Define State structures.
*/
typedef struct cbqstate {
#ifdef ALTQ3_COMPAT
struct cbqstate *cbq_next;
#endif
int cbq_qlen; /* # of packets in cbq */
struct rm_class *cbq_class_tbl[CBQ_MAX_CLASSES];
struct rm_ifdat ifnp;
struct callout cbq_callout; /* for timeouts */
#ifdef ALTQ3_CLFIER_COMPAT
struct acc_classifier cbq_classifier;
#endif
} cbq_state_t;
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* !_ALTQ_ALTQ_CBQ_H_ */

View File

@ -0,0 +1,207 @@
/* $FreeBSD$ */
/* $KAME: altq_classq.h,v 1.6 2003/01/07 07:33:38 kjc Exp $ */
/*
* Copyright (c) 1991-1997 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Network Research
* Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* class queue definitions extracted from rm_class.h.
*/
#ifndef _ALTQ_ALTQ_CLASSQ_H_
#define _ALTQ_ALTQ_CLASSQ_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* Packet Queue types: RED or DROPHEAD.
*/
#define Q_DROPHEAD 0x00
#define Q_RED 0x01
#define Q_RIO 0x02
#define Q_DROPTAIL 0x03
#ifdef _KERNEL
/*
* Packet Queue structures and macros to manipulate them.
*/
struct _class_queue_ {
struct mbuf *tail_; /* Tail of packet queue */
int qlen_; /* Queue length (in number of packets) */
int qlim_; /* Queue limit (in number of packets*) */
int qtype_; /* Queue type */
};
typedef struct _class_queue_ class_queue_t;
#define qtype(q) (q)->qtype_ /* Get queue type */
#define qlimit(q) (q)->qlim_ /* Max packets to be queued */
#define qlen(q) (q)->qlen_ /* Current queue length. */
#define qtail(q) (q)->tail_ /* Tail of the queue */
#define qhead(q) ((q)->tail_ ? (q)->tail_->m_nextpkt : NULL)
#define qempty(q) ((q)->qlen_ == 0) /* Is the queue empty?? */
#define q_is_red(q) ((q)->qtype_ == Q_RED) /* Is the queue a red queue */
#define q_is_rio(q) ((q)->qtype_ == Q_RIO) /* Is the queue a rio queue */
#define q_is_red_or_rio(q) ((q)->qtype_ == Q_RED || (q)->qtype_ == Q_RIO)
#if !defined(__GNUC__) || defined(ALTQ_DEBUG)
extern void _addq(class_queue_t *, struct mbuf *);
extern struct mbuf *_getq(class_queue_t *);
extern struct mbuf *_getq_tail(class_queue_t *);
extern struct mbuf *_getq_random(class_queue_t *);
extern void _removeq(class_queue_t *, struct mbuf *);
extern void _flushq(class_queue_t *);
#else /* __GNUC__ && !ALTQ_DEBUG */
/*
* inlined versions
*/
static __inline void
_addq(class_queue_t *q, struct mbuf *m)
{
struct mbuf *m0;
if ((m0 = qtail(q)) != NULL)
m->m_nextpkt = m0->m_nextpkt;
else
m0 = m;
m0->m_nextpkt = m;
qtail(q) = m;
qlen(q)++;
}
static __inline struct mbuf *
_getq(class_queue_t *q)
{
struct mbuf *m, *m0;
if ((m = qtail(q)) == NULL)
return (NULL);
if ((m0 = m->m_nextpkt) != m)
m->m_nextpkt = m0->m_nextpkt;
else
qtail(q) = NULL;
qlen(q)--;
m0->m_nextpkt = NULL;
return (m0);
}
/* drop a packet at the tail of the queue */
static __inline struct mbuf *
_getq_tail(class_queue_t *q)
{
struct mbuf *m, *m0, *prev;
if ((m = m0 = qtail(q)) == NULL)
return NULL;
do {
prev = m0;
m0 = m0->m_nextpkt;
} while (m0 != m);
prev->m_nextpkt = m->m_nextpkt;
if (prev == m)
qtail(q) = NULL;
else
qtail(q) = prev;
qlen(q)--;
m->m_nextpkt = NULL;
return (m);
}
/* randomly select a packet in the queue */
static __inline struct mbuf *
_getq_random(class_queue_t *q)
{
struct mbuf *m;
int i, n;
if ((m = qtail(q)) == NULL)
return NULL;
if (m->m_nextpkt == m)
qtail(q) = NULL;
else {
struct mbuf *prev = NULL;
n = random() % qlen(q) + 1;
for (i = 0; i < n; i++) {
prev = m;
m = m->m_nextpkt;
}
prev->m_nextpkt = m->m_nextpkt;
if (m == qtail(q))
qtail(q) = prev;
}
qlen(q)--;
m->m_nextpkt = NULL;
return (m);
}
static __inline void
_removeq(class_queue_t *q, struct mbuf *m)
{
struct mbuf *m0, *prev;
m0 = qtail(q);
do {
prev = m0;
m0 = m0->m_nextpkt;
} while (m0 != m);
prev->m_nextpkt = m->m_nextpkt;
if (prev == m)
qtail(q) = NULL;
else if (qtail(q) == m)
qtail(q) = prev;
qlen(q)--;
}
static __inline void
_flushq(class_queue_t *q)
{
struct mbuf *m;
while ((m = _getq(q)) != NULL)
m_freem(m);
}
#endif /* __GNUC__ && !ALTQ_DEBUG */
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _ALTQ_ALTQ_CLASSQ_H_ */

View File

@ -0,0 +1,325 @@
/* $FreeBSD$ */
/* $KAME: altq_hfsc.h,v 1.10 2003/07/10 12:07:48 kjc Exp $ */
/*
* Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation is hereby granted (including for commercial or
* for-profit use), provided that both the copyright notice and this
* permission notice appear in all copies of the software, derivative
* works, or modified versions, and any portions thereof, and that
* both notices appear in supporting documentation, and that credit
* is given to Carnegie Mellon University in all publications reporting
* on direct or indirect use of this code or its derivatives.
*
* THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
* WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
* SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Carnegie Mellon encourages (but does not require) users of this
* software to return any improvements or extensions that they make,
* and to grant Carnegie Mellon the rights to redistribute these
* changes without encumbrance.
*/
#ifndef _ALTQ_ALTQ_HFSC_H_
#define _ALTQ_ALTQ_HFSC_H_
#include <altq/altq.h>
#include <altq/altq_classq.h>
#include <altq/altq_red.h>
#include <altq/altq_rio.h>
#ifdef __cplusplus
extern "C" {
#endif
struct service_curve {
u_int m1; /* slope of the first segment in bits/sec */
u_int d; /* the x-projection of the first segment in msec */
u_int m2; /* slope of the second segment in bits/sec */
};
/* special class handles */
#define HFSC_NULLCLASS_HANDLE 0
#define HFSC_ROOTCLASS_HANDLE 1
#define HFSC_MAX_CLASSES 64
/* hfsc class flags */
#define HFCF_RED 0x0001 /* use RED */
#define HFCF_ECN 0x0002 /* use RED/ECN */
#define HFCF_RIO 0x0004 /* use RIO */
#define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
#define HFCF_DEFAULTCLASS 0x1000 /* default class */
/* service curve types */
#define HFSC_REALTIMESC 1
#define HFSC_LINKSHARINGSC 2
#define HFSC_UPPERLIMITSC 4
#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
struct hfsc_classstats {
u_int class_id;
u_int32_t class_handle;
struct service_curve rsc;
struct service_curve fsc;
struct service_curve usc; /* upper limit service curve */
u_int64_t total; /* total work in bytes */
u_int64_t cumul; /* cumulative work in bytes
done by real-time criteria */
u_int64_t d; /* deadline */
u_int64_t e; /* eligible time */
u_int64_t vt; /* virtual time */
u_int64_t f; /* fit time for upper-limit */
/* info helpful for debugging */
u_int64_t initvt; /* init virtual time */
u_int64_t vtoff; /* cl_vt_ipoff */
u_int64_t cvtmax; /* cl_maxvt */
u_int64_t myf; /* cl_myf */
u_int64_t cfmin; /* cl_mincf */
u_int64_t cvtmin; /* cl_mincvt */
u_int64_t myfadj; /* cl_myfadj */
u_int64_t vtadj; /* cl_vtadj */
u_int64_t cur_time;
u_int32_t machclk_freq;
u_int qlength;
u_int qlimit;
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
u_int period;
u_int vtperiod; /* vt period sequence no */
u_int parentperiod; /* parent's vt period seqno */
int nactive; /* number of active children */
/* red and rio related info */
int qtype;
struct redstats red[3];
};
#ifdef ALTQ3_COMPAT
struct hfsc_interface {
char hfsc_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
};
struct hfsc_attach {
struct hfsc_interface iface;
u_int bandwidth; /* link bandwidth in bits/sec */
};
struct hfsc_add_class {
struct hfsc_interface iface;
u_int32_t parent_handle;
struct service_curve service_curve;
int qlimit;
int flags;
u_int32_t class_handle; /* return value */
};
struct hfsc_delete_class {
struct hfsc_interface iface;
u_int32_t class_handle;
};
struct hfsc_modify_class {
struct hfsc_interface iface;
u_int32_t class_handle;
struct service_curve service_curve;
int sctype;
};
struct hfsc_add_filter {
struct hfsc_interface iface;
u_int32_t class_handle;
struct flow_filter filter;
u_long filter_handle; /* return value */
};
struct hfsc_delete_filter {
struct hfsc_interface iface;
u_long filter_handle;
};
struct hfsc_class_stats {
struct hfsc_interface iface;
int nskip; /* skip # of classes */
int nclasses; /* # of class stats (WR) */
u_int64_t cur_time; /* current time */
u_int32_t machclk_freq; /* machine clock frequency */
u_int hif_classes; /* # of classes in the tree */
u_int hif_packets; /* # of packets in the tree */
struct hfsc_classstats *stats; /* pointer to stats array */
};
#define HFSC_IF_ATTACH _IOW('Q', 1, struct hfsc_attach)
#define HFSC_IF_DETACH _IOW('Q', 2, struct hfsc_interface)
#define HFSC_ENABLE _IOW('Q', 3, struct hfsc_interface)
#define HFSC_DISABLE _IOW('Q', 4, struct hfsc_interface)
#define HFSC_CLEAR_HIERARCHY _IOW('Q', 5, struct hfsc_interface)
#define HFSC_ADD_CLASS _IOWR('Q', 7, struct hfsc_add_class)
#define HFSC_DEL_CLASS _IOW('Q', 8, struct hfsc_delete_class)
#define HFSC_MOD_CLASS _IOW('Q', 9, struct hfsc_modify_class)
#define HFSC_ADD_FILTER _IOWR('Q', 10, struct hfsc_add_filter)
#define HFSC_DEL_FILTER _IOW('Q', 11, struct hfsc_delete_filter)
#define HFSC_GETSTATS _IOWR('Q', 12, struct hfsc_class_stats)
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
/*
* kernel internal service curve representation
* coordinates are given by 64 bit unsigned integers.
* x-axis: unit is clock count. for the intel x86 architecture,
* the raw Pentium TSC (Timestamp Counter) value is used.
* virtual time is also calculated in this time scale.
* y-axis: unit is byte.
*
* the service curve parameters are converted to the internal
* representation.
* the slope values are scaled to avoid overflow.
* the inverse slope values as well as the y-projection of the 1st
* segment are kept in order to to avoid 64-bit divide operations
* that are expensive on 32-bit architectures.
*
* note: Intel Pentium TSC never wraps around in several thousands of years.
* x-axis doesn't wrap around for 1089 years with 1GHz clock.
* y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth.
*/
/* kernel internal representation of a service curve */
struct internal_sc {
u_int64_t sm1; /* scaled slope of the 1st segment */
u_int64_t ism1; /* scaled inverse-slope of the 1st segment */
u_int64_t dx; /* the x-projection of the 1st segment */
u_int64_t dy; /* the y-projection of the 1st segment */
u_int64_t sm2; /* scaled slope of the 2nd segment */
u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */
};
/* runtime service curve */
struct runtime_sc {
u_int64_t x; /* current starting position on x-axis */
u_int64_t y; /* current starting position on x-axis */
u_int64_t sm1; /* scaled slope of the 1st segment */
u_int64_t ism1; /* scaled inverse-slope of the 1st segment */
u_int64_t dx; /* the x-projection of the 1st segment */
u_int64_t dy; /* the y-projection of the 1st segment */
u_int64_t sm2; /* scaled slope of the 2nd segment */
u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */
};
/* for TAILQ based ellist and actlist implementation */
struct hfsc_class;
typedef TAILQ_HEAD(_eligible, hfsc_class) ellist_t;
typedef TAILQ_ENTRY(hfsc_class) elentry_t;
typedef TAILQ_HEAD(_active, hfsc_class) actlist_t;
typedef TAILQ_ENTRY(hfsc_class) actentry_t;
#define ellist_first(s) TAILQ_FIRST(s)
#define actlist_first(s) TAILQ_FIRST(s)
#define actlist_last(s) TAILQ_LAST(s, _active)
struct hfsc_class {
u_int cl_id; /* class id (just for debug) */
u_int32_t cl_handle; /* class handle */
struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */
int cl_flags; /* misc flags */
struct hfsc_class *cl_parent; /* parent class */
struct hfsc_class *cl_siblings; /* sibling classes */
struct hfsc_class *cl_children; /* child classes */
class_queue_t *cl_q; /* class queue structure */
struct red *cl_red; /* RED state */
struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
u_int64_t cl_total; /* total work in bytes */
u_int64_t cl_cumul; /* cumulative work in bytes
done by real-time criteria */
u_int64_t cl_d; /* deadline */
u_int64_t cl_e; /* eligible time */
u_int64_t cl_vt; /* virtual time */
u_int64_t cl_f; /* time when this class will fit for
link-sharing, max(myf, cfmin) */
u_int64_t cl_myf; /* my fit-time (as calculated from this
class's own upperlimit curve) */
u_int64_t cl_myfadj; /* my fit-time adjustment
(to cancel history dependence) */
u_int64_t cl_cfmin; /* earliest children's fit-time (used
with cl_myf to obtain cl_f) */
u_int64_t cl_cvtmin; /* minimal virtual time among the
children fit for link-sharing
(monotonic within a period) */
u_int64_t cl_vtadj; /* intra-period cumulative vt
adjustment */
u_int64_t cl_vtoff; /* inter-period cumulative vt offset */
u_int64_t cl_cvtmax; /* max child's vt in the last period */
u_int64_t cl_initvt; /* init virtual time (for debugging) */
struct internal_sc *cl_rsc; /* internal real-time service curve */
struct internal_sc *cl_fsc; /* internal fair service curve */
struct internal_sc *cl_usc; /* internal upperlimit service curve */
struct runtime_sc cl_deadline; /* deadline curve */
struct runtime_sc cl_eligible; /* eligible curve */
struct runtime_sc cl_virtual; /* virtual curve */
struct runtime_sc cl_ulimit; /* upperlimit curve */
u_int cl_vtperiod; /* vt period sequence no */
u_int cl_parentperiod; /* parent's vt period seqno */
int cl_nactive; /* number of active children */
actlist_t *cl_actc; /* active children list */
actentry_t cl_actlist; /* active children list entry */
elentry_t cl_ellist; /* eligible list entry */
struct {
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
u_int period;
} cl_stats;
};
/*
* hfsc interface state
*/
struct hfsc_if {
struct hfsc_if *hif_next; /* interface state list */
struct ifaltq *hif_ifq; /* backpointer to ifaltq */
struct hfsc_class *hif_rootclass; /* root class */
struct hfsc_class *hif_defaultclass; /* default class */
struct hfsc_class *hif_class_tbl[HFSC_MAX_CLASSES];
struct hfsc_class *hif_pollcache; /* cache for poll operation */
u_int hif_classes; /* # of classes in the tree */
u_int hif_packets; /* # of packets in the tree */
u_int hif_classid; /* class id sequence number */
ellist_t *hif_eligible; /* eligible list */
#ifdef ALTQ3_CLFIER_COMPAT
struct acc_classifier hif_classifier;
#endif
};
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _ALTQ_ALTQ_HFSC_H_ */

View File

@ -0,0 +1,172 @@
/* $FreeBSD$ */
/* $KAME: altq_priq.h,v 1.5 2003/07/10 12:07:48 kjc Exp $ */
/*
* Copyright (C) 2000-2003
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_PRIQ_H_
#define _ALTQ_ALTQ_PRIQ_H_
#include <altq/altq.h>
#include <altq/altq_classq.h>
#include <altq/altq_red.h>
#include <altq/altq_rio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PRIQ_MAXPRI 16 /* upper limit of the number of priorities */
#define PRIQ_MAXQID 256 /* upper limit of queues */
#ifdef ALTQ3_COMPAT
struct priq_interface {
char ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
u_long arg; /* request-specific argument */
};
struct priq_add_class {
struct priq_interface iface;
int pri; /* priority (0 is the lowest) */
int qlimit; /* queue size limit */
int flags; /* misc flags (see below) */
u_int32_t class_handle; /* return value */
};
#endif /* ALTQ3_COMPAT */
/* priq class flags */
#define PRCF_RED 0x0001 /* use RED */
#define PRCF_ECN 0x0002 /* use RED/ECN */
#define PRCF_RIO 0x0004 /* use RIO */
#define PRCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
#define PRCF_DEFAULTCLASS 0x1000 /* default class */
/* special class handles */
#define PRIQ_NULLCLASS_HANDLE 0
#ifdef ALTQ3_COMPAT
struct priq_delete_class {
struct priq_interface iface;
u_int32_t class_handle;
};
struct priq_modify_class {
struct priq_interface iface;
u_int32_t class_handle;
int pri;
int qlimit;
int flags;
};
struct priq_add_filter {
struct priq_interface iface;
u_int32_t class_handle;
struct flow_filter filter;
u_long filter_handle; /* return value */
};
struct priq_delete_filter {
struct priq_interface iface;
u_long filter_handle;
};
#endif /* ALTQ3_COMPAT */
struct priq_classstats {
u_int32_t class_handle;
u_int qlength;
u_int qlimit;
u_int period;
struct pktcntr xmitcnt; /* transmitted packet counter */
struct pktcntr dropcnt; /* dropped packet counter */
/* red and rio related info */
int qtype;
struct redstats red[3]; /* rio has 3 red stats */
};
#ifdef ALTQ3_COMPAT
struct priq_class_stats {
struct priq_interface iface;
int maxpri; /* in/out */
struct priq_classstats *stats; /* pointer to stats array */
};
#define PRIQ_IF_ATTACH _IOW('Q', 1, struct priq_interface)
#define PRIQ_IF_DETACH _IOW('Q', 2, struct priq_interface)
#define PRIQ_ENABLE _IOW('Q', 3, struct priq_interface)
#define PRIQ_DISABLE _IOW('Q', 4, struct priq_interface)
#define PRIQ_CLEAR _IOW('Q', 5, struct priq_interface)
#define PRIQ_ADD_CLASS _IOWR('Q', 7, struct priq_add_class)
#define PRIQ_DEL_CLASS _IOW('Q', 8, struct priq_delete_class)
#define PRIQ_MOD_CLASS _IOW('Q', 9, struct priq_modify_class)
#define PRIQ_ADD_FILTER _IOWR('Q', 10, struct priq_add_filter)
#define PRIQ_DEL_FILTER _IOW('Q', 11, struct priq_delete_filter)
#define PRIQ_GETSTATS _IOWR('Q', 12, struct priq_class_stats)
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
struct priq_class {
u_int32_t cl_handle; /* class handle */
class_queue_t *cl_q; /* class queue structure */
struct red *cl_red; /* RED state */
int cl_pri; /* priority */
int cl_flags; /* class flags */
struct priq_if *cl_pif; /* back pointer to pif */
struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
/* statistics */
u_int cl_period; /* backlog period */
struct pktcntr cl_xmitcnt; /* transmitted packet counter */
struct pktcntr cl_dropcnt; /* dropped packet counter */
};
/*
* priq interface state
*/
struct priq_if {
struct priq_if *pif_next; /* interface state list */
struct ifaltq *pif_ifq; /* backpointer to ifaltq */
u_int pif_bandwidth; /* link bandwidth in bps */
int pif_maxpri; /* max priority in use */
struct priq_class *pif_default; /* default class */
struct priq_class *pif_classes[PRIQ_MAXPRI]; /* classes */
#ifdef ALTQ3_CLFIER_COMPAT
struct acc_classifier pif_classifier; /* classifier */
#endif
};
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _ALTQ_ALTQ_PRIQ_H_ */

View File

@ -0,0 +1,199 @@
/* $FreeBSD$ */
/* $KAME: altq_red.h,v 1.8 2003/07/10 12:07:49 kjc Exp $ */
/*
* Copyright (C) 1997-2003
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_RED_H_
#define _ALTQ_ALTQ_RED_H_
#include <altq/altq_classq.h>
#ifdef ALTQ3_COMPAT
struct red_interface {
char red_ifname[IFNAMSIZ];
};
struct red_stats {
struct red_interface iface;
int q_len;
int q_avg;
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
u_int drop_forced;
u_int drop_unforced;
u_int marked_packets;
/* static red parameters */
int q_limit;
int weight;
int inv_pmax;
int th_min;
int th_max;
/* flowvalve related stuff */
u_int fv_flows;
u_int fv_pass;
u_int fv_predrop;
u_int fv_alloc;
u_int fv_escape;
};
struct red_conf {
struct red_interface iface;
int red_weight; /* weight for EWMA */
int red_inv_pmax; /* inverse of max drop probability */
int red_thmin; /* red min threshold */
int red_thmax; /* red max threshold */
int red_limit; /* max queue length */
int red_pkttime; /* average packet time in usec */
int red_flags; /* see below */
};
#endif /* ALTQ3_COMPAT */
/* red flags */
#define REDF_ECN4 0x01 /* use packet marking for IPv4 packets */
#define REDF_ECN6 0x02 /* use packet marking for IPv6 packets */
#define REDF_ECN (REDF_ECN4 | REDF_ECN6)
#define REDF_FLOWVALVE 0x04 /* use flowvalve (aka penalty-box) */
/*
* simpler versions of red parameters and statistics used by other
* disciplines (e.g., CBQ)
*/
struct redparams {
int th_min; /* red min threshold */
int th_max; /* red max threshold */
int inv_pmax; /* inverse of max drop probability */
};
struct redstats {
int q_avg;
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
u_int drop_forced;
u_int drop_unforced;
u_int marked_packets;
};
#ifdef ALTQ3_COMPAT
/*
* IOCTLs for RED
*/
#define RED_IF_ATTACH _IOW('Q', 1, struct red_interface)
#define RED_IF_DETACH _IOW('Q', 2, struct red_interface)
#define RED_ENABLE _IOW('Q', 3, struct red_interface)
#define RED_DISABLE _IOW('Q', 4, struct red_interface)
#define RED_CONFIG _IOWR('Q', 6, struct red_conf)
#define RED_GETSTATS _IOWR('Q', 12, struct red_stats)
#define RED_SETDEFAULTS _IOW('Q', 30, struct redparams)
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
#ifdef ALTQ3_COMPAT
struct flowvalve;
#endif
/* weight table structure for idle time calibration */
struct wtab {
struct wtab *w_next;
int w_weight;
int w_param_max;
int w_refcount;
int32_t w_tab[32];
};
typedef struct red {
int red_pkttime; /* average packet time in micro sec
used for idle calibration */
int red_flags; /* red flags */
/* red parameters */
int red_weight; /* weight for EWMA */
int red_inv_pmax; /* inverse of max drop probability */
int red_thmin; /* red min threshold */
int red_thmax; /* red max threshold */
/* variables for internal use */
int red_wshift; /* log(red_weight) */
int red_thmin_s; /* th_min scaled by avgshift */
int red_thmax_s; /* th_max scaled by avgshift */
int red_probd; /* drop probability denominator */
int red_avg; /* queue len avg scaled by avgshift */
int red_count; /* packet count since last dropped/
marked packet */
int red_idle; /* queue was empty */
int red_old; /* avg is above th_min */
struct wtab *red_wtab; /* weight table */
struct timeval red_last; /* time when the queue becomes idle */
#ifdef ALTQ3_COMPAT
struct flowvalve *red_flowvalve; /* flowvalve state */
#endif
struct {
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
u_int drop_forced;
u_int drop_unforced;
u_int marked_packets;
} red_stats;
} red_t;
#ifdef ALTQ3_COMPAT
typedef struct red_queue {
struct red_queue *rq_next; /* next red_state in the list */
struct ifaltq *rq_ifq; /* backpointer to ifaltq */
class_queue_t *rq_q;
red_t *rq_red;
} red_queue_t;
#endif /* ALTQ3_COMPAT */
/* red drop types */
#define DTYPE_NODROP 0 /* no drop */
#define DTYPE_FORCED 1 /* a "forced" drop */
#define DTYPE_EARLY 2 /* an "unforced" (early) drop */
extern red_t *red_alloc(int, int, int, int, int, int);
extern void red_destroy(red_t *);
extern void red_getstats(red_t *, struct redstats *);
extern int red_addq(red_t *, class_queue_t *, struct mbuf *,
struct altq_pktattr *);
extern struct mbuf *red_getq(red_t *, class_queue_t *);
extern int drop_early(int, int, int);
extern int mark_ecn(struct mbuf *, struct altq_pktattr *, int);
extern struct wtab *wtab_alloc(int);
extern int wtab_destroy(struct wtab *);
extern int32_t pow_w(struct wtab *, int);
#endif /* _KERNEL */
#endif /* _ALTQ_ALTQ_RED_H_ */

View File

@ -0,0 +1,145 @@
/* $FreeBSD$ */
/* $KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $ */
/*
* Copyright (C) 1998-2003
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_RIO_H_
#define _ALTQ_ALTQ_RIO_H_
#include <altq/altq_classq.h>
/*
* RIO: RED with IN/OUT bit
* (extended to support more than 2 drop precedence values)
*/
#define RIO_NDROPPREC 3 /* number of drop precedence values */
#ifdef ALTQ3_COMPAT
struct rio_interface {
char rio_ifname[IFNAMSIZ];
};
struct rio_stats {
struct rio_interface iface;
int q_len[RIO_NDROPPREC];
struct redstats q_stats[RIO_NDROPPREC];
/* static red parameters */
int q_limit;
int weight;
int flags;
struct redparams q_params[RIO_NDROPPREC];
};
struct rio_conf {
struct rio_interface iface;
struct redparams q_params[RIO_NDROPPREC];
int rio_weight; /* weight for EWMA */
int rio_limit; /* max queue length */
int rio_pkttime; /* average packet time in usec */
int rio_flags; /* see below */
};
#endif /* ALTQ3_COMPAT */
/* rio flags */
#define RIOF_ECN4 0x01 /* use packet marking for IPv4 packets */
#define RIOF_ECN6 0x02 /* use packet marking for IPv6 packets */
#define RIOF_ECN (RIOF_ECN4 | RIOF_ECN6)
#define RIOF_CLEARDSCP 0x200 /* clear diffserv codepoint */
#ifdef ALTQ3_COMPAT
/*
* IOCTLs for RIO
*/
#define RIO_IF_ATTACH _IOW('Q', 1, struct rio_interface)
#define RIO_IF_DETACH _IOW('Q', 2, struct rio_interface)
#define RIO_ENABLE _IOW('Q', 3, struct rio_interface)
#define RIO_DISABLE _IOW('Q', 4, struct rio_interface)
#define RIO_CONFIG _IOWR('Q', 6, struct rio_conf)
#define RIO_GETSTATS _IOWR('Q', 12, struct rio_stats)
#define RIO_SETDEFAULTS _IOW('Q', 30, struct redparams[RIO_NDROPPREC])
#endif /* ALTQ3_COMPAT */
#ifdef _KERNEL
typedef struct rio {
/* per drop precedence structure */
struct dropprec_state {
/* red parameters */
int inv_pmax; /* inverse of max drop probability */
int th_min; /* red min threshold */
int th_max; /* red max threshold */
/* variables for internal use */
int th_min_s; /* th_min scaled by avgshift */
int th_max_s; /* th_max scaled by avgshift */
int probd; /* drop probability denominator */
int qlen; /* queue length */
int avg; /* (scaled) queue length average */
int count; /* packet count since the last dropped/
marked packet */
int idle; /* queue was empty */
int old; /* avg is above th_min */
struct timeval last; /* timestamp when queue becomes idle */
} rio_precstate[RIO_NDROPPREC];
int rio_wshift; /* log(red_weight) */
int rio_weight; /* weight for EWMA */
struct wtab *rio_wtab; /* weight table */
int rio_pkttime; /* average packet time in micro sec
used for idle calibration */
int rio_flags; /* rio flags */
u_int8_t rio_codepoint; /* codepoint value to tag packets */
u_int8_t rio_codepointmask; /* codepoint mask bits */
struct redstats q_stats[RIO_NDROPPREC]; /* statistics */
} rio_t;
#ifdef ALTQ3_COMPAT
typedef struct rio_queue {
struct rio_queue *rq_next; /* next red_state in the list */
struct ifaltq *rq_ifq; /* backpointer to ifaltq */
class_queue_t *rq_q;
rio_t *rq_rio;
} rio_queue_t;
#endif /* ALTQ3_COMPAT */
extern rio_t *rio_alloc(int, struct redparams *, int, int);
extern void rio_destroy(rio_t *);
extern void rio_getstats(rio_t *, struct redstats *);
extern int rio_addq(rio_t *, class_queue_t *, struct mbuf *,
struct altq_pktattr *);
extern struct mbuf *rio_getq(rio_t *, class_queue_t *);
#endif /* _KERNEL */
#endif /* _ALTQ_ALTQ_RIO_H_ */

View File

@ -0,0 +1,267 @@
/* $FreeBSD$ */
/* $KAME: altq_rmclass.h,v 1.10 2003/08/20 23:30:23 itojun Exp $ */
/*
* Copyright (c) 1991-1997 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Network Research
* Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_RMCLASS_H_
#define _ALTQ_ALTQ_RMCLASS_H_
#include <altq/altq_classq.h>
/* #pragma ident "@(#)rm_class.h 1.20 97/10/23 SMI" */
#ifdef __cplusplus
extern "C" {
#endif
#define RM_MAXPRIO 8 /* Max priority */
#ifdef _KERNEL
typedef struct mbuf mbuf_t;
typedef struct rm_ifdat rm_ifdat_t;
typedef struct rm_class rm_class_t;
struct red;
/*
* Macros for dealing with time values. We assume all times are
* 'timevals'. `microtime' is used to get the best available clock
* resolution. If `microtime' *doesn't* return a value that's about
* ten times smaller than the average packet time on the fastest
* link that will use these routines, a slightly different clock
* scheme than this one should be used.
* (Bias due to truncation error in this scheme will overestimate utilization
* and discriminate against high bandwidth classes. To remove this bias an
* integrator needs to be added. The simplest integrator uses a history of
* 10 * avg.packet.time / min.tick.time packet completion entries. This is
* straight forward to add but we don't want to pay the extra memory
* traffic to maintain it if it's not necessary (occasionally a vendor
* accidentally builds a workstation with a decent clock - e.g., Sun & HP).)
*/
#define RM_GETTIME(now) microtime(&now)
#define TV_LT(a, b) (((a)->tv_sec < (b)->tv_sec) || \
(((a)->tv_usec < (b)->tv_usec) && ((a)->tv_sec <= (b)->tv_sec)))
#define TV_DELTA(a, b, delta) { \
register int xxs; \
\
delta = (a)->tv_usec - (b)->tv_usec; \
if ((xxs = (a)->tv_sec - (b)->tv_sec)) { \
switch (xxs) { \
default: \
/* if (xxs < 0) \
printf("rm_class: bogus time values\n"); */ \
delta = 0; \
/* fall through */ \
case 2: \
delta += 1000000; \
/* fall through */ \
case 1: \
delta += 1000000; \
break; \
} \
} \
}
#define TV_ADD_DELTA(a, delta, res) { \
register int xxus = (a)->tv_usec + (delta); \
\
(res)->tv_sec = (a)->tv_sec; \
while (xxus >= 1000000) { \
++((res)->tv_sec); \
xxus -= 1000000; \
} \
(res)->tv_usec = xxus; \
}
#define RM_TIMEOUT 2 /* 1 Clock tick. */
#if 1
#define RM_MAXQUEUED 1 /* this isn't used in ALTQ/CBQ */
#else
#define RM_MAXQUEUED 16 /* Max number of packets downstream of CBQ */
#endif
#define RM_MAXQUEUE 64 /* Max queue length */
#define RM_FILTER_GAIN 5 /* log2 of gain, e.g., 5 => 31/32 */
#define RM_POWER (1 << RM_FILTER_GAIN)
#define RM_MAXDEPTH 32
#define RM_NS_PER_SEC (1000000000)
typedef struct _rm_class_stats_ {
u_int handle;
u_int depth;
struct pktcntr xmit_cnt; /* packets sent in this class */
struct pktcntr drop_cnt; /* dropped packets */
u_int over; /* # times went over limit */
u_int borrows; /* # times tried to borrow */
u_int overactions; /* # times invoked overlimit action */
u_int delays; /* # times invoked delay actions */
} rm_class_stats_t;
/*
* CBQ Class state structure
*/
struct rm_class {
class_queue_t *q_; /* Queue of packets */
rm_ifdat_t *ifdat_;
int pri_; /* Class priority. */
int depth_; /* Class depth */
u_int ns_per_byte_; /* NanoSeconds per byte. */
u_int maxrate_; /* Bytes per second for this class. */
u_int allotment_; /* Fraction of link bandwidth. */
u_int w_allotment_; /* Weighted allotment for WRR */
int bytes_alloc_; /* Allocation for round of WRR */
int avgidle_;
int maxidle_;
int minidle_;
int offtime_;
int sleeping_; /* != 0 if delaying */
int qthresh_; /* Queue threshold for formal link sharing */
int leaf_; /* Note whether leaf class or not.*/
rm_class_t *children_; /* Children of this class */
rm_class_t *next_; /* Next pointer, used if child */
rm_class_t *peer_; /* Peer class */
rm_class_t *borrow_; /* Borrow class */
rm_class_t *parent_; /* Parent class */
void (*overlimit)(struct rm_class *, struct rm_class *);
void (*drop)(struct rm_class *); /* Class drop action. */
struct red *red_; /* RED state pointer */
struct altq_pktattr *pktattr_; /* saved hdr used by RED/ECN */
int flags_;
int last_pkttime_; /* saved pkt_time */
struct timeval undertime_; /* time can next send */
struct timeval last_; /* time last packet sent */
struct timeval overtime_;
struct callout callout_; /* for timeout() calls */
rm_class_stats_t stats_; /* Class Statistics */
};
/*
* CBQ Interface state
*/
struct rm_ifdat {
int queued_; /* # pkts queued downstream */
int efficient_; /* Link Efficency bit */
int wrr_; /* Enable Weighted Round-Robin */
u_long ns_per_byte_; /* Link byte speed. */
int maxqueued_; /* Max packets to queue */
int maxpkt_; /* Max packet size. */
int qi_; /* In/out pointers for downstream */
int qo_; /* packets */
/*
* Active class state and WRR state.
*/
rm_class_t *active_[RM_MAXPRIO]; /* Active cl's in each pri */
int na_[RM_MAXPRIO]; /* # of active cl's in a pri */
int num_[RM_MAXPRIO]; /* # of cl's per pri */
int alloc_[RM_MAXPRIO]; /* Byte Allocation */
u_long M_[RM_MAXPRIO]; /* WRR weights. */
/*
* Network Interface/Solaris Queue state pointer.
*/
struct ifaltq *ifq_;
rm_class_t *default_; /* Default Pkt class, BE */
rm_class_t *root_; /* Root Link class. */
rm_class_t *ctl_; /* Control Traffic class. */
void (*restart)(struct ifaltq *); /* Restart routine. */
/*
* Current packet downstream packet state and dynamic state.
*/
rm_class_t *borrowed_[RM_MAXQUEUED]; /* Class borrowed last */
rm_class_t *class_[RM_MAXQUEUED]; /* class sending */
int curlen_[RM_MAXQUEUED]; /* Current pktlen */
struct timeval now_[RM_MAXQUEUED]; /* Current packet time. */
int is_overlimit_[RM_MAXQUEUED];/* Current packet time. */
int cutoff_; /* Cut-off depth for borrowing */
struct timeval ifnow_; /* expected xmit completion time */
#if 1 /* ALTQ4PPP */
int maxiftime_; /* max delay inside interface */
#endif
rm_class_t *pollcache_; /* cached rm_class by poll operation */
};
/* flags for rmc_init and rmc_newclass */
/* class flags */
#define RMCF_RED 0x0001
#define RMCF_ECN 0x0002
#define RMCF_RIO 0x0004
#define RMCF_FLOWVALVE 0x0008 /* use flowvalve (aka penalty-box) */
#define RMCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
/* flags for rmc_init */
#define RMCF_WRR 0x0100
#define RMCF_EFFICIENT 0x0200
#define is_a_parent_class(cl) ((cl)->children_ != NULL)
extern rm_class_t *rmc_newclass(int, struct rm_ifdat *, u_int,
void (*)(struct rm_class *, struct rm_class *),
int, struct rm_class *, struct rm_class *,
u_int, int, u_int, int, int);
extern void rmc_delete_class(struct rm_ifdat *, struct rm_class *);
extern int rmc_modclass(struct rm_class *, u_int, int,
u_int, int, u_int, int);
extern void rmc_init(struct ifaltq *, struct rm_ifdat *, u_int,
void (*)(struct ifaltq *),
int, int, u_int, int, u_int, int);
extern int rmc_queue_packet(struct rm_class *, mbuf_t *);
extern mbuf_t *rmc_dequeue_next(struct rm_ifdat *, int);
extern void rmc_update_class_util(struct rm_ifdat *);
extern void rmc_delay_action(struct rm_class *, struct rm_class *);
extern void rmc_dropall(struct rm_class *);
extern int rmc_get_weight(struct rm_ifdat *, int);
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _ALTQ_ALTQ_RMCLASS_H_ */

View File

@ -0,0 +1,113 @@
/* $FreeBSD$ */
/* $KAME: altq_rmclass_debug.h,v 1.3 2002/11/29 04:36:24 kjc Exp $ */
/*
* Copyright (c) Sun Microsystems, Inc. 1998 All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the SMCC Technology
* Development Group at Sun Microsystems, Inc.
*
* 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
* SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is
* provided "as is" without express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this software.
*/
#ifndef _ALTQ_ALTQ_RMCLASS_DEBUG_H_
#define _ALTQ_ALTQ_RMCLASS_DEBUG_H_
/* #pragma ident "@(#)rm_class_debug.h 1.7 98/05/04 SMI" */
/*
* Cbq debugging macros
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CBQ_TRACE
#ifndef NCBQTRACE
#define NCBQTRACE (16 * 1024)
#endif
/*
* To view the trace output, using adb, type:
* adb -k /dev/ksyms /dev/mem <cr>, then type
* cbqtrace_count/D to get the count, then type
* cbqtrace_buffer,0tcount/Dp4C" "Xn
* This will dump the trace buffer from 0 to count.
*/
/*
* in ALTQ, "call cbqtrace_dump(N)" from DDB to display 20 events
* from Nth event in the circular buffer.
*/
struct cbqtrace {
int count;
int function; /* address of function */
int trace_action; /* descriptive 4 characters */
int object; /* object operated on */
};
extern struct cbqtrace cbqtrace_buffer[];
extern struct cbqtrace *cbqtrace_ptr;
extern int cbqtrace_count;
#define CBQTRACEINIT() { \
if (cbqtrace_ptr == NULL) \
cbqtrace_ptr = cbqtrace_buffer; \
else { \
cbqtrace_ptr = cbqtrace_buffer; \
bzero((void *)cbqtrace_ptr, sizeof(cbqtrace_buffer)); \
cbqtrace_count = 0; \
} \
}
#define LOCK_TRACE() splimp()
#define UNLOCK_TRACE(x) splx(x)
#define CBQTRACE(func, act, obj) { \
int __s = LOCK_TRACE(); \
int *_p = &cbqtrace_ptr->count; \
*_p++ = ++cbqtrace_count; \
*_p++ = (int)(func); \
*_p++ = (int)(act); \
*_p++ = (int)(obj); \
if ((struct cbqtrace *)(void *)_p >= &cbqtrace_buffer[NCBQTRACE])\
cbqtrace_ptr = cbqtrace_buffer; \
else \
cbqtrace_ptr = (struct cbqtrace *)(void *)_p; \
UNLOCK_TRACE(__s); \
}
#else
/* If no tracing, define no-ops */
#define CBQTRACEINIT()
#define CBQTRACE(a, b, c)
#endif /* !CBQ_TRACE */
#ifdef __cplusplus
}
#endif
#endif /* _ALTQ_ALTQ_RMCLASS_DEBUG_H_ */

View File

@ -0,0 +1,267 @@
/* $FreeBSD$ */
/* $KAME: altq_var.h,v 1.15 2003/07/10 12:07:49 kjc Exp $ */
/*
* Copyright (C) 1998-2003
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ALTQ_ALTQ_VAR_H_
#define _ALTQ_ALTQ_VAR_H_
#ifdef _KERNEL
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/queue.h>
#ifdef ALTQ3_CLFIER_COMPAT
/*
* filter structure for altq common classifier
*/
struct acc_filter {
LIST_ENTRY(acc_filter) f_chain;
void *f_class; /* pointer to the class */
u_long f_handle; /* filter id */
u_int32_t f_fbmask; /* filter bitmask */
struct flow_filter f_filter; /* filter value */
};
/*
* XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix
* the handle assignment.
*/
#define ACC_FILTER_TABLESIZE (256+1)
#define ACC_FILTER_MASK (ACC_FILTER_TABLESIZE - 2)
#define ACC_WILDCARD_INDEX (ACC_FILTER_TABLESIZE - 1)
#ifdef __GNUC__
#define ACC_GET_HASH_INDEX(addr) \
({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;})
#else
#define ACC_GET_HASH_INDEX(addr) \
(((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \
& ACC_FILTER_MASK)
#endif
#define ACC_GET_HINDEX(handle) ((handle) >> 20)
#if (__FreeBSD_version > 500000)
#define ACC_LOCK_INIT(ac) mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF)
#define ACC_LOCK_DESTROY(ac) mtx_destroy(&(ac)->acc_mtx)
#define ACC_LOCK(ac) mtx_lock(&(ac)->acc_mtx)
#define ACC_UNLOCK(ac) mtx_unlock(&(ac)->acc_mtx)
#else
#define ACC_LOCK_INIT(ac)
#define ACC_LOCK_DESTROY(ac)
#define ACC_LOCK(ac)
#define ACC_UNLOCK(ac)
#endif
struct acc_classifier {
u_int32_t acc_fbmask;
LIST_HEAD(filt, acc_filter) acc_filters[ACC_FILTER_TABLESIZE];
#if (__FreeBSD_version > 500000)
struct mtx acc_mtx;
#endif
};
/*
* flowinfo mask bits used by classifier
*/
/* for ipv4 */
#define FIMB4_PROTO 0x0001
#define FIMB4_TOS 0x0002
#define FIMB4_DADDR 0x0004
#define FIMB4_SADDR 0x0008
#define FIMB4_DPORT 0x0010
#define FIMB4_SPORT 0x0020
#define FIMB4_GPI 0x0040
#define FIMB4_ALL 0x007f
/* for ipv6 */
#define FIMB6_PROTO 0x0100
#define FIMB6_TCLASS 0x0200
#define FIMB6_DADDR 0x0400
#define FIMB6_SADDR 0x0800
#define FIMB6_DPORT 0x1000
#define FIMB6_SPORT 0x2000
#define FIMB6_GPI 0x4000
#define FIMB6_FLABEL 0x8000
#define FIMB6_ALL 0xff00
#define FIMB_ALL (FIMB4_ALL|FIMB6_ALL)
#define FIMB4_PORTS (FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI)
#define FIMB6_PORTS (FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI)
#endif /* ALTQ3_CLFIER_COMPAT */
/*
* machine dependent clock
* a 64bit high resolution time counter.
*/
extern int machclk_usepcc;
extern u_int32_t machclk_freq;
extern u_int32_t machclk_per_tick;
extern void init_machclk(void);
extern u_int64_t read_machclk(void);
/*
* debug support
*/
#ifdef ALTQ_DEBUG
#ifdef __STDC__
#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e))
#else /* PCC */
#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e"))
#endif
#else
#define ASSERT(e) ((void)0)
#endif
/*
* misc stuff for compatibility
*/
/* ioctl cmd type */
#if defined(__FreeBSD__) && (__FreeBSD__ < 3)
typedef int ioctlcmd_t;
#else
typedef u_long ioctlcmd_t;
#endif
/*
* queue macros:
* the interface of TAILQ_LAST macro changed after the introduction
* of softupdate. redefine it here to make it work with pre-2.2.7.
*/
#undef TAILQ_LAST
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
#ifndef TAILQ_EMPTY
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#endif
#ifndef TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field) \
for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
#endif
/* macro for timeout/untimeout */
#if (__FreeBSD_version > 300000) || defined(__NetBSD__)
/* use callout */
#include <sys/callout.h>
#if (__FreeBSD_version > 500000)
#define CALLOUT_INIT(c) callout_init((c), 0)
#else
#define CALLOUT_INIT(c) callout_init((c))
#endif
#define CALLOUT_RESET(c,t,f,a) callout_reset((c),(t),(f),(a))
#define CALLOUT_STOP(c) callout_stop((c))
#ifndef CALLOUT_INITIALIZER
#define CALLOUT_INITIALIZER { { { NULL } }, 0, NULL, NULL, 0 }
#endif
#elif defined(__OpenBSD__)
#include <sys/timeout.h>
/* callout structure as a wrapper of struct timeout */
struct callout {
struct timeout c_to;
};
#define CALLOUT_INIT(c) do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0)
#define CALLOUT_RESET(c,t,f,a) do { if (!timeout_initialized(&(c)->c_to)) \
timeout_set(&(c)->c_to, (f), (a)); \
timeout_add(&(c)->c_to, (t)); } while (/*CONSTCOND*/ 0)
#define CALLOUT_STOP(c) timeout_del(&(c)->c_to)
#define CALLOUT_INITIALIZER { { { NULL }, NULL, NULL, 0, 0 } }
#else
/* use old-style timeout/untimeout */
/* dummy callout structure */
struct callout {
void *c_arg; /* function argument */
void (*c_func)(void *); /* functiuon to call */
};
#define CALLOUT_INIT(c) do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0)
#define CALLOUT_RESET(c,t,f,a) do { (c)->c_arg = (a); \
(c)->c_func = (f); \
timeout((f),(a),(t)); } while (/*CONSTCOND*/ 0)
#define CALLOUT_STOP(c) untimeout((c)->c_func,(c)->c_arg)
#define CALLOUT_INITIALIZER { NULL, NULL }
#endif
#if !defined(__FreeBSD__)
typedef void (timeout_t)(void *);
#endif
#define m_pktlen(m) ((m)->m_pkthdr.len)
extern int pfaltq_running;
struct ifnet; struct mbuf;
struct pf_altq;
#ifdef ALTQ3_CLFIER_COMPAT
struct flowinfo;
#endif
void *altq_lookup(char *, int);
#ifdef ALTQ3_CLFIER_COMPAT
int altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t);
int acc_add_filter(struct acc_classifier *, struct flow_filter *,
void *, u_long *);
int acc_delete_filter(struct acc_classifier *, u_long);
int acc_discard_filters(struct acc_classifier *, void *, int);
void *acc_classify(void *, struct mbuf *, int);
#endif
u_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *);
void write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t);
void altq_assert(const char *, int, const char *);
int tbr_set(struct ifaltq *, struct tb_profile *);
int tbr_get(struct ifaltq *, struct tb_profile *);
int altq_pfattach(struct pf_altq *);
int altq_pfdetach(struct pf_altq *);
int altq_add(struct pf_altq *);
int altq_remove(struct pf_altq *);
int altq_add_queue(struct pf_altq *);
int altq_remove_queue(struct pf_altq *);
int altq_getqstats(struct pf_altq *, void *, int *);
int cbq_pfattach(struct pf_altq *);
int cbq_add_altq(struct pf_altq *);
int cbq_remove_altq(struct pf_altq *);
int cbq_add_queue(struct pf_altq *);
int cbq_remove_queue(struct pf_altq *);
int cbq_getqstats(struct pf_altq *, void *, int *);
int priq_pfattach(struct pf_altq *);
int priq_add_altq(struct pf_altq *);
int priq_remove_altq(struct pf_altq *);
int priq_add_queue(struct pf_altq *);
int priq_remove_queue(struct pf_altq *);
int priq_getqstats(struct pf_altq *, void *, int *);
int hfsc_pfattach(struct pf_altq *);
int hfsc_add_altq(struct pf_altq *);
int hfsc_remove_altq(struct pf_altq *);
int hfsc_add_queue(struct pf_altq *);
int hfsc_remove_queue(struct pf_altq *);
int hfsc_getqstats(struct pf_altq *, void *, int *);
#endif /* _KERNEL */
#endif /* _ALTQ_ALTQ_VAR_H_ */

View File

@ -0,0 +1,129 @@
/* $FreeBSD$ */
/* $KAME: altq_wfq.h,v 1.8 2003/07/10 12:07:49 kjc Exp $ */
/*
* Copyright (C) 1997-2002
* Sony Computer Science Laboratories Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* March 27, 1997. Written by Hiroshi Kyusojin of Keio University
* (kyu@mt.cs.keio.ac.jp).
*/
#ifndef _ALTQ_ALTQ_WFQ_H_
#define _ALTQ_ALTQ_WFQ_H_
#include <altq/altq.h>
#define DEFAULT_QSIZE 256
#define MAX_QSIZE 2048
struct wfq_interface{
char wfq_ifacename[IFNAMSIZ];
};
struct wfq_getqid{
struct wfq_interface iface;
#ifdef ALTQ3_CLFIER_COMPAT
struct flowinfo flow;
#endif
u_long qid;
};
struct wfq_setweight {
struct wfq_interface iface;
int qid;
int weight;
};
typedef struct each_queue_stats {
int bytes; /* bytes in this queue */
int weight; /* weight in percent */
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
} queue_stats;
struct wfq_getstats {
struct wfq_interface iface;
int qid;
queue_stats stats;
};
struct wfq_conf {
struct wfq_interface iface;
int hash_policy; /* hash policy */
int nqueues; /* number of queues */
int qlimit; /* queue size in bytes */
};
#define WFQ_HASH_DSTADDR 0 /* hash by dst address */
#define WFQ_HASH_SRCPORT 1 /* hash by src port */
#define WFQ_HASH_FULL 2 /* hash by all fields */
#define WFQ_IF_ATTACH _IOW('Q', 1, struct wfq_interface)
#define WFQ_IF_DETACH _IOW('Q', 2, struct wfq_interface)
#define WFQ_ENABLE _IOW('Q', 3, struct wfq_interface)
#define WFQ_DISABLE _IOW('Q', 4, struct wfq_interface)
#define WFQ_CONFIG _IOWR('Q', 6, struct wfq_conf)
#define WFQ_GET_STATS _IOWR('Q', 12, struct wfq_getstats)
#define WFQ_GET_QID _IOWR('Q', 30, struct wfq_getqid)
#define WFQ_SET_WEIGHT _IOWR('Q', 31, struct wfq_setweight)
#ifdef _KERNEL
#define HWM (64 * 1024)
#define WFQ_QUOTA 512 /* quota bytes to send at a time */
#define WFQ_ADDQUOTA(q) ((q)->quota += WFQ_QUOTA * (q)->weight / 100)
#define ENABLE 0
#define DISABLE 1
typedef struct weighted_fair_queue{
struct weighted_fair_queue *next, *prev;
struct mbuf *head, *tail;
int bytes; /* bytes in this queue */
int quota; /* bytes sent in this round */
int weight; /* weight in percent */
struct pktcntr xmit_cnt;
struct pktcntr drop_cnt;
} wfq;
typedef struct wfqstate {
struct wfqstate *next; /* for wfqstate list */
struct ifaltq *ifq;
int nums; /* number of queues */
int hwm; /* high water mark */
int bytes; /* total bytes in all the queues */
wfq *rrp; /* round robin pointer */
wfq *queue; /* pointer to queue list */
#ifdef ALTQ3_CLFIER_COMPAT
u_long (*hash_func)(struct flowinfo *, int);
#endif
u_int32_t fbmask; /* filter bitmask */
} wfq_state_t;
#endif /* _KERNEL */
#endif /* _ALTQ_ALTQ_WFQ_H */

13
sbin/pflogd/Makefile Normal file
View File

@ -0,0 +1,13 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../contrib/pf/pflogd
PROG= pflogd
SRCS= pflogd.c pidfile.c
MAN= pflogd.8
CFLAGS+=-Wall -Werror -Wmissing-prototypes -Wshadow
LDADD+= -lpcap -lutil
DPAPP+= ${LIBPCAP} ${LIBUTIL}
.include <bsd.prog.mk>

26
usr.sbin/authpf/Makefile Normal file
View File

@ -0,0 +1,26 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../contrib/pf/authpf
.PATH: ${.CURDIR}/../../contrib/pf/pfctl
PROG= authpf
MAN= authpf.8
BINOWN= root
BINGRP= authpf
BINMODE= 6555
SRCS= authpf.c parse.y pfctl_parser.c pf_print_state.c pfctl_altq.c
SRCS+= pfctl_radix.c pfctl_osfp.c
CFLAGS+= -I${.CURDIR}/../../contrib/pf/pfctl -Wall -Werror
# XXX ALTQ:
#CFLAGS+= -DENABLE_ALTQ
CFLAGS+= -I${.CURDIR}/../../sbin/pfctl/missing
LDADD+= -lm -lmd
DPADD+= ${LIBM} ${LIBMD}
CLEANFILES+=y.tab.h
.include <bsd.prog.mk>