]>
Commit | Line | Data |
---|---|---|
316670eb A |
1 | /* |
2 | * Copyright (c) 2011-2012 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _NET_CLASSQ_CLASSQ_SFB_H_ | |
30 | #define _NET_CLASSQ_CLASSQ_SFB_H_ | |
31 | ||
32 | #ifdef PRIVATE | |
33 | #ifdef BSD_KERNEL_PRIVATE | |
34 | #include <net/classq/if_classq.h> | |
35 | #include <stdbool.h> | |
36 | #include <sys/time.h> | |
37 | #endif /* BSD_KERNEL_PRIVATE */ | |
38 | ||
39 | #ifdef __cplusplus | |
40 | extern "C" { | |
41 | #endif | |
42 | ||
43 | #define SFB_FP_SHIFT 14 /* fixed-point shift (Q14) */ | |
44 | #define SFB_LEVELS 2 /* L */ | |
45 | #define SFB_BINS_SHIFT 5 | |
46 | #define SFB_BINS (1 << SFB_BINS_SHIFT) /* N */ | |
47 | ||
48 | struct sfbstats { | |
49 | u_int64_t drop_early; | |
50 | u_int64_t drop_pbox; | |
51 | u_int64_t drop_queue; | |
52 | u_int64_t marked_packets; | |
53 | u_int64_t pbox_packets; | |
54 | u_int64_t pbox_time; | |
55 | u_int64_t hold_time; | |
56 | u_int64_t dequeue_avg; | |
57 | u_int64_t rehash_intval; | |
58 | u_int64_t num_rehash; | |
59 | u_int64_t null_flowhash; | |
60 | u_int64_t flow_controlled; | |
61 | u_int64_t flow_feedback; | |
62 | }; | |
63 | ||
64 | struct sfbbinstats { | |
65 | int16_t pmark; /* marking probability in Q format */ | |
66 | u_int16_t pkts; /* number of packets */ | |
67 | }; | |
68 | ||
69 | struct sfb_stats { | |
70 | u_int32_t allocation; | |
71 | u_int32_t dropthresh; | |
72 | u_int32_t clearpkts; | |
73 | u_int32_t current; | |
74 | struct sfbstats sfbstats; | |
75 | struct sfbbins { | |
76 | struct sfbbinstats stats[SFB_LEVELS][SFB_BINS]; | |
77 | } binstats[2] __attribute__((aligned(8))); | |
78 | }; | |
79 | ||
80 | #ifdef BSD_KERNEL_PRIVATE | |
81 | struct sfb_bin_fcentry { | |
82 | SLIST_ENTRY(sfb_bin_fcentry) fce_link; | |
83 | u_int32_t fce_flowhash; | |
84 | }; | |
85 | ||
86 | SLIST_HEAD(sfb_fc_list, sfb_bin_fcentry); | |
87 | ||
88 | struct sfb_bins { | |
89 | u_int32_t fudge; | |
90 | struct sfbbinstats stats[SFB_LEVELS][SFB_BINS]; | |
91 | struct timespec freezetime[SFB_LEVELS][SFB_BINS]; | |
92 | }; | |
93 | ||
94 | /* SFB flags */ | |
95 | #define SFBF_ECN4 0x01 /* use packet marking for IPv4 packets */ | |
96 | #define SFBF_ECN6 0x02 /* use packet marking for IPv6 packets */ | |
97 | #define SFBF_ECN (SFBF_ECN4 | SFBF_ECN6) | |
98 | #define SFBF_FLOWCTL 0x04 /* enable flow control advisories */ | |
99 | #define SFBF_SUSPENDED 0x1000 /* queue is suspended */ | |
100 | ||
101 | #define SFBF_USERFLAGS \ | |
102 | (SFBF_ECN4 | SFBF_ECN6 | SFBF_FLOWCTL) | |
103 | ||
104 | typedef struct sfb { | |
105 | /* variables for internal use */ | |
106 | u_int32_t sfb_flags; /* SFB flags */ | |
107 | u_int32_t sfb_qlim; | |
108 | u_int32_t sfb_qid; | |
109 | u_int16_t sfb_allocation; | |
110 | u_int16_t sfb_drop_thresh; | |
111 | u_int32_t sfb_clearpkts; | |
112 | u_int64_t sfb_eff_rate; /* last known effective rate */ | |
113 | struct timespec sfb_getqtime; /* last dequeue timestamp */ | |
114 | struct timespec sfb_holdtime; /* random holdtime in nsec */ | |
115 | struct ifnet *sfb_ifp; /* back pointer to ifnet */ | |
116 | ||
117 | /* moving hash function */ | |
118 | struct timespec sfb_hinterval; /* random reset interval in sec */ | |
119 | struct timespec sfb_nextreset; /* reset deadline */ | |
120 | ||
121 | /* penalty box */ | |
122 | struct timespec sfb_pboxtime; /* random pboxtime in nsec */ | |
123 | struct timespec sfb_pboxfreeze; | |
124 | ||
125 | /* B[L][N] bins (2 sets: current and warm-up) */ | |
126 | u_int32_t sfb_current; /* current set (0 or 1) */ | |
127 | struct sfb_bins (*sfb_bins)[2]; | |
128 | ||
129 | /* Flow control lists for current set */ | |
130 | struct sfb_fc_list (*sfb_fc_lists)[SFB_BINS]; | |
131 | ||
132 | /* statistics */ | |
133 | struct sfbstats sfb_stats __attribute__((aligned(8))); | |
134 | } sfb_t; | |
135 | ||
136 | extern void sfb_init(void); | |
137 | extern struct sfb *sfb_alloc(struct ifnet *, u_int32_t, u_int32_t, u_int32_t); | |
138 | extern void sfb_destroy(struct sfb *); | |
139 | extern int sfb_addq(struct sfb *, class_queue_t *, struct mbuf *, | |
140 | struct pf_mtag *); | |
141 | extern struct mbuf *sfb_getq(struct sfb *, class_queue_t *); | |
142 | extern void sfb_purgeq(struct sfb *, class_queue_t *, u_int32_t, | |
143 | u_int32_t *, u_int32_t *); | |
144 | extern void sfb_getstats(struct sfb *, struct sfb_stats *); | |
145 | extern void sfb_updateq(struct sfb *, cqev_t); | |
146 | extern int sfb_suspendq(struct sfb *, class_queue_t *, boolean_t); | |
147 | #endif /* BSD_KERNEL_PRIVATE */ | |
148 | ||
149 | #ifdef __cplusplus | |
150 | } | |
151 | #endif | |
152 | #endif /* PRIVATE */ | |
153 | #endif /* _NET_CLASSQ_CLASSQ_SFB_H_ */ |