int cbq_add_altq(struct pf_altq *a) { cbq_state_t *cbqp; struct ifnet *ifp; ifnet_lock(); if ((ifp = ifunit(a->ifname)) == NULL) { ifnet_unlock(); return (EINVAL); } if (!ifq_is_ready(&ifp->if_snd)) { ifnet_unlock(); return (ENODEV); } /* allocate and initialize cbq_state_t */ cbqp = kmalloc(sizeof(*cbqp), M_ALTQ, M_WAITOK | M_ZERO); callout_init(&cbqp->cbq_callout); cbqp->cbq_qlen = 0; cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */ ifq_purge_all(&ifp->if_snd); ifnet_unlock(); /* keep the state in pf_altq */ a->altq_disc = cbqp; return (0); }
static int altq_enable_locked(struct ifaltq *ifq) { if (!ifq_is_ready(ifq)) return ENXIO; if (ifq_is_enabled(ifq)) return 0; ifq_purge_all_locked(ifq); ifq->altq_flags |= ALTQF_ENABLED; if (ifq->altq_clfier != NULL) ifq->altq_flags |= ALTQF_CLASSIFY; return 0; }
static int altq_detach_locked(struct ifaltq *ifq) { if (!ifq_is_ready(ifq)) return ENXIO; if (ifq_is_enabled(ifq)) return EBUSY; if (!ifq_is_attached(ifq)) return (0); ifq_set_classic(ifq); ifq->altq_type = ALTQT_NONE; ifq->altq_disc = NULL; ifq->altq_clfier = NULL; ifq->altq_classify = NULL; ifq->altq_flags &= ALTQF_CANTCHANGE; return 0; }
int altq_attach(struct ifaltq *ifq, int type, void *discipline, altq_mapsubq_t mapsubq, ifsq_enqueue_t enqueue, ifsq_dequeue_t dequeue, ifsq_request_t request, void *clfier, void *(*classify)(struct ifaltq *, struct mbuf *, struct altq_pktattr *)) { if (!ifq_is_ready(ifq)) return ENXIO; ifq->altq_type = type; ifq->altq_disc = discipline; ifq->altq_clfier = clfier; ifq->altq_classify = classify; ifq->altq_flags &= (ALTQF_CANTCHANGE|ALTQF_ENABLED); ifq_set_methods(ifq, mapsubq, enqueue, dequeue, request); return 0; }
int priq_add_altq(struct pf_altq *a) { struct priq_if *pif; struct ifnet *ifp; if ((ifp = ifunit(a->ifname)) == NULL) return (EINVAL); if (!ifq_is_ready(&ifp->if_snd)) return (ENODEV); pif = kmalloc(sizeof(*pif), M_ALTQ, M_WAITOK | M_ZERO); pif->pif_bandwidth = a->ifbandwidth; pif->pif_maxpri = -1; pif->pif_ifq = &ifp->if_snd; ifq_purge_all(&ifp->if_snd); /* keep the state in pf_altq */ a->altq_disc = pif; return (0); }