1/*- 2 * Copyright (C) 2000-2003 3 * Sony Computer Science Laboratories Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $KAME: altq_priq.c,v 1.11 2003/09/17 14:23:25 kjc Exp $ |
27 * $FreeBSD: head/sys/net/altq/altq_priq.c 287009 2015-08-21 22:02:22Z loos $ |
28 */ 29/* 30 * priority queue 31 */ 32 33#include "opt_altq.h" 34#include "opt_inet.h" 35#include "opt_inet6.h" --- 249 unchanged lines hidden (view full) --- 285#ifndef ALTQ_RED 286 if (flags & PRCF_RED) { 287#ifdef ALTQ_DEBUG 288 printf("priq_class_create: RED not configured for PRIQ!\n"); 289#endif 290 return (NULL); 291 } 292#endif |
293#ifndef ALTQ_CODEL 294 if (flags & PRCF_CODEL) { 295#ifdef ALTQ_DEBUG 296 printf("priq_class_create: CODEL not configured for PRIQ!\n"); 297#endif 298 return (NULL); 299 } 300#endif |
301 302 if ((cl = pif->pif_classes[pri]) != NULL) { 303 /* modify the class instead of creating a new one */ 304 s = splnet(); 305 IFQ_LOCK(cl->cl_pif->pif_ifq); 306 if (!qempty(cl->cl_q)) 307 priq_purgeq(cl); 308 IFQ_UNLOCK(cl->cl_pif->pif_ifq); 309 splx(s); 310#ifdef ALTQ_RIO 311 if (q_is_rio(cl->cl_q)) 312 rio_destroy((rio_t *)cl->cl_red); 313#endif 314#ifdef ALTQ_RED 315 if (q_is_red(cl->cl_q)) 316 red_destroy(cl->cl_red); 317#endif |
318#ifdef ALTQ_CODEL 319 if (q_is_codel(cl->cl_q)) 320 codel_destroy(cl->cl_codel); 321#endif |
322 } else { 323 cl = malloc(sizeof(struct priq_class), M_DEVBUF, 324 M_NOWAIT | M_ZERO); 325 if (cl == NULL) 326 return (NULL); 327 328 cl->cl_q = malloc(sizeof(class_queue_t), M_DEVBUF, 329 M_NOWAIT | M_ZERO); --- 4 unchanged lines hidden (view full) --- 334 pif->pif_classes[pri] = cl; 335 if (flags & PRCF_DEFAULTCLASS) 336 pif->pif_default = cl; 337 if (qlimit == 0) 338 qlimit = 50; /* use default */ 339 qlimit(cl->cl_q) = qlimit; 340 qtype(cl->cl_q) = Q_DROPTAIL; 341 qlen(cl->cl_q) = 0; |
342 qsize(cl->cl_q) = 0; |
343 cl->cl_flags = flags; 344 cl->cl_pri = pri; 345 if (pri > pif->pif_maxpri) 346 pif->pif_maxpri = pri; 347 cl->cl_pif = pif; 348 cl->cl_handle = qid; 349 350#ifdef ALTQ_RED --- 27 unchanged lines hidden (view full) --- 378 qlimit(cl->cl_q) * 30/100, 379 red_flags, red_pkttime); 380 if (cl->cl_red == NULL) 381 goto err_ret; 382 qtype(cl->cl_q) = Q_RED; 383 } 384 } 385#endif /* ALTQ_RED */ |
386#ifdef ALTQ_CODEL 387 if (flags & PRCF_CODEL) { 388 cl->cl_codel = codel_alloc(5, 100, 0); 389 if (cl->cl_codel != NULL) 390 qtype(cl->cl_q) = Q_CODEL; 391 } 392#endif |
393 394 return (cl); 395 396 err_ret: 397 if (cl->cl_red != NULL) { 398#ifdef ALTQ_RIO 399 if (q_is_rio(cl->cl_q)) 400 rio_destroy((rio_t *)cl->cl_red); 401#endif 402#ifdef ALTQ_RED 403 if (q_is_red(cl->cl_q)) 404 red_destroy(cl->cl_red); 405#endif |
406#ifdef ALTQ_CODEL 407 if (q_is_codel(cl->cl_q)) 408 codel_destroy(cl->cl_codel); 409#endif |
410 } 411 if (cl->cl_q != NULL) 412 free(cl->cl_q, M_DEVBUF); 413 free(cl, M_DEVBUF); 414 return (NULL); 415} 416 417static int --- 31 unchanged lines hidden (view full) --- 449#ifdef ALTQ_RIO 450 if (q_is_rio(cl->cl_q)) 451 rio_destroy((rio_t *)cl->cl_red); 452#endif 453#ifdef ALTQ_RED 454 if (q_is_red(cl->cl_q)) 455 red_destroy(cl->cl_red); 456#endif |
457#ifdef ALTQ_CODEL 458 if (q_is_codel(cl->cl_q)) 459 codel_destroy(cl->cl_codel); 460#endif |
461 } 462 free(cl->cl_q, M_DEVBUF); 463 free(cl, M_DEVBUF); 464 return (0); 465} 466 467/* 468 * priq_enqueue is an enqueue function to be registered to --- 99 unchanged lines hidden (view full) --- 568 if (q_is_rio(cl->cl_q)) 569 return rio_addq((rio_t *)cl->cl_red, cl->cl_q, m, 570 cl->cl_pktattr); 571#endif 572#ifdef ALTQ_RED 573 if (q_is_red(cl->cl_q)) 574 return red_addq(cl->cl_red, cl->cl_q, m, cl->cl_pktattr); 575#endif |
576#ifdef ALTQ_CODEL 577 if (q_is_codel(cl->cl_q)) 578 return codel_addq(cl->cl_codel, cl->cl_q, m); 579#endif |
580 if (qlen(cl->cl_q) >= qlimit(cl->cl_q)) { 581 m_freem(m); 582 return (-1); 583 } 584 585 if (cl->cl_flags & PRCF_CLEARDSCP) 586 write_dsfield(m, cl->cl_pktattr, 0); 587 --- 8 unchanged lines hidden (view full) --- 596#ifdef ALTQ_RIO 597 if (q_is_rio(cl->cl_q)) 598 return rio_getq((rio_t *)cl->cl_red, cl->cl_q); 599#endif 600#ifdef ALTQ_RED 601 if (q_is_red(cl->cl_q)) 602 return red_getq(cl->cl_red, cl->cl_q); 603#endif |
604#ifdef ALTQ_CODEL 605 if (q_is_codel(cl->cl_q)) 606 return codel_getq(cl->cl_codel, cl->cl_q); 607#endif |
608 return _getq(cl->cl_q); 609} 610 611static struct mbuf * 612priq_pollq(cl) 613 struct priq_class *cl; 614{ 615 return qhead(cl->cl_q); --- 28 unchanged lines hidden (view full) --- 644#ifdef ALTQ_RED 645 if (q_is_red(cl->cl_q)) 646 red_getstats(cl->cl_red, &sp->red[0]); 647#endif 648#ifdef ALTQ_RIO 649 if (q_is_rio(cl->cl_q)) 650 rio_getstats((rio_t *)cl->cl_red, &sp->red[0]); 651#endif |
652#ifdef ALTQ_CODEL 653 if (q_is_codel(cl->cl_q)) 654 codel_getstats(cl->cl_codel, &sp->codel); 655#endif |
656} 657 658/* convert a class handle to the corresponding class pointer */ 659static struct priq_class * 660clh_to_clp(struct priq_if *pif, u_int32_t chandle) 661{ 662 struct priq_class *cl; 663 int idx; --- 407 unchanged lines hidden --- |