org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * q_htb.c HTB. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Martin Devera, devik@cdi.cz |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <unistd.h> |
| 16 | #include <syslog.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <sys/socket.h> |
| 19 | #include <netinet/in.h> |
| 20 | #include <arpa/inet.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include "utils.h" |
| 24 | #include "tc_util.h" |
| 25 | |
| 26 | #define HTB_TC_VER 0x30003 |
| 27 | #if HTB_TC_VER >> 16 != TC_HTB_PROTOVER |
| 28 | #error "Different kernel and TC HTB versions" |
| 29 | #endif |
| 30 | |
| 31 | static void explain(void) |
| 32 | { |
| 33 | fprintf(stderr, "Usage: ... qdisc add ... htb [default N] [r2q N]\n" |
Eric Dumazet | b43f331 | 2013-09-13 09:10:01 -0700 | [diff] [blame] | 34 | " [direct_qlen P]\n" |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 35 | " default minor id of class to which unclassified packets are sent {0}\n" |
| 36 | " r2q DRR quantums are computed as rate in Bps/r2q {10}\n" |
| 37 | " debug string of 16 numbers each 0-3 {0}\n\n" |
Eric Dumazet | b43f331 | 2013-09-13 09:10:01 -0700 | [diff] [blame] | 38 | " direct_qlen Limit of the direct queue {in packets}\n" |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 39 | "... class add ... htb rate R1 [burst B1] [mpu B] [overhead O]\n" |
| 40 | " [prio P] [slot S] [pslot PS]\n" |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 41 | " [ceil R2] [cburst B2] [mtu MTU] [quantum Q]\n" |
| 42 | " rate rate allocated to this class (class can still borrow)\n" |
| 43 | " burst max bytes burst which can be accumulated during idle period {computed}\n" |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 44 | " mpu minimum packet size used in rate computations\n" |
| 45 | " overhead per-packet size overhead used in rate computations\n" |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 46 | " linklay adapting to a linklayer e.g. atm\n" |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 47 | " ceil definite upper class rate (no borrows) {rate}\n" |
| 48 | " cburst burst but for ceil {computed}\n" |
| 49 | " mtu max packet size we create rate map for {1600}\n" |
| 50 | " prio priority of leaf; lower are served first {0}\n" |
| 51 | " quantum how much bytes to serve from leaf at once {use r2q}\n" |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 52 | "\nTC HTB version %d.%d\n", HTB_TC_VER>>16, HTB_TC_VER&0xffff |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 53 | ); |
| 54 | } |
| 55 | |
| 56 | static void explain1(char *arg) |
| 57 | { |
| 58 | fprintf(stderr, "Illegal \"%s\"\n", arg); |
| 59 | explain(); |
| 60 | } |
| 61 | |
| 62 | |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 63 | static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 64 | { |
Hiroaki SHIMODA | 4d4da09 | 2014-03-08 22:10:03 +0900 | [diff] [blame] | 65 | unsigned int direct_qlen = ~0U; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 66 | struct tc_htb_glob opt; |
| 67 | struct rtattr *tail; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 68 | unsigned int i; char *p; |
| 69 | |
| 70 | memset(&opt, 0, sizeof(opt)); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 71 | opt.rate2quantum = 10; |
| 72 | opt.version = 3; |
| 73 | |
| 74 | while (argc > 0) { |
| 75 | if (matches(*argv, "r2q") == 0) { |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 76 | NEXT_ARG(); |
| 77 | if (get_u32(&opt.rate2quantum, *argv, 10)) { |
| 78 | explain1("r2q"); return -1; |
| 79 | } |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 80 | } else if (matches(*argv, "default") == 0) { |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 81 | NEXT_ARG(); |
| 82 | if (get_u32(&opt.defcls, *argv, 16)) { |
| 83 | explain1("default"); return -1; |
| 84 | } |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 85 | } else if (matches(*argv, "debug") == 0) { |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 86 | NEXT_ARG(); p = *argv; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 87 | for (i = 0; i < 16; i++, p++) { |
| 88 | if (*p < '0' || *p > '3') break; |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 89 | opt.debug |= (*p-'0')<<(2*i); |
| 90 | } |
Hiroaki SHIMODA | 4d4da09 | 2014-03-08 22:10:03 +0900 | [diff] [blame] | 91 | } else if (matches(*argv, "direct_qlen") == 0) { |
| 92 | NEXT_ARG(); |
| 93 | if (get_u32(&direct_qlen, *argv, 10)) { |
| 94 | explain1("direct_qlen"); return -1; |
| 95 | } |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 96 | } else { |
| 97 | fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 98 | explain(); |
| 99 | return -1; |
| 100 | } |
| 101 | argc--; argv++; |
| 102 | } |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 103 | tail = NLMSG_TAIL(n); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 104 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); |
| 105 | addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt))); |
Hiroaki SHIMODA | 4d4da09 | 2014-03-08 22:10:03 +0900 | [diff] [blame] | 106 | if (direct_qlen != ~0U) |
| 107 | addattr_l(n, 2024, TCA_HTB_DIRECT_QLEN, |
| 108 | &direct_qlen, sizeof(direct_qlen)); |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 109 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 114 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 115 | int ok = 0; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 116 | struct tc_htb_opt opt; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 117 | __u32 rtab[256], ctab[256]; |
| 118 | unsigned buffer = 0, cbuffer = 0; |
| 119 | int cell_log = -1, ccell_log = -1; |
| 120 | unsigned int mtu; |
Jesper Dangaard Brouer | bccd014 | 2007-09-11 16:59:58 +0200 | [diff] [blame] | 121 | unsigned short mpu = 0; |
| 122 | unsigned short overhead = 0; |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 123 | unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */ |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 124 | struct rtattr *tail; |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 125 | __u64 ceil64 = 0, rate64 = 0; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 126 | |
| 127 | memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */ |
| 128 | |
| 129 | while (argc > 0) { |
| 130 | if (matches(*argv, "prio") == 0) { |
| 131 | NEXT_ARG(); |
| 132 | if (get_u32(&opt.prio, *argv, 10)) { |
| 133 | explain1("prio"); return -1; |
| 134 | } |
| 135 | ok++; |
| 136 | } else if (matches(*argv, "mtu") == 0) { |
| 137 | NEXT_ARG(); |
| 138 | if (get_u32(&mtu, *argv, 10)) { |
| 139 | explain1("mtu"); return -1; |
| 140 | } |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 141 | } else if (matches(*argv, "mpu") == 0) { |
| 142 | NEXT_ARG(); |
Jesper Dangaard Brouer | bccd014 | 2007-09-11 16:59:58 +0200 | [diff] [blame] | 143 | if (get_u16(&mpu, *argv, 10)) { |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 144 | explain1("mpu"); return -1; |
| 145 | } |
| 146 | } else if (matches(*argv, "overhead") == 0) { |
| 147 | NEXT_ARG(); |
Jesper Dangaard Brouer | bccd014 | 2007-09-11 16:59:58 +0200 | [diff] [blame] | 148 | if (get_u16(&overhead, *argv, 10)) { |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 149 | explain1("overhead"); return -1; |
| 150 | } |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 151 | } else if (matches(*argv, "linklayer") == 0) { |
| 152 | NEXT_ARG(); |
| 153 | if (get_linklayer(&linklayer, *argv)) { |
| 154 | explain1("linklayer"); return -1; |
| 155 | } |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 156 | } else if (matches(*argv, "quantum") == 0) { |
| 157 | NEXT_ARG(); |
| 158 | if (get_u32(&opt.quantum, *argv, 10)) { |
| 159 | explain1("quantum"); return -1; |
| 160 | } |
| 161 | } else if (matches(*argv, "burst") == 0 || |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 162 | strcmp(*argv, "buffer") == 0 || |
| 163 | strcmp(*argv, "maxburst") == 0) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 164 | NEXT_ARG(); |
| 165 | if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) { |
| 166 | explain1("buffer"); |
| 167 | return -1; |
| 168 | } |
| 169 | ok++; |
| 170 | } else if (matches(*argv, "cburst") == 0 || |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 171 | strcmp(*argv, "cbuffer") == 0 || |
| 172 | strcmp(*argv, "cmaxburst") == 0) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 173 | NEXT_ARG(); |
| 174 | if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) { |
| 175 | explain1("cbuffer"); |
| 176 | return -1; |
| 177 | } |
| 178 | ok++; |
| 179 | } else if (strcmp(*argv, "ceil") == 0) { |
| 180 | NEXT_ARG(); |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 181 | if (ceil64) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 182 | fprintf(stderr, "Double \"ceil\" spec\n"); |
| 183 | return -1; |
| 184 | } |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 185 | if (get_rate64(&ceil64, *argv)) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 186 | explain1("ceil"); |
| 187 | return -1; |
| 188 | } |
| 189 | ok++; |
| 190 | } else if (strcmp(*argv, "rate") == 0) { |
| 191 | NEXT_ARG(); |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 192 | if (rate64) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 193 | fprintf(stderr, "Double \"rate\" spec\n"); |
| 194 | return -1; |
| 195 | } |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 196 | if (get_rate64(&rate64, *argv)) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 197 | explain1("rate"); |
| 198 | return -1; |
| 199 | } |
| 200 | ok++; |
| 201 | } else if (strcmp(*argv, "help") == 0) { |
| 202 | explain(); |
| 203 | return -1; |
| 204 | } else { |
| 205 | fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 206 | explain(); |
| 207 | return -1; |
| 208 | } |
| 209 | argc--; argv++; |
| 210 | } |
| 211 | |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 212 | /* if (!ok) |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 213 | return 0;*/ |
| 214 | |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 215 | if (!rate64) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 216 | fprintf(stderr, "\"rate\" is required.\n"); |
| 217 | return -1; |
| 218 | } |
| 219 | /* if ceil params are missing, use the same as rate */ |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 220 | if (!ceil64) |
| 221 | ceil64 = rate64; |
| 222 | |
| 223 | opt.rate.rate = (rate64 >= (1ULL << 32)) ? ~0U : rate64; |
| 224 | opt.ceil.rate = (ceil64 >= (1ULL << 32)) ? ~0U : ceil64; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 225 | |
| 226 | /* compute minimal allowed burst from rate; mtu is added here to make |
| 227 | sute that buffer is larger than mtu and to have some safeguard space */ |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 228 | if (!buffer) |
| 229 | buffer = rate64 / get_hz() + mtu; |
| 230 | if (!cbuffer) |
| 231 | cbuffer = ceil64 / get_hz() + mtu; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 232 | |
Jesper Dangaard Brouer | bccd014 | 2007-09-11 16:59:58 +0200 | [diff] [blame] | 233 | opt.ceil.overhead = overhead; |
| 234 | opt.rate.overhead = overhead; |
| 235 | |
| 236 | opt.ceil.mpu = mpu; |
| 237 | opt.rate.mpu = mpu; |
osdl.net!shemminger | a166d24 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 238 | |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 239 | if (tc_calc_rtable(&opt.rate, rtab, cell_log, mtu, linklayer) < 0) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 240 | fprintf(stderr, "htb: failed to calculate rate table.\n"); |
| 241 | return -1; |
| 242 | } |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 243 | opt.buffer = tc_calc_xmittime(rate64, buffer); |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 244 | |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 245 | if (tc_calc_rtable(&opt.ceil, ctab, ccell_log, mtu, linklayer) < 0) { |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 246 | fprintf(stderr, "htb: failed to calculate ceil rate table.\n"); |
| 247 | return -1; |
| 248 | } |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 249 | opt.cbuffer = tc_calc_xmittime(ceil64, cbuffer); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 250 | |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 251 | tail = NLMSG_TAIL(n); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 252 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 253 | |
| 254 | if (rate64 >= (1ULL << 32)) |
| 255 | addattr_l(n, 1124, TCA_HTB_RATE64, &rate64, sizeof(rate64)); |
| 256 | |
| 257 | if (ceil64 >= (1ULL << 32)) |
| 258 | addattr_l(n, 1224, TCA_HTB_CEIL64, &ceil64, sizeof(ceil64)); |
| 259 | |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 260 | addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt)); |
| 261 | addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024); |
| 262 | addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024); |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 263 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 268 | { |
Eric Dumazet | b43f331 | 2013-09-13 09:10:01 -0700 | [diff] [blame] | 269 | struct rtattr *tb[TCA_HTB_MAX + 1]; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 270 | struct tc_htb_opt *hopt; |
| 271 | struct tc_htb_glob *gopt; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 272 | double buffer, cbuffer; |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 273 | unsigned int linklayer; |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 274 | __u64 rate64, ceil64; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 275 | |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 276 | SPRINT_BUF(b1); |
| 277 | SPRINT_BUF(b2); |
Dmitrii Shcherbakov | 467f9fc | 2015-12-19 18:26:03 +0300 | [diff] [blame] | 278 | SPRINT_BUF(b3); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 279 | |
| 280 | if (opt == NULL) |
| 281 | return 0; |
| 282 | |
Eric Dumazet | b43f331 | 2013-09-13 09:10:01 -0700 | [diff] [blame] | 283 | parse_rtattr_nested(tb, TCA_HTB_MAX, opt); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 284 | |
| 285 | if (tb[TCA_HTB_PARMS]) { |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 286 | hopt = RTA_DATA(tb[TCA_HTB_PARMS]); |
| 287 | if (RTA_PAYLOAD(tb[TCA_HTB_PARMS]) < sizeof(*hopt)) return -1; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 288 | |
| 289 | if (!hopt->level) { |
| 290 | fprintf(f, "prio %d ", (int)hopt->prio); |
| 291 | if (show_details) |
| 292 | fprintf(f, "quantum %d ", (int)hopt->quantum); |
| 293 | } |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 294 | |
| 295 | rate64 = hopt->rate.rate; |
| 296 | if (tb[TCA_HTB_RATE64] && |
| 297 | RTA_PAYLOAD(tb[TCA_HTB_RATE64]) >= sizeof(rate64)) { |
| 298 | rate64 = rta_getattr_u64(tb[TCA_HTB_RATE64]); |
| 299 | } |
| 300 | |
| 301 | ceil64 = hopt->ceil.rate; |
| 302 | if (tb[TCA_HTB_CEIL64] && |
| 303 | RTA_PAYLOAD(tb[TCA_HTB_CEIL64]) >= sizeof(ceil64)) |
| 304 | ceil64 = rta_getattr_u64(tb[TCA_HTB_CEIL64]); |
| 305 | |
| 306 | fprintf(f, "rate %s ", sprint_rate(rate64, b1)); |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 307 | if (hopt->rate.overhead) |
| 308 | fprintf(f, "overhead %u ", hopt->rate.overhead); |
Eric Dumazet | 8334bb3 | 2013-11-12 14:34:07 -0800 | [diff] [blame] | 309 | buffer = tc_calc_xmitsize(rate64, hopt->buffer); |
| 310 | |
| 311 | fprintf(f, "ceil %s ", sprint_rate(ceil64, b1)); |
| 312 | cbuffer = tc_calc_xmitsize(ceil64, hopt->cbuffer); |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 313 | linklayer = (hopt->rate.linklayer & TC_LINKLAYER_MASK); |
| 314 | if (linklayer > TC_LINKLAYER_ETHERNET || show_details) |
Dmitrii Shcherbakov | 467f9fc | 2015-12-19 18:26:03 +0300 | [diff] [blame] | 315 | fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b3)); |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 316 | if (show_details) { |
Dmitrii Shcherbakov | 1aea7fe | 2015-12-19 18:25:52 +0300 | [diff] [blame] | 317 | fprintf(f, "burst %s/%u mpu %s ", |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 318 | sprint_size(buffer, b1), |
| 319 | 1<<hopt->rate.cell_log, |
Dmitrii Shcherbakov | 1aea7fe | 2015-12-19 18:25:52 +0300 | [diff] [blame] | 320 | sprint_size(hopt->rate.mpu, b2)); |
| 321 | fprintf(f, "cburst %s/%u mpu %s ", |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 322 | sprint_size(cbuffer, b1), |
| 323 | 1<<hopt->ceil.cell_log, |
Dmitrii Shcherbakov | 1aea7fe | 2015-12-19 18:25:52 +0300 | [diff] [blame] | 324 | sprint_size(hopt->ceil.mpu, b2)); |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 325 | fprintf(f, "level %d ", (int)hopt->level); |
| 326 | } else { |
| 327 | fprintf(f, "burst %s ", sprint_size(buffer, b1)); |
| 328 | fprintf(f, "cburst %s ", sprint_size(cbuffer, b1)); |
| 329 | } |
| 330 | if (show_raw) |
| 331 | fprintf(f, "buffer [%08x] cbuffer [%08x] ", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 332 | hopt->buffer, hopt->cbuffer); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 333 | } |
| 334 | if (tb[TCA_HTB_INIT]) { |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 335 | gopt = RTA_DATA(tb[TCA_HTB_INIT]); |
| 336 | if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1; |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 337 | |
Stephen Hemminger | 22fa92e | 2013-06-07 08:54:45 -0700 | [diff] [blame] | 338 | fprintf(f, "r2q %d default %x direct_packets_stat %u", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 339 | gopt->rate2quantum, gopt->defcls, gopt->direct_pkts); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 340 | if (show_details) |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 341 | fprintf(f, " ver %d.%d", gopt->version >> 16, gopt->version & 0xffff); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 342 | } |
Eric Dumazet | b43f331 | 2013-09-13 09:10:01 -0700 | [diff] [blame] | 343 | if (tb[TCA_HTB_DIRECT_QLEN] && |
| 344 | RTA_PAYLOAD(tb[TCA_HTB_DIRECT_QLEN]) >= sizeof(__u32)) { |
| 345 | __u32 direct_qlen = rta_getattr_u32(tb[TCA_HTB_DIRECT_QLEN]); |
| 346 | |
| 347 | fprintf(f, " direct_qlen %u", direct_qlen); |
| 348 | } |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats) |
| 353 | { |
| 354 | struct tc_htb_xstats *st; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 355 | |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 356 | if (xstats == NULL) |
| 357 | return 0; |
| 358 | |
| 359 | if (RTA_PAYLOAD(xstats) < sizeof(*st)) |
| 360 | return -1; |
| 361 | |
| 362 | st = RTA_DATA(xstats); |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 363 | fprintf(f, " lended: %u borrowed: %u giants: %u\n", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 364 | st->lends, st->borrows, st->giants); |
| 365 | fprintf(f, " tokens: %d ctokens: %d\n", st->tokens, st->ctokens); |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 369 | struct qdisc_util htb_qdisc_util = { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 370 | .id = "htb", |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 371 | .parse_qopt = htb_parse_opt, |
| 372 | .print_qopt = htb_print_opt, |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 373 | .print_xstats = htb_print_xstats, |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 374 | .parse_copt = htb_parse_class_opt, |
| 375 | .print_copt = htb_print_opt, |
org[shemminger]!shemminger | 9e9d615 | 2004-06-07 22:04:51 +0000 | [diff] [blame] | 376 | }; |