master
 1/*	$NetBSD: altq_flowvalve.h,v 1.4 2020/03/05 07:46:36 riastradh 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#ifdef _KERNEL_OPT
36#include "opt_inet.h"
37#endif
38
39/* fv_flow structure to define a unique address pair */
40struct fv_flow {
41	int flow_af;		/* address family */
42	union {
43		struct {
44			struct in_addr ip_src;
45			struct in_addr ip_dst;
46		} _ip;
47#ifdef INET6
48		struct {
49			struct in6_addr ip6_src;
50			struct in6_addr ip6_dst;
51		} _ip6;
52#endif
53	} flow_un;
54};
55
56#define	flow_ip		flow_un._ip
57#define	flow_ip6	flow_un._ip6
58
59/* flowvalve entry */
60struct fve {
61	TAILQ_ENTRY(fve) fve_lru;	/* for LRU list */
62
63	enum fv_state { Green, Red } fve_state;
64
65	int	fve_p;			/* scaled average drop rate */
66	int	fve_f;			/* scaled average fraction */
67	int	fve_count;		/* counter to update f */
68	u_int	fve_ifseq;		/* ifseq at the last update of f */
69	struct timeval	fve_lastdrop;	/* timestamp of the last drop */
70
71	struct fv_flow fve_flow;	/* unique address pair */
72};
73
74/* flowvalve structure */
75struct flowvalve {
76	u_int	fv_ifseq;	/* packet sequence number */
77	int	fv_flows;	/* number of valid flows in the flowlist */
78	int	fv_pthresh;	/* drop rate threshold */
79
80	TAILQ_HEAD(fv_flowhead, fve) fv_flowlist;		/* LRU list */
81
82	struct fve *fv_fves;	/* pointer to the allocated fves */
83
84	int	*fv_p2ftab;	/* drop rate to fraction table */
85
86	struct {
87		u_int	pass;		/* # of packets that have the fve
88					   but aren't predropped */
89		u_int	predrop;	/* # of packets predropped */
90		u_int	alloc;		/* # of fves assigned */
91		u_int	escape;		/* # of fves escaped */
92	} fv_stats;
93};
94
95#endif /* _KERNEL */
96
97#endif /* _ALTQ_ALTQ_FLOWVALVE_H_ */