Skip to content

Commit 0f42f8b

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 0f42f8b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

sys/net/npf/npf_altq.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct npf_altqqueue npf_altqs[2];
2323

2424
struct pool npf_altq_pl;
2525
int npf_altq_loaded = 0;
26+
bool npf_altq_running = false;
2627

2728
/* npf interface to start altq */
2829
void
@@ -179,4 +180,44 @@ npf_get_altqs(void *data)
179180
return 0 ;
180181
}
181182

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