]>
git.saurik.com Git - apple/xnu.git/blob - bsd/net/altq/altq_qfq.c
2 * Copyright (c) 2011-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
35 #include <sys/cdefs.h>
36 #include <sys/param.h>
37 #include <sys/malloc.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/kernel.h>
44 #include <net/pfvar.h>
45 #include <net/net_osdep.h>
46 #include <net/altq/altq.h>
47 #include <net/altq/altq_qfq.h>
48 #include <netinet/in.h>
53 static int altq_qfq_enqueue(struct ifaltq
*, struct mbuf
*);
54 static struct mbuf
*altq_qfq_dequeue(struct ifaltq
*, enum altdq_op
);
55 static int altq_qfq_request(struct ifaltq
*, enum altrq
, void *);
58 altq_qfq_pfattach(struct pf_altq
*a
)
63 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
65 if ((ifp
= ifunit(a
->ifname
)) == NULL
|| a
->altq_disc
== NULL
)
68 IFCQ_LOCK(&ifp
->if_snd
);
69 error
= altq_attach(IFCQ_ALTQ(&ifp
->if_snd
), ALTQT_QFQ
, a
->altq_disc
,
70 altq_qfq_enqueue
, altq_qfq_dequeue
, NULL
, altq_qfq_request
);
71 IFCQ_UNLOCK(&ifp
->if_snd
);
77 altq_qfq_add(struct pf_altq
*a
)
82 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
84 if ((ifp
= ifunit(a
->ifname
)) == NULL
)
86 if (!ALTQ_IS_READY(IFCQ_ALTQ(&ifp
->if_snd
)))
89 qif
= qfq_alloc(ifp
, M_WAITOK
, TRUE
);
93 /* keep the state in pf_altq */
100 altq_qfq_remove(struct pf_altq
*a
)
104 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
106 if ((qif
= a
->altq_disc
) == NULL
)
110 return (qfq_destroy(qif
));
114 altq_qfq_add_queue(struct pf_altq
*a
)
119 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
121 if ((qif
= a
->altq_disc
) == NULL
)
124 IFCQ_LOCK(qif
->qif_ifq
);
125 err
= qfq_add_queue(qif
, a
->qlimit
, a
->weight
, a
->pq_u
.qfq_opts
.lmax
,
126 a
->pq_u
.qfq_opts
.flags
, a
->qid
, NULL
);
127 IFCQ_UNLOCK(qif
->qif_ifq
);
133 altq_qfq_remove_queue(struct pf_altq
*a
)
138 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
140 if ((qif
= a
->altq_disc
) == NULL
)
143 IFCQ_LOCK(qif
->qif_ifq
);
144 err
= qfq_remove_queue(qif
, a
->qid
);
145 IFCQ_UNLOCK(qif
->qif_ifq
);
151 altq_qfq_getqstats(struct pf_altq
*a
, void *ubuf
, int *nbytes
)
153 struct ifclassq
*ifq
= NULL
;
155 struct qfq_classstats stats
;
158 lck_mtx_assert(pf_lock
, LCK_MTX_ASSERT_OWNED
);
160 if ((unsigned)*nbytes
< sizeof (stats
))
163 if ((qif
= altq_lookup(a
->ifname
, ALTQT_QFQ
)) == NULL
)
167 IFCQ_LOCK_ASSERT_HELD(ifq
); /* lock held by altq_lookup */
168 error
= qfq_get_class_stats(qif
, a
->qid
, &stats
);
173 if ((error
= copyout((caddr_t
)&stats
, (user_addr_t
)(uintptr_t)ubuf
,
174 sizeof (stats
))) != 0)
177 *nbytes
= sizeof (stats
);
183 altq_qfq_request(struct ifaltq
*altq
, enum altrq req
, void *arg
)
185 struct qfq_if
*qif
= (struct qfq_if
*)altq
->altq_disc
;
193 /* not supported for ALTQ instance */
197 qfq_event(qif
, (cqev_t
)arg
);
208 * altq_qfq_enqueue is an enqueue function to be registered to
209 * (*altq_enqueue) in struct ifaltq.
212 altq_qfq_enqueue(struct ifaltq
*altq
, struct mbuf
*m
)
214 /* grab class set by classifier */
215 if (!(m
->m_flags
& M_PKTHDR
)) {
216 /* should not happen */
217 printf("%s: packet for %s does not have pkthdr\n", __func__
,
218 if_name(altq
->altq_ifcq
->ifcq_ifp
));
223 return (qfq_enqueue(altq
->altq_disc
, NULL
, m
, m_pftag(m
)));
227 * altq_qfq_dequeue is a dequeue function to be registered to
228 * (*altq_dequeue) in struct ifaltq.
230 * note: ALTDQ_POLL returns the next packet without removing the packet
231 * from the queue. ALTDQ_REMOVE is a normal dequeue operation.
232 * ALTDQ_REMOVE must return the same packet if called immediately
236 altq_qfq_dequeue(struct ifaltq
*altq
, enum altdq_op op
)
238 return (qfq_dequeue(altq
->altq_disc
, (cqdq_op_t
)op
));