Home | History | Annotate | Line # | Download | only in altq
altq_flowvalve.h revision 1.3
      1 /*	$NetBSD: altq_flowvalve.h,v 1.3 2006/10/12 19:59:08 peter Exp $	*/
      2 /*	$KAME: altq_flowvalve.h,v 1.5 2002/04/03 05:38:50 kjc Exp $	*/
      3 
      4 /*
      5  * Copyright (C) 1998-2002
      6  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #ifndef _ALTQ_ALTQ_FLOWVALVE_H_
     31 #define	_ALTQ_ALTQ_FLOWVALVE_H_
     32 
     33 #ifdef _KERNEL
     34 
     35 /* fv_flow structure to define a unique address pair */
     36 struct fv_flow {
     37 	int flow_af;		/* address family */
     38 	union {
     39 		struct {
     40 			struct in_addr ip_src;
     41 			struct in_addr ip_dst;
     42 		} _ip;
     43 #ifdef INET6
     44 		struct {
     45 			struct in6_addr ip6_src;
     46 			struct in6_addr ip6_dst;
     47 		} _ip6;
     48 #endif
     49 	} flow_un;
     50 };
     51 
     52 #define	flow_ip		flow_un._ip
     53 #define	flow_ip6	flow_un._ip6
     54 
     55 /* flowvalve entry */
     56 struct fve {
     57 	TAILQ_ENTRY(fve) fve_lru;	/* for LRU list */
     58 
     59 	enum fv_state { Green, Red } fve_state;
     60 
     61 	int	fve_p;			/* scaled average drop rate */
     62 	int	fve_f;			/* scaled average fraction */
     63 	int	fve_count;		/* counter to update f */
     64 	u_int	fve_ifseq;		/* ifseq at the last update of f */
     65 	struct timeval	fve_lastdrop;	/* timestamp of the last drop */
     66 
     67 	struct fv_flow fve_flow;	/* unique address pair */
     68 };
     69 
     70 /* flowvalve structure */
     71 struct flowvalve {
     72 	u_int	fv_ifseq;	/* packet sequence number */
     73 	int	fv_flows;	/* number of valid flows in the flowlist */
     74 	int	fv_pthresh;	/* drop rate threshold */
     75 
     76 	TAILQ_HEAD(fv_flowhead, fve) fv_flowlist;		/* LRU list */
     77 
     78 	struct fve *fv_fves;	/* pointer to the allocated fves */
     79 
     80 	int	*fv_p2ftab;	/* drop rate to fraction table */
     81 
     82 	struct {
     83 		u_int	pass;		/* # of packets that have the fve
     84 					   but aren't predropped */
     85 		u_int	predrop;	/* # of packets predropped */
     86 		u_int	alloc;		/* # of fves assigned */
     87 		u_int	escape;		/* # of fves escaped */
     88 	} fv_stats;
     89 };
     90 
     91 #endif /* _KERNEL */
     92 
     93 #endif /* _ALTQ_ALTQ_FLOWVALVE_H_ */
     94