3 @@ -1324,6 +1324,19 @@ peers are allowed to send to us.
4 If it is not given, Linux uses the value selected with \verb|sysctl|
5 variable \verb|net/ipv4/tcp_reordering|.
7 +\item \verb|hoplimit NUMBER|
9 +--- [2.5.74+ only] Hop limit on the path to this destination. If it is not
10 + given, Linux uses the value selected with \verb|sysctl| variable
11 + \verb|net/ipv4/ip_default_ttl|.
13 +\item \verb|initcwnd NUMBER|
15 +--- [2.5.70+ only] Initial congestion window size when establishing
16 + connections to this destination. This value is multiplied with the
17 + MSS (``Maximal Segment Size'') for the connection to get the actual
18 + window size. If it is not given (or set to zero), Linux uses the
19 + values specified in~\cite{RFC2414}.
22 \item \verb|nexthop NEXTHOP|
23 @@ -2653,6 +2666,9 @@ http://www.cisco.com/univercd/cc/td/doc/
24 \bibitem{RFC-DHCP} R.~Droms.
25 ``Dynamic Host Configuration Protocol.'', RFC-2131
27 +\bibitem{RFC2414} M.~Allman, S.~Floyd, C.~Partridge.
28 +``Increasing TCP's Initial Window'', RFC-2414.
35 @@ -14,6 +14,7 @@ PAGESIZE=a4
38 HTMLFILES=$(subst .sgml,.html,$(shell echo *.sgml))
39 +TXTFILES=$(subst .sgml,.txt,$(shell echo *.sgml))
40 DVIFILES=$(subst .ps,.dvi,$(PSFILES))
43 @@ -23,6 +24,8 @@ pstwocol: $(PSFILES)
52 @@ -47,9 +50,12 @@ print: $(PSFILES)
57 + lynx -nolist -dump $< > $@
60 install -m 0644 $(shell echo *.tex) $(DESTDIR)$(DOCDIR)
61 install -m 0644 $(shell echo *.sgml) $(DESTDIR)$(DOCDIR)
64 - rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html
65 + rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html $(TXTFILES)
66 --- a/include/linux/pkt_sched.h
67 +++ b/include/linux/pkt_sched.h
70 +#ifndef __LINUX_PKT_SCHED_H
71 +#define __LINUX_PKT_SCHED_H
73 +/* Logical priority bands not depending on specific packet scheduler.
74 + Every scheduler will map them to real traffic classes, if it has
75 + no more precise mechanism to classify packets.
77 + These numbers have no special meaning, though their coincidence
78 + with obsolete IPv6 values is not occasional :-). New IPv6 drafts
79 + preferred full anarchy inspired by diffserv group.
81 + Note: TC_PRIO_BESTEFFORT does not mean that it is the most unhappy
82 + class, actually, as rule it will be handled with more care than
83 + filler or even bulk.
86 +#define TC_PRIO_BESTEFFORT 0
87 +#define TC_PRIO_FILLER 1
88 +#define TC_PRIO_BULK 2
89 +#define TC_PRIO_INTERACTIVE_BULK 4
90 +#define TC_PRIO_INTERACTIVE 6
91 +#define TC_PRIO_CONTROL 7
93 +#define TC_PRIO_MAX 15
95 +/* Generic queue statistics, available for all the elements.
96 + Particular schedulers may have also their private records.
101 + __u64 bytes; /* NUmber of enqueues bytes */
102 + __u32 packets; /* Number of enqueued packets */
103 + __u32 drops; /* Packets dropped because of lack of resources */
104 + __u32 overlimits; /* Number of throttle events when this
105 + * flow goes out of allocated bandwidth */
106 + __u32 bps; /* Current flow byte rate */
107 + __u32 pps; /* Current flow packet rate */
118 + unsigned char ewma_log;
124 + All the traffic control objects have 32bit identifiers, or "handles".
126 + They can be considered as opaque numbers from user API viewpoint,
127 + but actually they always consist of two fields: major and
128 + minor numbers, which are interpreted by kernel specially,
129 + that may be used by applications, though not recommended.
131 + F.e. qdisc handles always have minor number equal to zero,
132 + classes (or flows) have major equal to parent qdisc major, and
133 + minor uniquely identifying class inside qdisc.
135 + Macros to manipulate handles:
138 +#define TC_H_MAJ_MASK (0xFFFF0000U)
139 +#define TC_H_MIN_MASK (0x0000FFFFU)
140 +#define TC_H_MAJ(h) ((h)&TC_H_MAJ_MASK)
141 +#define TC_H_MIN(h) ((h)&TC_H_MIN_MASK)
142 +#define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK))
144 +#define TC_H_UNSPEC (0U)
145 +#define TC_H_ROOT (0xFFFFFFFFU)
146 +#define TC_H_INGRESS (0xFFFFFFF1U)
150 + unsigned char cell_log;
151 + unsigned char __reserved;
152 + unsigned short feature;
154 + unsigned short mpu;
162 + __u32 limit; /* Queue length: bytes for bfifo, packets for pfifo */
167 +#define TCQ_PRIO_BANDS 16
171 + int bands; /* Number of bands */
172 + __u8 priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */
179 + int flows; /* Maximal number of guaranteed flows */
180 + unsigned char R_log; /* Fixed point position for round number */
181 + unsigned char delta_log; /* Log of maximal managed time interval */
182 + __u8 priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> CSZ band */
187 + struct tc_ratespec slice;
188 + struct tc_ratespec rate;
189 + struct tc_ratespec peakrate;
207 + struct tc_ratespec rate;
208 + struct tc_ratespec peakrate;
225 +/* TEQL does not require any parameters */
231 + unsigned quantum; /* Bytes per round allocated to flow */
232 + int perturb_period; /* Period of hash perturbation */
233 + __u32 limit; /* Maximal packets in queue */
234 + unsigned divisor; /* Hash divisor */
235 + unsigned flows; /* Maximal number of flows */
239 + * NOTE: limit, divisor and flows are hardwired to code at the moment.
241 + * limit=flows=128, divisor=1024;
243 + * The only reason for this is efficiency, it is possible
244 + * to change these parameters in compile time.
258 + __u32 limit; /* HARD maximal queue length (bytes) */
259 + __u32 qth_min; /* Min average length threshold (bytes) */
260 + __u32 qth_max; /* Max average length threshold (bytes) */
261 + unsigned char Wlog; /* log(W) */
262 + unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */
263 + unsigned char Scell_log; /* cell size for idle damping */
264 + unsigned char flags;
265 +#define TC_RED_ECN 1
268 +struct tc_red_xstats
270 + __u32 early; /* Early drops */
271 + __u32 pdrop; /* Drops due to queue limits */
272 + __u32 other; /* Drops due to drop() calls */
273 + __u32 marked; /* Marked packets */
288 +#define TCA_SET_OFF TCA_GRED_PARMS
291 + __u32 limit; /* HARD maximal queue length (bytes)
293 + __u32 qth_min; /* Min average length threshold (bytes)
295 + __u32 qth_max; /* Max average length threshold (bytes)
297 + __u32 DP; /* upto 2^32 DPs */
305 + unsigned char Wlog; /* log(W) */
306 + unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */
307 + unsigned char Scell_log; /* cell size for idle damping */
308 + __u8 prio; /* prio of this VQ */
321 +#define TC_HTB_NUMPRIO 8
322 +#define TC_HTB_MAXDEPTH 8
323 +#define TC_HTB_PROTOVER 3 /* the same as HTB and TC's major */
327 + struct tc_ratespec rate;
328 + struct tc_ratespec ceil;
332 + __u32 level; /* out only */
337 + __u32 version; /* to match HTB/TC */
338 + __u32 rate2quantum; /* bps->quantum divisor */
339 + __u32 defcls; /* default class number */
340 + __u32 debug; /* debug flags */
343 + __u32 direct_pkts; /* count of non shapped packets */
353 +struct tc_htb_xstats
357 + __u32 giants; /* too big packets (rate will not be accurate) */
364 +#define TC_CBQ_MAXPRIO 8
365 +#define TC_CBQ_MAXLEVEL 8
366 +#define TC_CBQ_DEF_EWMA 5
368 +struct tc_cbq_lssopt
370 + unsigned char change;
371 + unsigned char flags;
372 +#define TCF_CBQ_LSS_BOUNDED 1
373 +#define TCF_CBQ_LSS_ISOLATED 2
374 + unsigned char ewma_log;
375 + unsigned char level;
376 +#define TCF_CBQ_LSS_FLAGS 1
377 +#define TCF_CBQ_LSS_EWMA 2
378 +#define TCF_CBQ_LSS_MAXIDLE 4
379 +#define TCF_CBQ_LSS_MINIDLE 8
380 +#define TCF_CBQ_LSS_OFFTIME 0x10
381 +#define TCF_CBQ_LSS_AVPKT 0x20
388 +struct tc_cbq_wrropt
390 + unsigned char flags;
391 + unsigned char priority;
392 + unsigned char cpriority;
393 + unsigned char __reserved;
400 + unsigned char strategy;
401 +#define TC_CBQ_OVL_CLASSIC 0
402 +#define TC_CBQ_OVL_DELAY 1
403 +#define TC_CBQ_OVL_LOWPRIO 2
404 +#define TC_CBQ_OVL_DROP 3
405 +#define TC_CBQ_OVL_RCLASSIC 4
406 + unsigned char priority2;
410 +struct tc_cbq_police
412 + unsigned char police;
413 + unsigned char __res1;
414 + unsigned short __res2;
424 +struct tc_cbq_xstats
438 + TCA_CBQ_OVL_STRATEGY,
444 +#define TCA_CBQ_MAX TCA_CBQ_POLICE
446 +/* dsmark section */
450 + TCA_DSMARK_INDICES,
451 + TCA_DSMARK_DEFAULT_INDEX,
452 + TCA_DSMARK_SET_TC_INDEX,
457 +#define TCA_DSMARK_MAX TCA_DSMARK_VALUE
463 + TCA_ATM_FD, /* file/socket descriptor */
464 + TCA_ATM_PTR, /* pointer to descriptor - later */
465 + TCA_ATM_HDR, /* LL header */
466 + TCA_ATM_EXCESS, /* excess traffic class (0 for CLP) */
467 + TCA_ATM_ADDR, /* PVC address (for output only) */
468 + TCA_ATM_STATE /* VC state (ATM_VS_*; for output only) */
471 +#define TCA_ATM_MAX TCA_ATM_STATE
475 #ifndef __LINUX_PKT_SCHED_H
476 #define __LINUX_PKT_SCHED_H
478 @@ -518,4 +924,116 @@ struct tc_drr_stats
484 +/* Other includes */
485 +#include <linux/if_ether.h>
487 +// A sub weight and of a class
488 +// All numbers are represented as parts of (2^64-1).
489 +struct tc_wrr_class_weight {
490 + __u64 val; // Current value (0 is not valid)
491 + __u64 decr; // Value pr bytes (2^64-1 is not valid)
492 + __u64 incr; // Value pr seconds (2^64-1 is not valid)
493 + __u64 min; // Minimal value (0 is not valid)
494 + __u64 max; // Minimal value (0 is not valid)
496 +// The time where the above information was correct:
500 +// Packet send when modifying a class:
501 +struct tc_wrr_class_modf {
502 + // Not-valid values are ignored.
503 + struct tc_wrr_class_weight weight1;
504 + struct tc_wrr_class_weight weight2;
507 +// Packet returned when quering a class:
508 +struct tc_wrr_class_stats {
509 + char used; // If this is false the information below is invalid
511 + struct tc_wrr_class_modf class_modf;
513 + unsigned char addr[ETH_ALEN];
514 + char usemac; // True if addr is a MAC address, else it is an IP address
515 + // (this value is only for convience, it is always the same
516 + // value as in the qdisc)
517 + int heappos; // Current heap position or 0 if not in heap
518 + __u64 penal_ls; // Penalty value in heap (ls)
519 + __u64 penal_ms; // Penalty value in heap (ms)
522 +// Qdisc-wide penalty information (boolean values - 2 not valid)
523 +struct tc_wrr_qdisc_weight {
524 + char weight_mode; // 0=No automatic change to weight
525 + // 1=Decrease normally
526 + // 2=Also multiply with number of machines
527 + // 3=Instead multiply with priority divided
528 + // with priority of the other.
532 +// Packet send when modifing a qdisc:
533 +struct tc_wrr_qdisc_modf {
534 + // Not-valid values are ignored:
535 + struct tc_wrr_qdisc_weight weight1;
536 + struct tc_wrr_qdisc_weight weight2;
539 +// Packet send when creating a qdisc:
540 +struct tc_wrr_qdisc_crt {
541 + struct tc_wrr_qdisc_modf qdisc_modf;
543 + char srcaddr; // 1=lookup source, 0=lookup destination
544 + char usemac; // 1=Classify on MAC addresses, 0=classify on IP
545 + char usemasq; // 1=Classify based on masqgrading - only valid
546 + // if usemac is zero
547 + int bands_max; // Maximal number of bands (i.e.: classes)
548 + int proxy_maxconn;// If differnt from 0 then we support proxy remapping
549 + // of packets. And this is the number of maximal
550 + // concurrent proxy connections.
553 +// Packet returned when quering a qdisc:
554 +struct tc_wrr_qdisc_stats {
555 + struct tc_wrr_qdisc_crt qdisc_crt;
557 + int nodes_in_heap; // Current number of bands wanting to send something
558 + int bands_cur; // Current number of bands used (i.e.: MAC/IP addresses seen)
559 + int bands_reused; // Number of times this band has been reused.
560 + int packets_requed; // Number of times packets have been requeued.
561 + __u64 priosum; // Sum of priorities in heap where 1 is 2^32
564 +struct tc_wrr_qdisc_modf_std {
565 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
566 + char proxy; // 0=This struct
568 + // Should we also change a class?
571 + // Only valid if change_class is false
572 + struct tc_wrr_qdisc_modf qdisc_modf;
574 + // Only valid if change_class is true:
575 + unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
576 + struct tc_wrr_class_modf class_modf; // The change
579 +// Used for proxyrempping:
580 +struct tc_wrr_qdisc_modf_proxy {
581 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
582 + char proxy; // 1=This struct
584 + // This is 1 if the proxyremap information should be reset
587 + // changec is the number of elements in changes.
590 + // This is an array of type ProxyRemapBlock:
597 @@ -73,7 +73,7 @@ static void usage(void)
598 fprintf(stderr, " [ rtt TIME ] [ rttvar TIME ]\n");
599 fprintf(stderr, " [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
600 fprintf(stderr, " [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n");
601 - fprintf(stderr, " [ rto_min TIME ]\n");
602 + fprintf(stderr, " [ rto_min TIME ] [ hoplimit NUMBER ]\n");
603 fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
604 fprintf(stderr, " unreachable | prohibit | blackhole | nat ]\n");
605 fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
606 @@ -792,6 +792,30 @@ int iproute_modify(int cmd, unsigned fla
607 invarg("\"reordering\" value is invalid\n", *argv);
608 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
610 +#ifdef RTAX_HOPLIMIT
611 + } else if (strcmp(*argv, "hoplimit") == 0) {
614 + if (strcmp(*argv, "lock") == 0) {
615 + mxlock |= (1<<RTAX_HOPLIMIT);
618 + if (get_unsigned(&hoplim, *argv, 0))
619 + invarg("\"hoplimit\" value is invalid\n", *argv);
620 + rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplim);
622 +#ifdef RTAX_INITCWND
623 + } else if (strcmp(*argv, "initcwnd") == 0) {
626 + if (strcmp(*argv, "lock") == 0) {
627 + mxlock |= (1<<RTAX_HOPLIMIT);
630 + if (get_unsigned(&initcwnd, *argv, 0))
631 + invarg("\"initcwnd\" value is invalid\n", *argv);
632 + rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, initcwnd);
634 } else if (strcmp(*argv, "rtt") == 0) {
639 @@ -134,7 +134,7 @@ static int parse_args(int argc, char **a
641 p->o_flags |= GRE_KEY;
642 if (strchr(*argv, '.'))
643 - p->o_key = get_addr32(*argv);
644 + p->i_key = get_addr32(*argv);
646 if (get_unsigned(&uval, *argv, 0)<0) {
647 fprintf(stderr, "invalid value of \"okey\"\n");
650 @@ -49,7 +49,7 @@ install: all
651 $(DESTDIR)$(DOCDIR)/examples
652 install -m 0644 $(shell find examples/diffserv -maxdepth 1 -type f) \
653 $(DESTDIR)$(DOCDIR)/examples/diffserv
654 - @for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done
655 + @set -e; for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done
656 install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONFDIR)
657 install -m 0755 -d $(DESTDIR)$(MANDIR)/man8
658 install -m 0644 $(shell find man/man8 -maxdepth 1 -type f) $(DESTDIR)$(MANDIR)/man8
659 @@ -67,7 +67,7 @@ snapshot:
663 - @for i in $(SUBDIRS) doc; \
664 + @set -e; for i in $(SUBDIRS) doc; \
665 do $(MAKE) $(MFLAGS) -C $$i clean; done
671 SSOBJ=ss.o ssfilter.o
672 LNSTATOBJ=lnstat.o lnstat_util.o
674 -TARGETS=ss nstat ifstat rtacct arpd lnstat
675 +#TARGETS=ss nstat ifstat rtacct arpd lnstat
676 +TARGETS=ss nstat rtacct lnstat
682 @@ -14,6 +14,7 @@ TCMODULES += q_cbq.o
684 TCMODULES += q_multiq.o
685 TCMODULES += q_netem.o
686 +TCMODULES += q_wrr.o
687 TCMODULES += f_rsvp.o
689 TCMODULES += f_route.o
697 + * This program is free software; you can redistribute it and/or
698 + * modify it under the terms of the GNU General Public License
699 + * as published by the Free Software Foundation; either version
700 + * 2 of the License, or (at your option) any later version.
702 + * Authors: Martin Devera, devik@cdi.cz
711 +#include <sys/socket.h>
712 +#include <netinet/in.h>
713 +#include <arpa/inet.h>
717 +#include "tc_util.h"
719 +#define HTB_TC_VER 0x30003
720 +#if HTB_TC_VER >> 16 != TC_HTB_PROTOVER
721 +#error "Different kernel and TC HTB versions"
724 +static void explain(void)
726 + fprintf(stderr, "Usage: ... qdisc add ... htb [default N] [r2q N]\n"
727 + " default minor id of class to which unclassified packets are sent {0}\n"
728 + " r2q DRR quantums are computed as rate in Bps/r2q {10}\n"
729 + " debug string of 16 numbers each 0-3 {0}\n\n"
730 + "... class add ... htb rate R1 burst B1 [prio P] [slot S] [pslot PS]\n"
731 + " [ceil R2] [cburst B2] [mtu MTU] [quantum Q]\n"
732 + " rate rate allocated to this class (class can still borrow)\n"
733 + " burst max bytes burst which can be accumulated during idle period {computed}\n"
734 + " ceil definite upper class rate (no borrows) {rate}\n"
735 + " cburst burst but for ceil {computed}\n"
736 + " mtu max packet size we create rate map for {1600}\n"
737 + " prio priority of leaf; lower are served first {0}\n"
738 + " quantum how much bytes to serve from leaf at once {use r2q}\n"
739 + "\nTC HTB version %d.%d\n",HTB_TC_VER>>16,HTB_TC_VER&0xffff
743 +static void explain1(char *arg)
745 + fprintf(stderr, "Illegal \"%s\"\n", arg);
750 +#define usage() return(-1)
752 +static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
754 + struct tc_htb_glob opt;
755 + struct rtattr *tail;
756 + unsigned i; char *p;
757 + memset(&opt,0,sizeof(opt));
758 + opt.rate2quantum = 10;
762 + if (matches(*argv, "r2q") == 0) {
764 + if (get_u32(&opt.rate2quantum, *argv, 10)) {
765 + explain1("r2q"); return -1;
767 + } else if (matches(*argv, "default") == 0) {
769 + if (get_u32(&opt.defcls, *argv, 16)) {
770 + explain1("default"); return -1;
772 + } else if (matches(*argv, "debug") == 0) {
773 + NEXT_ARG(); p = *argv;
774 + for (i=0; i<16; i++,p++) {
775 + if (*p<'0' || *p>'3') break;
776 + opt.debug |= (*p-'0')<<(2*i);
779 + fprintf(stderr, "What is \"%s\"?\n", *argv);
785 + tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
786 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
787 + addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
788 + tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
792 +static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
795 + struct tc_htb_opt opt;
796 + __u32 rtab[256],ctab[256];
797 + unsigned buffer=0,cbuffer=0;
798 + int cell_log=-1,ccell_log = -1,mtu;
799 + struct rtattr *tail;
801 + memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
804 + if (matches(*argv, "prio") == 0) {
806 + if (get_u32(&opt.prio, *argv, 10)) {
807 + explain1("prio"); return -1;
810 + } else if (matches(*argv, "mtu") == 0) {
812 + if (get_u32(&mtu, *argv, 10)) {
813 + explain1("mtu"); return -1;
815 + } else if (matches(*argv, "quantum") == 0) {
817 + if (get_u32(&opt.quantum, *argv, 10)) {
818 + explain1("quantum"); return -1;
820 + } else if (matches(*argv, "burst") == 0 ||
821 + strcmp(*argv, "buffer") == 0 ||
822 + strcmp(*argv, "maxburst") == 0) {
824 + if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) {
825 + explain1("buffer");
829 + } else if (matches(*argv, "cburst") == 0 ||
830 + strcmp(*argv, "cbuffer") == 0 ||
831 + strcmp(*argv, "cmaxburst") == 0) {
833 + if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) {
834 + explain1("cbuffer");
838 + } else if (strcmp(*argv, "ceil") == 0) {
840 + if (opt.ceil.rate) {
841 + fprintf(stderr, "Double \"ceil\" spec\n");
844 + if (get_rate(&opt.ceil.rate, *argv)) {
849 + } else if (strcmp(*argv, "rate") == 0) {
851 + if (opt.rate.rate) {
852 + fprintf(stderr, "Double \"rate\" spec\n");
855 + if (get_rate(&opt.rate.rate, *argv)) {
860 + } else if (strcmp(*argv, "help") == 0) {
864 + fprintf(stderr, "What is \"%s\"?\n", *argv);
874 + if (opt.rate.rate == 0) {
875 + fprintf(stderr, "\"rate\" is required.\n");
878 + /* if ceil params are missing, use the same as rate */
879 + if (!opt.ceil.rate) opt.ceil = opt.rate;
881 + /* compute minimal allowed burst from rate; mtu is added here to make
882 + sute that buffer is larger than mtu and to have some safeguard space */
883 + if (!buffer) buffer = opt.rate.rate / HZ + mtu;
884 + if (!cbuffer) cbuffer = opt.ceil.rate / HZ + mtu;
886 + if ((cell_log = tc_calc_rtable(opt.rate.rate, rtab, cell_log, mtu, 0)) < 0) {
887 + fprintf(stderr, "htb: failed to calculate rate table.\n");
890 + opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer);
891 + opt.rate.cell_log = cell_log;
893 + if ((ccell_log = tc_calc_rtable(opt.ceil.rate, ctab, cell_log, mtu, 0)) < 0) {
894 + fprintf(stderr, "htb: failed to calculate ceil rate table.\n");
897 + opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
898 + opt.ceil.cell_log = ccell_log;
900 + tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
901 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
902 + addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
903 + addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
904 + addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
905 + tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
909 +static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
911 + struct rtattr *tb[TCA_HTB_RTAB+1];
912 + struct tc_htb_opt *hopt;
913 + struct tc_htb_glob *gopt;
914 + double buffer,cbuffer;
921 + memset(tb, 0, sizeof(tb));
922 + parse_rtattr(tb, TCA_HTB_RTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));
924 + if (tb[TCA_HTB_PARMS]) {
926 + hopt = RTA_DATA(tb[TCA_HTB_PARMS]);
927 + if (RTA_PAYLOAD(tb[TCA_HTB_PARMS]) < sizeof(*hopt)) return -1;
929 + if (!hopt->level) {
930 + fprintf(f, "prio %d ", (int)hopt->prio);
932 + fprintf(f, "quantum %d ", (int)hopt->quantum);
934 + fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
935 + buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
936 + fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
937 + cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
938 + if (show_details) {
939 + fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
940 + 1<<hopt->rate.cell_log, sprint_size(hopt->rate.mpu, b2));
941 + fprintf(f, "cburst %s/%u mpu %s ", sprint_size(cbuffer, b1),
942 + 1<<hopt->ceil.cell_log, sprint_size(hopt->ceil.mpu, b2));
943 + fprintf(f, "level %d ", (int)hopt->level);
945 + fprintf(f, "burst %s ", sprint_size(buffer, b1));
946 + fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
949 + fprintf(f, "buffer [%08x] cbuffer [%08x] ",
950 + hopt->buffer,hopt->cbuffer);
952 + if (tb[TCA_HTB_INIT]) {
953 + gopt = RTA_DATA(tb[TCA_HTB_INIT]);
954 + if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
956 + fprintf(f, "r2q %d default %x direct_packets_stat %u",
957 + gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
959 + fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
964 +static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
966 + struct tc_htb_xstats *st;
967 + if (xstats == NULL)
970 + if (RTA_PAYLOAD(xstats) < sizeof(*st))
973 + st = RTA_DATA(xstats);
974 + fprintf(f, " lended: %u borrowed: %u giants: %u\n",
975 + st->lends,st->borrows,st->giants);
976 + fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
980 +struct qdisc_util htb_util = {
986 + htb_parse_class_opt,
990 +/* for testing of old one */
991 +struct qdisc_util htb2_util = {
997 + htb_parse_class_opt,
1008 +#include <stdlib.h>
1009 +#include <unistd.h>
1010 +#include <syslog.h>
1012 +#include <sys/socket.h>
1013 +#include <netinet/in.h>
1014 +#include <arpa/inet.h>
1015 +#include <string.h>
1019 +#include "tc_util.h"
1021 +#define usage() return(-1)
1023 +// Returns -1 on error
1024 +static int wrr_parse_qdisc_weight(int argc, char** argv,
1025 + struct tc_wrr_qdisc_modf* opt) {
1028 + opt->weight1.weight_mode=-1;
1029 + opt->weight2.weight_mode=-1;
1031 + for(i=0; i<argc; i++) {
1032 + if(!memcmp(argv[i],"wmode1=",7)) {
1033 + opt->weight1.weight_mode=atoi(argv[i]+7);
1034 + } else if(!memcmp(argv[i],"wmode2=",7)) {
1035 + opt->weight2.weight_mode=atoi(argv[i]+7);
1037 + printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
1044 +static int wrr_parse_class_modf(int argc, char** argv,
1045 + struct tc_wrr_class_modf* modf) {
1049 + fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
1050 + fprintf(stderr, " The values can be floating point like 0.42 or divisions like 42/100\n");
1054 + // Set meaningless values:
1055 + modf->weight1.val=0;
1056 + modf->weight1.decr=(__u64)-1;
1057 + modf->weight1.incr=(__u64)-1;
1058 + modf->weight1.min=0;
1059 + modf->weight1.max=0;
1060 + modf->weight2.val=0;
1061 + modf->weight2.decr=(__u64)-1;
1062 + modf->weight2.incr=(__u64)-1;
1063 + modf->weight2.min=0;
1064 + modf->weight2.max=0;
1066 + // And read values:
1067 + for(i=0; i<argc; i++) {
1069 + char* name,*value1=0,*value2=0;
1070 + long double f_val1,f_val2=1,value;
1071 + if(strlen(argv[i])>=sizeof(arg)) {
1072 + fprintf(stderr,"Argument too long: %s\n",argv[i]);
1075 + strcpy(arg,argv[i]);
1077 + name=strtok(arg,"=");
1078 + if(name) value1=strtok(0,"/");
1079 + if(value1) value2=strtok(0,"");
1082 + fprintf(stderr,"No = found in argument: %s\n",argv[i]);
1086 + f_val1=atof(value1);
1087 + if(value2) f_val2=atof(value2);
1090 + fprintf(stderr,"Division by 0\n");
1094 + value=f_val1/f_val2;
1095 + if(value>1) value=1;
1096 + if(value<0) value=0;
1097 + value*=((__u64)-1);
1099 + // And find the value set
1100 + if(!strcmp(name,"weight1")) modf->weight1.val=value;
1101 + else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
1102 + else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
1103 + else if(!strcmp(name,"min1")) modf->weight1.min=value;
1104 + else if(!strcmp(name,"max1")) modf->weight1.max=value;
1105 + else if(!strcmp(name,"weight2")) modf->weight2.val=value;
1106 + else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
1107 + else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
1108 + else if(!strcmp(name,"min2")) modf->weight2.min=value;
1109 + else if(!strcmp(name,"max2")) modf->weight2.max=value;
1111 + fprintf(stderr,"illegal value: %s\n",name);
1119 +static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
1121 + if(n->nlmsg_flags & NLM_F_CREATE) {
1122 + // This is a create request:
1123 + struct tc_wrr_qdisc_crt opt;
1125 + int sour,dest,ip,mac,masq;
1128 + fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
1132 + // Read sour/dest:
1133 + memset(&opt,0,sizeof(opt));
1134 + sour=!strcmp(argv[0],"sour");
1135 + dest=!strcmp(argv[0],"dest");
1137 + if(!sour && !dest) {
1138 + fprintf(stderr,"sour or dest must be specified\n");
1143 + ip=!strcmp(argv[1],"ip");
1144 + mac=!strcmp(argv[1],"mac");
1145 + masq=!strcmp(argv[1],"masq");
1147 + if(!ip && !mac && !masq) {
1148 + fprintf(stderr,"ip, masq or mac must be specified\n");
1155 + opt.bands_max=atoi(argv[2]);
1157 + opt.proxy_maxconn=atoi(argv[3]);
1160 + if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
1161 + if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
1162 + if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
1164 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1166 + struct tc_wrr_qdisc_modf_std opt;
1169 + // This is a modify request:
1171 + fprintf(stderr,"... qdisc ... or ... class ...\n");
1175 + qdisc=!strcmp(argv[0],"qdisc");
1176 + class=!strcmp(argv[0],"class");
1178 + if(!qdisc && !class) {
1179 + fprintf(stderr,"qdisc or class must be specified\n");
1189 + opt.change_class=0;
1190 + if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
1192 + int a0,a1,a2,a3,a4=0,a5=0;
1194 + opt.change_class=1;
1197 + fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
1200 + memset(opt.addr,0,sizeof(opt.addr));
1202 + if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
1203 + (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
1204 + fprintf(stderr,"Wrong format of mac or ip address\n");
1208 + opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
1209 + opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
1211 + if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
1214 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1219 +static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
1220 + struct tc_wrr_class_modf opt;
1222 + memset(&opt,0,sizeof(opt));
1223 + if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
1225 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1229 +static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1231 + struct tc_wrr_qdisc_stats *qopt;
1236 + if (RTA_PAYLOAD(opt) < sizeof(*qopt))
1238 + qopt = RTA_DATA(opt);
1240 + fprintf(f,"\n (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
1241 + qopt->qdisc_crt.srcaddr ? "sour" : "dest",
1242 + qopt->qdisc_crt.usemac ? "mac" : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),
1243 + qopt->qdisc_crt.bands_max,
1245 + qopt->bands_reused
1248 + if(qopt->qdisc_crt.proxy_maxconn) {
1249 + fprintf(f," (proxy maxcon %i) (proxy curcon %i)\n",
1250 + qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
1253 + fprintf(f," (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
1254 + qopt->nodes_in_heap,
1255 + qopt->packets_requed,
1256 + qopt->priosum/((long double)((__u32)-1))
1259 + fprintf(f," (wmode1 %i) (wmode2 %i) \n",
1260 + qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
1261 + qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
1266 +static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
1267 + struct tc_wrr_class_stats *copt;
1268 + long double d=(__u64)-1;
1270 + if (opt == NULL) return 0;
1272 + if (RTA_PAYLOAD(opt) < sizeof(*copt))
1274 + copt = RTA_DATA(opt);
1277 + fprintf(f,"(unused)");
1281 + if(copt->usemac) {
1282 + fprintf(f,"\n (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
1283 + copt->addr[0],copt->addr[1],copt->addr[2],
1284 + copt->addr[3],copt->addr[4],copt->addr[5]);
1286 + fprintf(f,"\n (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
1289 + fprintf(f," (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
1290 + (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
1292 + (unsigned)(copt->penal_ms>>32),
1293 + (unsigned)(copt->penal_ms & 0xffffffffU),
1294 + (unsigned)(copt->penal_ls>>32),
1295 + (unsigned)(copt->penal_ls & 0xffffffffU)
1298 + fprintf(f," Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
1299 + copt->class_modf.weight1.val/d,
1300 + copt->class_modf.weight1.decr/d,
1301 + copt->class_modf.weight1.incr/d,
1302 + copt->class_modf.weight1.min/d,
1303 + copt->class_modf.weight1.max/d);
1305 + fprintf(f," Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
1306 + copt->class_modf.weight2.val/d,
1307 + copt->class_modf.weight2.decr/d,
1308 + copt->class_modf.weight2.incr/d,
1309 + copt->class_modf.weight2.min/d,
1310 + copt->class_modf.weight2.max/d);
1315 +static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
1321 +struct qdisc_util wrr_qdisc_util = {
1323 + .parse_qopt = wrr_parse_opt,
1324 + .print_qopt = wrr_print_opt,
1325 + .print_xstats = wrr_print_xstats,
1326 + .parse_copt = wrr_parse_copt,
1327 + .print_copt = wrr_print_copt