File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff 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 */
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