static void priq_purge_sc(struct priq_if *pif, cqrq_purge_sc_t *pr) { struct ifclassq *ifq = pif->pif_ifq; u_int32_t i; IFCQ_LOCK_ASSERT_HELD(ifq); VERIFY(pr->sc == MBUF_SC_UNSPEC || MBUF_VALID_SC(pr->sc)); VERIFY(pr->flow != 0); if (pr->sc != MBUF_SC_UNSPEC) { i = MBUF_SCIDX(pr->sc); VERIFY(i < IFCQ_SC_MAX); priq_purgeq(pif, ifq->ifcq_disc_slots[i].cl, pr->flow, &pr->packets, &pr->bytes); } else { u_int32_t cnt, len; pr->packets = 0; pr->bytes = 0; for (i = 0; i < IFCQ_SC_MAX; i++) { priq_purgeq(pif, ifq->ifcq_disc_slots[i].cl, pr->flow, &cnt, &len); pr->packets += cnt; pr->bytes += len; } } }
static int priq_class_destroy(struct priq_if *pif, struct priq_class *cl) { struct ifclassq *ifq = pif->pif_ifq; int pri; IFCQ_LOCK_ASSERT_HELD(ifq); if (!qempty(&cl->cl_q)) priq_purgeq(pif, cl, 0, NULL, NULL); VERIFY(cl->cl_pri < PRIQ_MAXPRI); VERIFY(!pktsched_bit_tst(cl->cl_pri, &pif->pif_bitmap)); pif->pif_classes[cl->cl_pri] = NULL; if (pif->pif_maxpri == cl->cl_pri) { for (pri = cl->cl_pri; pri >= 0; pri--) if (pif->pif_classes[pri] != NULL) { pif->pif_maxpri = pri; break; } if (pri < 0) pif->pif_maxpri = -1; } if (pif->pif_default == cl) pif->pif_default = NULL; if (cl->cl_qalg.ptr != NULL) { #if CLASSQ_RIO if (q_is_rio(&cl->cl_q)) rio_destroy(cl->cl_rio); #endif /* CLASSQ_RIO */ #if CLASSQ_RED if (q_is_red(&cl->cl_q)) red_destroy(cl->cl_red); #endif /* CLASSQ_RED */ #if CLASSQ_BLUE if (q_is_blue(&cl->cl_q)) blue_destroy(cl->cl_blue); #endif /* CLASSQ_BLUE */ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) sfb_destroy(cl->cl_sfb); cl->cl_qalg.ptr = NULL; qtype(&cl->cl_q) = Q_DROPTAIL; qstate(&cl->cl_q) = QS_RUNNING; } if (pktsched_verbose) { log(LOG_DEBUG, "%s: %s destroyed qid=%d pri=%d\n", if_name(PRIQIF_IFP(pif)), priq_style(pif), cl->cl_handle, cl->cl_pri); } zfree(priq_cl_zone, cl); return (0); }
static int priq_throttle(struct priq_if *pif, cqrq_throttle_t *tr) { struct ifclassq *ifq = pif->pif_ifq; struct priq_class *cl; int err = 0; IFCQ_LOCK_ASSERT_HELD(ifq); VERIFY(!(pif->pif_flags & PRIQIFF_ALTQ)); if (!tr->set) { tr->level = pif->pif_throttle; return (0); } if (tr->level == pif->pif_throttle) return (EALREADY); /* Current throttling levels only involve BK_SYS class */ cl = ifq->ifcq_disc_slots[SCIDX_BK_SYS].cl; switch (tr->level) { case IFNET_THROTTLE_OFF: err = priq_resumeq(pif, cl); break; case IFNET_THROTTLE_OPPORTUNISTIC: err = priq_suspendq(pif, cl); break; default: VERIFY(0); /* NOTREACHED */ } if (err == 0 || err == ENXIO) { if (pktsched_verbose) { log(LOG_DEBUG, "%s: %s throttling level %sset %d->%d\n", if_name(PRIQIF_IFP(pif)), priq_style(pif), (err == 0) ? "" : "lazy ", pif->pif_throttle, tr->level); } pif->pif_throttle = tr->level; if (err != 0) err = 0; else priq_purgeq(pif, cl, 0, NULL, NULL); } else { log(LOG_ERR, "%s: %s unable to set throttling level " "%d->%d [error=%d]\n", if_name(PRIQIF_IFP(pif)), priq_style(pif), pif->pif_throttle, tr->level, err); } return (err); }
/* discard all the queued packets on the interface */ static void priq_purge(struct priq_if *pif) { struct priq_class *cl; int pri; for (pri = 0; pri <= pif->pif_maxpri; pri++) { if ((cl = pif->pif_classes[pri]) != NULL && !qempty(cl->cl_q)) priq_purgeq(cl); } if (ALTQ_IS_ENABLED(pif->pif_ifq)) pif->pif_ifq->ifq_len = 0; }
/* discard all the queued packets on the interface */ static void priq_purge(struct priq_if *pif) { struct priq_class *cl; int pri; for (pri = 0; pri <= pif->pif_maxpri; pri++) { if ((cl = pif->pif_classes[pri]) != NULL && !qempty(cl->cl_q)) priq_purgeq(cl); } if (ifq_is_enabled(pif->pif_ifq)) pif->pif_ifq->altq_subq[PRIQ_SUBQ_INDEX].ifq_len = 0; }
static int priq_class_destroy(struct priq_class *cl) { struct priq_if *pif; int s, pri; s = splnet(); IFQ_LOCK(cl->cl_pif->pif_ifq); #ifdef ALTQ3_CLFIER_COMPAT /* delete filters referencing to this class */ acc_discard_filters(&cl->cl_pif->pif_classifier, cl, 0); #endif if (!qempty(cl->cl_q)) priq_purgeq(cl); pif = cl->cl_pif; pif->pif_classes[cl->cl_pri] = NULL; if (pif->pif_maxpri == cl->cl_pri) { for (pri = cl->cl_pri; pri >= 0; pri--) if (pif->pif_classes[pri] != NULL) { pif->pif_maxpri = pri; break; } if (pri < 0) pif->pif_maxpri = -1; } IFQ_UNLOCK(cl->cl_pif->pif_ifq); splx(s); if (cl->cl_red != NULL) { #ifdef ALTQ_RIO if (q_is_rio(cl->cl_q)) rio_destroy((rio_t *)cl->cl_red); #endif #ifdef ALTQ_RED if (q_is_red(cl->cl_q)) red_destroy(cl->cl_red); #endif #ifdef ALTQ_CODEL if (q_is_codel(cl->cl_q)) codel_destroy(cl->cl_codel); #endif } free(cl->cl_q, M_DEVBUF); free(cl, M_DEVBUF); return (0); }
/* discard all the queued packets on the interface */ void priq_purge(struct priq_if *pif) { struct priq_class *cl; int pri; IFCQ_LOCK_ASSERT_HELD(pif->pif_ifq); for (pri = 0; pri <= pif->pif_maxpri; pri++) { if ((cl = pif->pif_classes[pri]) != NULL && !qempty(&cl->cl_q)) priq_purgeq(pif, cl, 0, NULL, NULL); } #if !PF_ALTQ /* * This assertion is safe to be made only when PF_ALTQ is not * configured; otherwise, IFCQ_LEN represents the sum of the * packets managed by ifcq_disc and altq_disc instances, which * is possible when transitioning between the two. */ VERIFY(IFCQ_LEN(pif->pif_ifq) == 0); #endif /* !PF_ALTQ */ }
static int priq_class_destroy(struct priq_class *cl) { struct priq_if *pif; int pri; crit_enter(); if (!qempty(cl->cl_q)) priq_purgeq(cl); pif = cl->cl_pif; pif->pif_classes[cl->cl_pri] = NULL; if (pif->pif_maxpri == cl->cl_pri) { for (pri = cl->cl_pri; pri >= 0; pri--) if (pif->pif_classes[pri] != NULL) { pif->pif_maxpri = pri; break; } if (pri < 0) pif->pif_maxpri = -1; } crit_exit(); if (cl->cl_red != NULL) { #ifdef ALTQ_RIO if (q_is_rio(cl->cl_q)) rio_destroy((rio_t *)cl->cl_red); #endif #ifdef ALTQ_RED if (q_is_red(cl->cl_q)) red_destroy(cl->cl_red); #endif } kfree(cl->cl_q, M_ALTQ); kfree(cl, M_ALTQ); return (0); }
static struct priq_class * priq_class_create(struct priq_if *pif, int pri, int qlimit, int flags, int qid) { struct priq_class *cl; int s; #ifndef ALTQ_RED if (flags & PRCF_RED) { #ifdef ALTQ_DEBUG printf("priq_class_create: RED not configured for PRIQ!\n"); #endif return (NULL); } #endif if ((cl = pif->pif_classes[pri]) != NULL) { /* modify the class instead of creating a new one */ s = splnet(); if (!qempty(cl->cl_q)) priq_purgeq(cl); splx(s); #ifdef ALTQ_RIO if (q_is_rio(cl->cl_q)) rio_destroy((rio_t *)cl->cl_red); #endif #ifdef ALTQ_RED if (q_is_red(cl->cl_q)) red_destroy(cl->cl_red); #endif } else { cl = malloc(sizeof(struct priq_class), M_DEVBUF, M_WAITOK|M_ZERO); if (cl == NULL) return (NULL); cl->cl_q = malloc(sizeof(class_queue_t), M_DEVBUF, M_WAITOK|M_ZERO); if (cl->cl_q == NULL) goto err_ret; } pif->pif_classes[pri] = cl; if (flags & PRCF_DEFAULTCLASS) pif->pif_default = cl; if (qlimit == 0) qlimit = 50; /* use default */ qlimit(cl->cl_q) = qlimit; qtype(cl->cl_q) = Q_DROPTAIL; qlen(cl->cl_q) = 0; cl->cl_flags = flags; cl->cl_pri = pri; if (pri > pif->pif_maxpri) pif->pif_maxpri = pri; cl->cl_pif = pif; cl->cl_handle = qid; #ifdef ALTQ_RED if (flags & (PRCF_RED|PRCF_RIO)) { int red_flags, red_pkttime; red_flags = 0; if (flags & PRCF_ECN) red_flags |= REDF_ECN; #ifdef ALTQ_RIO if (flags & PRCF_CLEARDSCP) red_flags |= RIOF_CLEARDSCP; #endif if (pif->pif_bandwidth < 8) red_pkttime = 1000 * 1000 * 1000; /* 1 sec */ else red_pkttime = (int64_t)pif->pif_ifq->altq_ifp->if_mtu * 1000 * 1000 * 1000 / (pif->pif_bandwidth / 8); #ifdef ALTQ_RIO if (flags & PRCF_RIO) { cl->cl_red = (red_t *)rio_alloc(0, NULL, red_flags, red_pkttime); if (cl->cl_red != NULL) qtype(cl->cl_q) = Q_RIO; } else #endif if (flags & PRCF_RED) { cl->cl_red = red_alloc(0, 0, qlimit(cl->cl_q) * 10/100, qlimit(cl->cl_q) * 30/100, red_flags, red_pkttime); if (cl->cl_red != NULL) qtype(cl->cl_q) = Q_RED; } } #endif /* ALTQ_RED */ return (cl); err_ret: if (cl->cl_red != NULL) { #ifdef ALTQ_RIO if (q_is_rio(cl->cl_q)) rio_destroy((rio_t *)cl->cl_red); #endif #ifdef ALTQ_RED if (q_is_red(cl->cl_q)) red_destroy(cl->cl_red); #endif } if (cl->cl_q != NULL) free(cl->cl_q, M_DEVBUF); free(cl, M_DEVBUF); return (NULL); }
static struct priq_class * priq_class_create(struct priq_if *pif, int pri, u_int32_t qlimit, int flags, u_int32_t qid) { struct ifnet *ifp; struct ifclassq *ifq; struct priq_class *cl; IFCQ_LOCK_ASSERT_HELD(pif->pif_ifq); /* Sanitize flags unless internally configured */ if (pif->pif_flags & PRIQIFF_ALTQ) flags &= PRCF_USERFLAGS; #if !CLASSQ_RED if (flags & PRCF_RED) { log(LOG_ERR, "%s: %s RED not available!\n", if_name(PRIQIF_IFP(pif)), priq_style(pif)); return (NULL); } #endif /* !CLASSQ_RED */ #if !CLASSQ_RIO if (flags & PRCF_RIO) { log(LOG_ERR, "%s: %s RIO not available!\n", if_name(PRIQIF_IFP(pif)), priq_style(pif)); return (NULL); } #endif /* CLASSQ_RIO */ #if !CLASSQ_BLUE if (flags & PRCF_BLUE) { log(LOG_ERR, "%s: %s BLUE not available!\n", if_name(PRIQIF_IFP(pif)), priq_style(pif)); return (NULL); } #endif /* CLASSQ_BLUE */ /* These are mutually exclusive */ if ((flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) && (flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) != PRCF_RED && (flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) != PRCF_RIO && (flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) != PRCF_BLUE && (flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) != PRCF_SFB) { log(LOG_ERR, "%s: %s more than one RED|RIO|BLUE|SFB\n", if_name(PRIQIF_IFP(pif)), priq_style(pif)); return (NULL); } ifq = pif->pif_ifq; ifp = PRIQIF_IFP(pif); if ((cl = pif->pif_classes[pri]) != NULL) { /* modify the class instead of creating a new one */ if (!qempty(&cl->cl_q)) priq_purgeq(pif, cl, 0, NULL, NULL); #if CLASSQ_RIO if (q_is_rio(&cl->cl_q)) rio_destroy(cl->cl_rio); #endif /* CLASSQ_RIO */ #if CLASSQ_RED if (q_is_red(&cl->cl_q)) red_destroy(cl->cl_red); #endif /* CLASSQ_RED */ #if CLASSQ_BLUE if (q_is_blue(&cl->cl_q)) blue_destroy(cl->cl_blue); #endif /* CLASSQ_BLUE */ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) sfb_destroy(cl->cl_sfb); cl->cl_qalg.ptr = NULL; qtype(&cl->cl_q) = Q_DROPTAIL; qstate(&cl->cl_q) = QS_RUNNING; } else { cl = zalloc(priq_cl_zone); if (cl == NULL) return (NULL); bzero(cl, priq_cl_size); } pif->pif_classes[pri] = cl; if (flags & PRCF_DEFAULTCLASS) pif->pif_default = cl; if (qlimit == 0 || qlimit > IFCQ_MAXLEN(ifq)) { qlimit = IFCQ_MAXLEN(ifq); if (qlimit == 0) qlimit = DEFAULT_QLIMIT; /* use default */ } _qinit(&cl->cl_q, Q_DROPTAIL, qlimit); cl->cl_flags = flags; cl->cl_pri = pri; if (pri > pif->pif_maxpri) pif->pif_maxpri = pri; cl->cl_pif = pif; cl->cl_handle = qid; if (flags & (PRCF_RED|PRCF_RIO|PRCF_BLUE|PRCF_SFB)) { #if CLASSQ_RED || CLASSQ_RIO u_int64_t ifbandwidth = ifnet_output_linkrate(ifp); int pkttime; #endif /* CLASSQ_RED || CLASSQ_RIO */ cl->cl_qflags = 0; if (flags & PRCF_ECN) { if (flags & PRCF_BLUE) cl->cl_qflags |= BLUEF_ECN; else if (flags & PRCF_SFB) cl->cl_qflags |= SFBF_ECN; else if (flags & PRCF_RED) cl->cl_qflags |= REDF_ECN; else if (flags & PRCF_RIO) cl->cl_qflags |= RIOF_ECN; } if (flags & PRCF_FLOWCTL) { if (flags & PRCF_SFB) cl->cl_qflags |= SFBF_FLOWCTL; } if (flags & PRCF_CLEARDSCP) { if (flags & PRCF_RIO) cl->cl_qflags |= RIOF_CLEARDSCP; } #if CLASSQ_RED || CLASSQ_RIO /* * XXX: RED & RIO should be watching link speed and MTU * events and recompute pkttime accordingly. */ if (ifbandwidth < 8) pkttime = 1000 * 1000 * 1000; /* 1 sec */ else pkttime = (int64_t)ifp->if_mtu * 1000 * 1000 * 1000 / (ifbandwidth / 8); /* Test for exclusivity {RED,RIO,BLUE,SFB} was done above */ #if CLASSQ_RED if (flags & PRCF_RED) { cl->cl_red = red_alloc(ifp, 0, 0, qlimit(&cl->cl_q) * 10/100, qlimit(&cl->cl_q) * 30/100, cl->cl_qflags, pkttime); if (cl->cl_red != NULL) qtype(&cl->cl_q) = Q_RED; } #endif /* CLASSQ_RED */ #if CLASSQ_RIO if (flags & PRCF_RIO) { cl->cl_rio = rio_alloc(ifp, 0, NULL, cl->cl_qflags, pkttime); if (cl->cl_rio != NULL) qtype(&cl->cl_q) = Q_RIO; } #endif /* CLASSQ_RIO */ #endif /* CLASSQ_RED || CLASSQ_RIO */ #if CLASSQ_BLUE if (flags & PRCF_BLUE) { cl->cl_blue = blue_alloc(ifp, 0, 0, cl->cl_qflags); if (cl->cl_blue != NULL) qtype(&cl->cl_q) = Q_BLUE; } #endif /* CLASSQ_BLUE */ if (flags & PRCF_SFB) { if (!(cl->cl_flags & PRCF_LAZY)) cl->cl_sfb = sfb_alloc(ifp, cl->cl_handle, qlimit(&cl->cl_q), cl->cl_qflags); if (cl->cl_sfb != NULL || (cl->cl_flags & PRCF_LAZY)) qtype(&cl->cl_q) = Q_SFB; } } if (pktsched_verbose) { log(LOG_DEBUG, "%s: %s created qid=%d pri=%d qlimit=%d " "flags=%b\n", if_name(ifp), priq_style(pif), cl->cl_handle, cl->cl_pri, qlimit, flags, PRCF_BITS); } return (cl); }