static void tcq_purgeq(struct tcq_if *tif, struct tcq_class *cl, u_int32_t flow, u_int32_t *packets, u_int32_t *bytes) { struct ifclassq *ifq = tif->tif_ifq; u_int32_t cnt = 0, len = 0, qlen; IFCQ_LOCK_ASSERT_HELD(ifq); if ((qlen = qlen(&cl->cl_q)) == 0) goto done; /* become regular mutex before freeing mbufs */ IFCQ_CONVERT_LOCK(ifq); #if CLASSQ_RIO if (q_is_rio(&cl->cl_q)) rio_purgeq(cl->cl_rio, &cl->cl_q, flow, &cnt, &len); else #endif /* CLASSQ_RIO */ #if CLASSQ_RED if (q_is_red(&cl->cl_q)) red_purgeq(cl->cl_red, &cl->cl_q, flow, &cnt, &len); else #endif /* CLASSQ_RED */ #if CLASSQ_BLUE if (q_is_blue(&cl->cl_q)) blue_purgeq(cl->cl_blue, &cl->cl_q, flow, &cnt, &len); else #endif /* CLASSQ_BLUE */ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) sfb_purgeq(cl->cl_sfb, &cl->cl_q, flow, &cnt, &len); else _flushq_flow(&cl->cl_q, flow, &cnt, &len); if (cnt > 0) { VERIFY(qlen(&cl->cl_q) == (qlen - cnt)); PKTCNTR_ADD(&cl->cl_dropcnt, cnt, len); IFCQ_DROP_ADD(ifq, cnt, len); VERIFY(((signed)IFCQ_LEN(ifq) - cnt) >= 0); IFCQ_LEN(ifq) -= cnt; if (pktsched_verbose) { log(LOG_DEBUG, "%s: %s purge qid=%d pri=%d " "qlen=[%d,%d] cnt=%d len=%d flow=0x%x\n", if_name(TCQIF_IFP(tif)), tcq_style(tif), cl->cl_handle, cl->cl_pri, qlen, qlen(&cl->cl_q), cnt, len, flow); } } done: if (packets != NULL) *packets = cnt; if (bytes != NULL) *bytes = len; }
/* discard all the queued packets on the interface */ void qfq_purge(struct qfq_if *qif) { struct qfq_class *cl; int i; IFCQ_LOCK_ASSERT_HELD(qif->qif_ifq); for (i = 0; i < qif->qif_maxclasses; i++) { if ((cl = qif->qif_class_tbl[i]) != NULL) qfq_purgeq(qif, cl, 0, NULL, NULL); } VERIFY(IFCQ_LEN(qif->qif_ifq) == 0); }
/* discard all the queued packets on the interface */ void fairq_purge(struct fairq_if *fif) { struct fairq_class *cl; int pri; IFCQ_LOCK_ASSERT_HELD(fif->fif_ifq); for (pri = 0; pri <= fif->fif_maxpri; pri++) { if ((cl = fif->fif_classes[pri]) != NULL && cl->cl_head) fairq_purgeq(fif, 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(fif->fif_ifq) == 0); #endif /* !PF_ALTQ */ }
int make_ifmibdata(struct ifnet *ifp, int *name, struct sysctl_req *req) { struct ifmibdata ifmd; int error = 0; switch(name[1]) { default: error = ENOENT; break; case IFDATA_GENERAL: bzero(&ifmd, sizeof(ifmd)); /* * Make sure the interface is in use */ if (ifnet_is_attached(ifp, 0)) { snprintf(ifmd.ifmd_name, sizeof(ifmd.ifmd_name), "%s%d", ifp->if_name, ifp->if_unit); #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld COPY(pcount); COPY(flags); if_data_internal_to_if_data64(ifp, &ifp->if_data, &ifmd.ifmd_data); #undef COPY ifmd.ifmd_snd_len = IFCQ_LEN(&ifp->if_snd); ifmd.ifmd_snd_maxlen = IFCQ_MAXLEN(&ifp->if_snd); ifmd.ifmd_snd_drops = ifp->if_snd.ifcq_dropcnt.packets; } error = SYSCTL_OUT(req, &ifmd, sizeof ifmd); if (error || !req->newptr) break; #ifdef IF_MIB_WR error = SYSCTL_IN(req, &ifmd, sizeof ifmd); if (error) break; #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld DONTCOPY(type); DONTCOPY(physical); DONTCOPY(addrlen); DONTCOPY(hdrlen); DONTCOPY(mtu); DONTCOPY(metric); DONTCOPY(baudrate); #undef DONTCOPY #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld COPY(data); ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen; ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops; #undef COPY #endif /* IF_MIB_WR */ break; case IFDATA_LINKSPECIFIC: error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen); if (error || !req->newptr) break; #ifdef IF_MIB_WR error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen); if (error) break; #endif /* IF_MIB_WR */ break; case IFDATA_SUPPLEMENTAL: { struct ifmibdata_supplemental *ifmd_supp; if ((ifmd_supp = _MALLOC(sizeof (*ifmd_supp), M_TEMP, M_NOWAIT | M_ZERO)) == NULL) { error = ENOMEM; break; } if_copy_traffic_class(ifp, &ifmd_supp->ifmd_traffic_class); if_copy_data_extended(ifp, &ifmd_supp->ifmd_data_extended); if_copy_packet_stats(ifp, &ifmd_supp->ifmd_packet_stats); if_copy_rxpoll_stats(ifp, &ifmd_supp->ifmd_rxpoll_stats); error = SYSCTL_OUT(req, ifmd_supp, sizeof (*ifmd_supp)); _FREE(ifmd_supp, M_TEMP); break; } } return error; }