File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ struct npf_altqqueue npf_altqs[2];
2323
2424struct pool npf_altq_pl ;
2525int npf_altq_loaded = 0 ;
26+ bool npf_altq_running = false;
2627
2728/* npf interface to start altq */
2829void
@@ -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 */
Original file line number Diff line number Diff line change @@ -119,12 +119,15 @@ struct npf_tagname {
119119TAILQ_HEAD (npf_altqqueue , npf_altq );
120120
121121extern int npf_altq_loaded ;
122+ extern bool npf_altq_running ;
122123
123124extern int npf_get_altqs (void * );
124125extern void npf_altq_init (void );
125126extern int npf_begin_altq (void );
126127extern int npf_add_altq (void * );
127128void npf_qid_unref (uint32_t );
128129extern 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_ */
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments