Skip to content

Commit ae55017

Browse files
committed
Starting ALTQ in NPF
starting ALTQ is fully handed over to the kernel. when you start NPF, it checks if altq is loaded and not already running. if ALTQ is already running, it ignores it.
1 parent 9772953 commit ae55017

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

sys/net/npf/npf_altq.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,44 @@ npf_get_altqs(void *data)
179179
return 0 ;
180180
}
181181

182+
int
183+
npf_altq_start(void)
184+
{
185+
int error;
186+
struct npf_altq *altq;
187+
/* enable all altq interfaces on active list */
188+
TAILQ_FOREACH(altq, npf_altqs_active, entries) {
189+
if (altq->qname[0] == 0) {
190+
error = npf_enable_altq(altq);
191+
if (error != 0)
192+
break;
193+
}
194+
}
195+
196+
return error;
197+
}
198+
199+
int
200+
npf_enable_altq(struct npf_altq *altq)
201+
{
202+
struct ifnet *ifp;
203+
struct tb_profile tb;
204+
int s, error = 0;
205+
if ((ifp = ifunit(altq->ifname)) == NULL)
206+
return EINVAL;
207+
if (ifp->if_snd.altq_type != ALTQT_NONE)
208+
error = altq_enable(&ifp->if_snd);
209+
/* set tokenbucket regulator */
210+
if (error == 0 && ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) {
211+
tb.rate = altq->ifbandwidth;
212+
tb.depth = altq->tbrsize;
213+
s = splnet();
214+
error = tbr_set(&ifp->if_snd, &tb);
215+
splx(s);
216+
}
217+
if (error == 0)
218+
npf_altq_running = true;
219+
return error;
220+
}
221+
182222
#endif /* ALTQ */

sys/net/npf/npf_altq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@ struct npf_tagname {
119119
TAILQ_HEAD(npf_altqqueue, npf_altq);
120120

121121
extern int npf_altq_loaded;
122+
extern bool npf_altq_running;
122123

123124
extern int npf_get_altqs(void *);
124125
extern void npf_altq_init(void);
125126
extern int npf_begin_altq(void);
126127
extern int npf_add_altq(void *);
127128
void npf_qid_unref(uint32_t);
128129
extern uint32_t npf_qname2qid(char *);
130+
int npf_altq_start(void);
131+
int npf_enable_altq(struct npf_altq *);
129132

130133
#endif /* NPF_ALTQ_H_ */

sys/net/npf/npf_os.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ npfctl_switch(void *data)
248248
if (onoff) {
249249
/* Enable: add pfil hooks. */
250250
error = npf_pfil_register(false);
251+
#ifdef ALTQ
252+
if (!npf_altq_running && npf_altq_loaded)
253+
error = npf_altq_start();
254+
#endif /* ALTQ */
251255
} else {
256+
252257
/* Disable: remove pfil hooks. */
253258
npf_pfil_unregister(false);
254259
error = 0;

0 commit comments

Comments
 (0)