osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * m_police.c Parse/print policing module options. |
| 3 | * |
| 4 | * This program is free software; you can u32istribute 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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 10 | * FIXES: 19990619 - J Hadi Salim (hadi@cyberus.ca) |
| 11 | * simple addattr packaging fix. |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 12 | * 2002: J Hadi Salim - Add tc action extensions syntax |
| 13 | * |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <syslog.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
| 24 | #include <string.h> |
| 25 | |
| 26 | #include "utils.h" |
| 27 | #include "tc_util.h" |
| 28 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 29 | struct action_util police_action_util = { |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 30 | .id = "police", |
| 31 | .parse_aopt = act_parse_police, |
| 32 | .print_aopt = print_police, |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Jamal Hadi Salim | ebf3208 | 2006-08-08 12:10:08 -0700 | [diff] [blame] | 35 | static void usage(void) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 36 | { |
| 37 | fprintf(stderr, "Usage: ... police rate BPS burst BYTES[/BYTES] [ mtu BYTES[/BYTES] ]\n"); |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 38 | fprintf(stderr, " [ peakrate BPS ] [ avrate BPS ] [ overhead BYTES ]\n"); |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 39 | fprintf(stderr, " [ linklayer TYPE ] [ ACTIONTERM ]\n"); |
| 40 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 41 | fprintf(stderr, "New Syntax ACTIONTERM := conform-exceed <EXCEEDACT>[/NOTEXCEEDACT]\n"); |
| 42 | fprintf(stderr, "Where: *EXCEEDACT := pipe | ok | reclassify | drop | continue\n"); |
| 43 | fprintf(stderr, "Where: pipe is only valid for new syntax\n"); |
Jamal Hadi Salim | ebf3208 | 2006-08-08 12:10:08 -0700 | [diff] [blame] | 44 | exit(-1); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void explain1(char *arg) |
| 48 | { |
| 49 | fprintf(stderr, "Illegal \"%s\"\n", arg); |
| 50 | } |
| 51 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 52 | static const char *police_action_n2a(int action, char *buf, int len) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 53 | { |
| 54 | switch (action) { |
| 55 | case -1: |
| 56 | return "continue"; |
| 57 | break; |
| 58 | case TC_POLICE_OK: |
| 59 | return "pass"; |
| 60 | break; |
| 61 | case TC_POLICE_SHOT: |
| 62 | return "drop"; |
| 63 | break; |
| 64 | case TC_POLICE_RECLASSIFY: |
| 65 | return "reclassify"; |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 66 | case TC_POLICE_PIPE: |
| 67 | return "pipe"; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 68 | default: |
| 69 | snprintf(buf, len, "%d", action); |
| 70 | return buf; |
| 71 | } |
| 72 | } |
| 73 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 74 | static int police_action_a2n(const char *arg, int *result) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 75 | { |
| 76 | int res; |
| 77 | |
| 78 | if (matches(arg, "continue") == 0) |
| 79 | res = -1; |
| 80 | else if (matches(arg, "drop") == 0) |
| 81 | res = TC_POLICE_SHOT; |
| 82 | else if (matches(arg, "shot") == 0) |
| 83 | res = TC_POLICE_SHOT; |
| 84 | else if (matches(arg, "pass") == 0) |
| 85 | res = TC_POLICE_OK; |
| 86 | else if (strcmp(arg, "ok") == 0) |
| 87 | res = TC_POLICE_OK; |
| 88 | else if (matches(arg, "reclassify") == 0) |
| 89 | res = TC_POLICE_RECLASSIFY; |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 90 | else if (matches(arg, "pipe") == 0) |
| 91 | res = TC_POLICE_PIPE; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 92 | else { |
| 93 | char dummy; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 94 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 95 | if (sscanf(arg, "%d%c", &res, &dummy) != 1) |
| 96 | return -1; |
| 97 | } |
| 98 | *result = res; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 103 | static int get_police_result(int *action, int *result, char *arg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 104 | { |
| 105 | char *p = strchr(arg, '/'); |
| 106 | |
| 107 | if (p) |
| 108 | *p = 0; |
| 109 | |
| 110 | if (police_action_a2n(arg, action)) { |
| 111 | if (p) |
| 112 | *p = '/'; |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | if (p) { |
| 117 | *p = '/'; |
| 118 | if (police_action_a2n(p+1, result)) |
| 119 | return -1; |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 124 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 125 | int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 126 | { |
| 127 | int argc = *argc_p; |
| 128 | char **argv = *argv_p; |
| 129 | int res = -1; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 130 | int ok = 0; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 131 | struct tc_police p; |
| 132 | __u32 rtab[256]; |
| 133 | __u32 ptab[256]; |
| 134 | __u32 avrate = 0; |
| 135 | int presult = 0; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 136 | unsigned buffer = 0, mtu = 0, mpu = 0; |
| 137 | unsigned short overhead = 0; |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 138 | unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */ |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 139 | int Rcell_log = -1, Pcell_log = -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 140 | struct rtattr *tail; |
| 141 | |
| 142 | memset(&p, 0, sizeof(p)); |
| 143 | p.action = TC_POLICE_RECLASSIFY; |
| 144 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 145 | if (a) /* new way of doing things */ |
| 146 | NEXT_ARG(); |
| 147 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 148 | if (argc <= 0) |
| 149 | return -1; |
| 150 | |
| 151 | while (argc > 0) { |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 152 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 153 | if (matches(*argv, "index") == 0) { |
| 154 | NEXT_ARG(); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 155 | if (get_u32(&p.index, *argv, 10)) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 156 | fprintf(stderr, "Illegal \"index\"\n"); |
| 157 | return -1; |
| 158 | } |
| 159 | } else if (matches(*argv, "burst") == 0 || |
| 160 | strcmp(*argv, "buffer") == 0 || |
| 161 | strcmp(*argv, "maxburst") == 0) { |
| 162 | NEXT_ARG(); |
| 163 | if (buffer) { |
| 164 | fprintf(stderr, "Double \"buffer/burst\" spec\n"); |
| 165 | return -1; |
| 166 | } |
| 167 | if (get_size_and_cell(&buffer, &Rcell_log, *argv) < 0) { |
| 168 | explain1("buffer"); |
| 169 | return -1; |
| 170 | } |
| 171 | } else if (strcmp(*argv, "mtu") == 0 || |
| 172 | strcmp(*argv, "minburst") == 0) { |
| 173 | NEXT_ARG(); |
| 174 | if (mtu) { |
| 175 | fprintf(stderr, "Double \"mtu/minburst\" spec\n"); |
| 176 | return -1; |
| 177 | } |
| 178 | if (get_size_and_cell(&mtu, &Pcell_log, *argv) < 0) { |
| 179 | explain1("mtu"); |
| 180 | return -1; |
| 181 | } |
| 182 | } else if (strcmp(*argv, "mpu") == 0) { |
| 183 | NEXT_ARG(); |
| 184 | if (mpu) { |
| 185 | fprintf(stderr, "Double \"mpu\" spec\n"); |
| 186 | return -1; |
| 187 | } |
| 188 | if (get_size(&mpu, *argv)) { |
| 189 | explain1("mpu"); |
| 190 | return -1; |
| 191 | } |
| 192 | } else if (strcmp(*argv, "rate") == 0) { |
| 193 | NEXT_ARG(); |
| 194 | if (p.rate.rate) { |
| 195 | fprintf(stderr, "Double \"rate\" spec\n"); |
| 196 | return -1; |
| 197 | } |
| 198 | if (get_rate(&p.rate.rate, *argv)) { |
| 199 | explain1("rate"); |
| 200 | return -1; |
| 201 | } |
| 202 | } else if (strcmp(*argv, "avrate") == 0) { |
| 203 | NEXT_ARG(); |
| 204 | if (avrate) { |
| 205 | fprintf(stderr, "Double \"avrate\" spec\n"); |
| 206 | return -1; |
| 207 | } |
| 208 | if (get_rate(&avrate, *argv)) { |
| 209 | explain1("avrate"); |
| 210 | return -1; |
| 211 | } |
| 212 | } else if (matches(*argv, "peakrate") == 0) { |
| 213 | NEXT_ARG(); |
| 214 | if (p.peakrate.rate) { |
| 215 | fprintf(stderr, "Double \"peakrate\" spec\n"); |
| 216 | return -1; |
| 217 | } |
| 218 | if (get_rate(&p.peakrate.rate, *argv)) { |
| 219 | explain1("peakrate"); |
| 220 | return -1; |
| 221 | } |
| 222 | } else if (matches(*argv, "reclassify") == 0) { |
| 223 | p.action = TC_POLICE_RECLASSIFY; |
| 224 | } else if (matches(*argv, "drop") == 0 || |
| 225 | matches(*argv, "shot") == 0) { |
| 226 | p.action = TC_POLICE_SHOT; |
| 227 | } else if (matches(*argv, "continue") == 0) { |
| 228 | p.action = TC_POLICE_UNSPEC; |
| 229 | } else if (matches(*argv, "pass") == 0) { |
| 230 | p.action = TC_POLICE_OK; |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 231 | } else if (matches(*argv, "pipe") == 0) { |
| 232 | p.action = TC_POLICE_PIPE; |
Jamal Hadi Salim | 4bfb21c | 2013-12-21 17:16:53 -0500 | [diff] [blame] | 233 | } else if (strcmp(*argv, "conform-exceed") == 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 234 | NEXT_ARG(); |
| 235 | if (get_police_result(&p.action, &presult, *argv)) { |
| 236 | fprintf(stderr, "Illegal \"action\"\n"); |
| 237 | return -1; |
| 238 | } |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 239 | } else if (matches(*argv, "overhead") == 0) { |
| 240 | NEXT_ARG(); |
| 241 | if (get_u16(&overhead, *argv, 10)) { |
| 242 | explain1("overhead"); return -1; |
| 243 | } |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 244 | } else if (matches(*argv, "linklayer") == 0) { |
| 245 | NEXT_ARG(); |
| 246 | if (get_linklayer(&linklayer, *argv)) { |
| 247 | explain1("linklayer"); return -1; |
| 248 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 249 | } else if (strcmp(*argv, "help") == 0) { |
Jamal Hadi Salim | ebf3208 | 2006-08-08 12:10:08 -0700 | [diff] [blame] | 250 | usage(); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 251 | } else { |
Stephen Hemminger | ef1d6f9 | 2008-01-02 16:34:58 -0800 | [diff] [blame] | 252 | break; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 253 | } |
| 254 | ok++; |
| 255 | argc--; argv++; |
| 256 | } |
| 257 | |
| 258 | if (!ok) |
| 259 | return -1; |
| 260 | |
| 261 | if (p.rate.rate && !buffer) { |
| 262 | fprintf(stderr, "\"burst\" requires \"rate\".\n"); |
| 263 | return -1; |
| 264 | } |
| 265 | if (p.peakrate.rate) { |
| 266 | if (!p.rate.rate) { |
| 267 | fprintf(stderr, "\"peakrate\" requires \"rate\".\n"); |
| 268 | return -1; |
| 269 | } |
| 270 | if (!mtu) { |
| 271 | fprintf(stderr, "\"mtu\" is required, if \"peakrate\" is requested.\n"); |
| 272 | return -1; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (p.rate.rate) { |
Jesper Dangaard Brouer | d5f46f9 | 2007-09-05 10:47:47 +0200 | [diff] [blame] | 277 | p.rate.mpu = mpu; |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 278 | p.rate.overhead = overhead; |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 279 | if (tc_calc_rtable(&p.rate, rtab, Rcell_log, mtu, linklayer) < 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 280 | fprintf(stderr, "TBF: failed to calculate rate table.\n"); |
| 281 | return -1; |
| 282 | } |
| 283 | p.burst = tc_calc_xmittime(p.rate.rate, buffer); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 284 | } |
| 285 | p.mtu = mtu; |
| 286 | if (p.peakrate.rate) { |
Jesper Dangaard Brouer | d5f46f9 | 2007-09-05 10:47:47 +0200 | [diff] [blame] | 287 | p.peakrate.mpu = mpu; |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 288 | p.peakrate.overhead = overhead; |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 289 | if (tc_calc_rtable(&p.peakrate, ptab, Pcell_log, mtu, linklayer) < 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 290 | fprintf(stderr, "POLICE: failed to calculate peak rate table.\n"); |
| 291 | return -1; |
| 292 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 293 | } |
| 294 | |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 295 | tail = NLMSG_TAIL(n); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 296 | addattr_l(n, MAX_MSG, tca_id, NULL, 0); |
| 297 | addattr_l(n, MAX_MSG, TCA_POLICE_TBF, &p, sizeof(p)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 298 | if (p.rate.rate) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 299 | addattr_l(n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 300 | if (p.peakrate.rate) |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 301 | addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 302 | if (avrate) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 303 | addattr32(n, MAX_MSG, TCA_POLICE_AVRATE, avrate); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 304 | if (presult) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 305 | addattr32(n, MAX_MSG, TCA_POLICE_RESULT, presult); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 306 | |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 307 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 308 | res = 0; |
| 309 | |
| 310 | *argc_p = argc; |
| 311 | *argv_p = argv; |
| 312 | return res; |
| 313 | } |
| 314 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 315 | int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) |
| 316 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 317 | return act_parse_police(NULL, argc_p, argv_p, tca_id, n); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 318 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 319 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 320 | int |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 321 | print_police(struct action_util *a, FILE *f, struct rtattr *arg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 322 | { |
| 323 | SPRINT_BUF(b1); |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 324 | SPRINT_BUF(b2); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 325 | struct tc_police *p; |
| 326 | struct rtattr *tb[TCA_POLICE_MAX+1]; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 327 | unsigned int buffer; |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 328 | unsigned int linklayer; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 329 | |
| 330 | if (arg == NULL) |
| 331 | return 0; |
| 332 | |
6!tgraf | 14ee9e6 | 2005-01-18 22:11:58 +0000 | [diff] [blame] | 333 | parse_rtattr_nested(tb, TCA_POLICE_MAX, arg); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 334 | |
| 335 | if (tb[TCA_POLICE_TBF] == NULL) { |
| 336 | fprintf(f, "[NULL police tbf]"); |
| 337 | return 0; |
| 338 | } |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 339 | #ifndef STOOPID_8BYTE |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 340 | if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) { |
| 341 | fprintf(f, "[truncated police tbf]"); |
| 342 | return -1; |
| 343 | } |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 344 | #endif |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 345 | p = RTA_DATA(tb[TCA_POLICE_TBF]); |
| 346 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 347 | fprintf(f, " police 0x%x ", p->index); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 348 | fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1)); |
Patrick McHardy | 76dc0aa | 2007-03-04 20:14:57 +0100 | [diff] [blame] | 349 | buffer = tc_calc_xmitsize(p->rate.rate, p->burst); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 350 | fprintf(f, "burst %s ", sprint_size(buffer, b1)); |
| 351 | fprintf(f, "mtu %s ", sprint_size(p->mtu, b1)); |
| 352 | if (show_raw) |
| 353 | fprintf(f, "[%08x] ", p->burst); |
| 354 | if (p->peakrate.rate) |
| 355 | fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1)); |
| 356 | if (tb[TCA_POLICE_AVRATE]) |
Stephen Hemminger | ff24746 | 2012-04-10 08:47:55 -0700 | [diff] [blame] | 357 | fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1)); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 358 | fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1))); |
| 359 | if (tb[TCA_POLICE_RESULT]) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 360 | fprintf(f, "/%s ", police_action_n2a(*(int *)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1))); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 361 | } else |
| 362 | fprintf(f, " "); |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 363 | fprintf(f, "overhead %ub ", p->rate.overhead); |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 364 | linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK); |
| 365 | if (linklayer > TC_LINKLAYER_ETHERNET || show_details) |
| 366 | fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2)); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 367 | fprintf(f, "\nref %d bind %d\n", p->refcnt, p->bindcnt); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 372 | int |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 373 | tc_print_police(FILE *f, struct rtattr *arg) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 374 | return print_police(&police_action_util, f, arg); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 375 | } |