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