Home | History | Annotate | Line # | Download | only in altq
if_altq.h revision 1.5.2.3
      1  1.5.2.3  bouyer /*	$NetBSD: if_altq.h,v 1.5.2.3 2001/02/11 19:08:30 bouyer Exp $	*/
      2  1.5.2.3  bouyer /*	$KAME: if_altq.h,v 1.6 2001/01/29 19:59:09 itojun Exp $	*/
      3  1.5.2.2  bouyer 
      4  1.5.2.2  bouyer /*
      5  1.5.2.2  bouyer  * Copyright (C) 1997-2000
      6  1.5.2.2  bouyer  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      7  1.5.2.2  bouyer  *
      8  1.5.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
      9  1.5.2.2  bouyer  * modification, are permitted provided that the following conditions
     10  1.5.2.2  bouyer  * are met:
     11  1.5.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     12  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     13  1.5.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     15  1.5.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     16  1.5.2.2  bouyer  *
     17  1.5.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     18  1.5.2.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.5.2.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.5.2.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     21  1.5.2.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  1.5.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  1.5.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.5.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  1.5.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  1.5.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  1.5.2.2  bouyer  * SUCH DAMAGE.
     28  1.5.2.2  bouyer  */
     29  1.5.2.2  bouyer #ifndef _ALTQ_IF_ALTQ_H_
     30  1.5.2.2  bouyer #define	_ALTQ_IF_ALTQ_H_
     31  1.5.2.2  bouyer 
     32  1.5.2.2  bouyer #ifdef _KERNEL
     33  1.5.2.2  bouyer #include <altq/altqconf.h>
     34  1.5.2.2  bouyer #endif
     35  1.5.2.2  bouyer 
     36  1.5.2.2  bouyer struct altq_pktattr; struct tb_regulator; struct top_cdnr;
     37  1.5.2.2  bouyer 
     38  1.5.2.2  bouyer /*
     39  1.5.2.2  bouyer  * Structure defining a queue for a network interface.
     40  1.5.2.2  bouyer  */
     41  1.5.2.2  bouyer struct	ifaltq {
     42  1.5.2.2  bouyer 	/* fields compatible with struct ifqueue */
     43  1.5.2.2  bouyer 	struct	mbuf *ifq_head;
     44  1.5.2.2  bouyer 	struct	mbuf *ifq_tail;
     45  1.5.2.2  bouyer 	int	ifq_len;
     46  1.5.2.2  bouyer 	int	ifq_maxlen;
     47  1.5.2.2  bouyer 	int	ifq_drops;
     48  1.5.2.2  bouyer 
     49  1.5.2.2  bouyer 	/* alternate queueing related fields */
     50  1.5.2.2  bouyer 	int	altq_type;		/* discipline type */
     51  1.5.2.2  bouyer 	int	altq_flags;		/* flags (e.g. ready, in-use) */
     52  1.5.2.2  bouyer 	void	*altq_disc;		/* for discipline-specific use */
     53  1.5.2.2  bouyer 	struct	ifnet *altq_ifp;	/* back pointer to interface */
     54  1.5.2.2  bouyer 
     55  1.5.2.3  bouyer 	int	(*altq_enqueue) __P((struct ifaltq *, struct mbuf *,
     56  1.5.2.2  bouyer 				     struct altq_pktattr *));
     57  1.5.2.3  bouyer 	struct	mbuf *(*altq_dequeue) __P((struct ifaltq *, int));
     58  1.5.2.3  bouyer 	int	(*altq_request) __P((struct ifaltq *, int, void *));
     59  1.5.2.2  bouyer 
     60  1.5.2.2  bouyer 	/* classifier fields */
     61  1.5.2.2  bouyer 	void	*altq_clfier;		/* classifier-specific use */
     62  1.5.2.2  bouyer 	void	*(*altq_classify) __P((void *, struct mbuf *, int));
     63  1.5.2.2  bouyer 
     64  1.5.2.2  bouyer 	/* token bucket regulator */
     65  1.5.2.2  bouyer 	struct	tb_regulator *altq_tbr;
     66  1.5.2.2  bouyer 
     67  1.5.2.2  bouyer 	/* input traffic conditioner (doesn't belong to the output queue...) */
     68  1.5.2.2  bouyer 	struct top_cdnr *altq_cdnr;
     69  1.5.2.2  bouyer };
     70  1.5.2.2  bouyer 
     71  1.5.2.2  bouyer 
     72  1.5.2.2  bouyer #ifdef _KERNEL
     73  1.5.2.2  bouyer 
     74  1.5.2.2  bouyer /*
     75  1.5.2.2  bouyer  * packet attributes used by queueing disciplines.
     76  1.5.2.2  bouyer  * pattr_class is a discipline-dependent scheduling class that is
     77  1.5.2.2  bouyer  * set by a classifier.
     78  1.5.2.2  bouyer  * pattr_hdr and pattr_af may be used by a discipline to access
     79  1.5.2.2  bouyer  * the header within a mbuf.  (e.g. ECN needs to update the CE bit)
     80  1.5.2.2  bouyer  * note that pattr_hdr could be stale after m_pullup, though link
     81  1.5.2.2  bouyer  * layer output routines usually don't use m_pullup.  link-level
     82  1.5.2.2  bouyer  * compression also invalidates these fields.  thus, pattr_hdr needs
     83  1.5.2.2  bouyer  * to be verified when a discipline touches the header.
     84  1.5.2.2  bouyer  */
     85  1.5.2.2  bouyer struct altq_pktattr {
     86  1.5.2.2  bouyer 	void	*pattr_class;		/* sched class set by classifier */
     87  1.5.2.2  bouyer 	int	pattr_af;		/* address family */
     88  1.5.2.2  bouyer 	caddr_t	pattr_hdr;		/* saved header position in mbuf */
     89  1.5.2.2  bouyer };
     90  1.5.2.2  bouyer 
     91  1.5.2.2  bouyer /*
     92  1.5.2.2  bouyer  * a token-bucket regulator limits the rate that a network driver can
     93  1.5.2.2  bouyer  * dequeue packets from the output queue.
     94  1.5.2.2  bouyer  * modern cards are able to buffer a large amount of packets and dequeue
     95  1.5.2.2  bouyer  * too many packets at a time.  this bursty dequeue behavior makes it
     96  1.5.2.2  bouyer  * impossible to schedule packets by queueing disciplines.
     97  1.5.2.2  bouyer  * a token-bucket is used to control the burst size in a device
     98  1.5.2.2  bouyer  * independent manner.
     99  1.5.2.2  bouyer  */
    100  1.5.2.2  bouyer struct tb_regulator {
    101  1.5.2.2  bouyer 	int64_t		tbr_rate;	/* (scaled) token bucket rate */
    102  1.5.2.2  bouyer 	int64_t		tbr_depth;	/* (scaled) token bucket depth */
    103  1.5.2.2  bouyer 
    104  1.5.2.2  bouyer 	int64_t		tbr_token;	/* (scaled) current token */
    105  1.5.2.2  bouyer 	int64_t		tbr_filluptime;	/* (scaled) time to fill up bucket */
    106  1.5.2.2  bouyer 	u_int64_t	tbr_last;	/* last time token was updated */
    107  1.5.2.2  bouyer 
    108  1.5.2.2  bouyer 	int		tbr_lastop;	/* last dequeue operation type
    109  1.5.2.2  bouyer 					   needed for poll-and-dequeue */
    110  1.5.2.2  bouyer };
    111  1.5.2.2  bouyer 
    112  1.5.2.2  bouyer /* if_altqflags */
    113  1.5.2.2  bouyer #define	ALTQF_READY	 0x01	/* driver supports alternate queueing */
    114  1.5.2.2  bouyer #define	ALTQF_ENABLED	 0x02	/* altq is in use */
    115  1.5.2.2  bouyer #define	ALTQF_CLASSIFY	 0x04	/* classify packets */
    116  1.5.2.2  bouyer #define	ALTQF_CNDTNING	 0x08	/* altq traffic conditioning is enabled */
    117  1.5.2.2  bouyer #define	ALTQF_DRIVER1	 0x40	/* driver specific */
    118  1.5.2.2  bouyer 
    119  1.5.2.2  bouyer /* if_altqflags set internally only: */
    120  1.5.2.2  bouyer #define	ALTQF_CANTCHANGE 	(ALTQF_READY)
    121  1.5.2.2  bouyer 
    122  1.5.2.2  bouyer /* altq_dequeue 2nd arg */
    123  1.5.2.2  bouyer #define	ALTDQ_REMOVE		1	/* dequeue mbuf from the queue */
    124  1.5.2.2  bouyer #define	ALTDQ_POLL		2	/* don't dequeue mbuf from the queue */
    125  1.5.2.2  bouyer 
    126  1.5.2.2  bouyer /* altq request types (currently only purge is defined) */
    127  1.5.2.2  bouyer #define	ALTRQ_PURGE		1	/* purge all packets */
    128  1.5.2.2  bouyer 
    129  1.5.2.2  bouyer #define	ALTQ_IS_READY(ifq)		((ifq)->altq_flags & ALTQF_READY)
    130  1.5.2.2  bouyer #define	ALTQ_IS_ENABLED(ifq)		((ifq)->altq_flags & ALTQF_ENABLED)
    131  1.5.2.2  bouyer #define	ALTQ_NEEDS_CLASSIFY(ifq)	((ifq)->altq_flags & ALTQF_CLASSIFY)
    132  1.5.2.2  bouyer #define	ALTQ_IS_CNDTNING(ifq)		((ifq)->altq_flags & ALTQF_CNDTNING)
    133  1.5.2.2  bouyer 
    134  1.5.2.2  bouyer #define	ALTQ_SET_CNDTNING(ifq)		((ifq)->altq_flags |= ALTQF_CNDTNING)
    135  1.5.2.2  bouyer #define	ALTQ_CLEAR_CNDTNING(ifq)	((ifq)->altq_flags &= ~ALTQF_CNDTNING)
    136  1.5.2.2  bouyer #define	ALTQ_IS_ATTACHED(ifq)		((ifq)->altq_disc != NULL)
    137  1.5.2.2  bouyer 
    138  1.5.2.2  bouyer #define	ALTQ_ENQUEUE(ifq, m, pa, err)					\
    139  1.5.2.2  bouyer 	(err) = (*(ifq)->altq_enqueue)((ifq),(m),(pa))
    140  1.5.2.2  bouyer #define	ALTQ_DEQUEUE(ifq, m)						\
    141  1.5.2.2  bouyer 	(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_REMOVE)
    142  1.5.2.2  bouyer #define	ALTQ_POLL(ifq, m)						\
    143  1.5.2.2  bouyer 	(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_POLL)
    144  1.5.2.2  bouyer #define	ALTQ_PURGE(ifq)							\
    145  1.5.2.2  bouyer 	(void)(*(ifq)->altq_request)((ifq), ALTRQ_PURGE, (void *)0)
    146  1.5.2.2  bouyer #define	ALTQ_IS_EMPTY(ifq)		((ifq)->ifq_len == 0)
    147  1.5.2.2  bouyer #define	TBR_IS_ENABLED(ifq)		((ifq)->altq_tbr != NULL)
    148  1.5.2.2  bouyer 
    149  1.5.2.2  bouyer extern int altq_attach __P((struct ifaltq *, int, void *,
    150  1.5.2.2  bouyer 			    int (*)(struct ifaltq *, struct mbuf *,
    151  1.5.2.2  bouyer 				    struct altq_pktattr *),
    152  1.5.2.2  bouyer 			    struct mbuf *(*)(struct ifaltq *, int),
    153  1.5.2.2  bouyer 			    int (*)(struct ifaltq *, int, void *),
    154  1.5.2.2  bouyer 			    void *,
    155  1.5.2.2  bouyer 			    void *(*)(void *, struct mbuf *, int)));
    156  1.5.2.2  bouyer extern int altq_detach __P((struct ifaltq *));
    157  1.5.2.2  bouyer extern int altq_enable __P((struct ifaltq *));
    158  1.5.2.2  bouyer extern int altq_disable __P((struct ifaltq *));
    159  1.5.2.2  bouyer extern struct mbuf *tbr_dequeue __P((struct ifaltq *, int));
    160  1.5.2.2  bouyer extern int (*altq_input) __P((struct mbuf *, int));
    161  1.5.2.2  bouyer 
    162  1.5.2.2  bouyer #endif /* _KERNEL */
    163  1.5.2.2  bouyer 
    164  1.5.2.2  bouyer #endif /* _ALTQ_IF_ALTQ_H_ */
    165