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 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 102 | static int get_police_result(int *action, int *result, char *arg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 103 | { |
| 104 | char *p = strchr(arg, '/'); |
| 105 | |
| 106 | if (p) |
| 107 | *p = 0; |
| 108 | |
| 109 | if (police_action_a2n(arg, action)) { |
| 110 | if (p) |
| 111 | *p = '/'; |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | if (p) { |
| 116 | *p = '/'; |
| 117 | if (police_action_a2n(p+1, result)) |
| 118 | return -1; |
| 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 123 | int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p, |
| 124 | int tca_id, struct nlmsghdr *n) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 125 | { |
| 126 | int argc = *argc_p; |
| 127 | char **argv = *argv_p; |
| 128 | int res = -1; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 129 | int ok = 0; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 130 | struct tc_police p; |
| 131 | __u32 rtab[256]; |
| 132 | __u32 ptab[256]; |
| 133 | __u32 avrate = 0; |
| 134 | int presult = 0; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 135 | unsigned buffer = 0, mtu = 0, mpu = 0; |
| 136 | unsigned short overhead = 0; |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 137 | unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */ |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 138 | int Rcell_log = -1, Pcell_log = -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 139 | struct rtattr *tail; |
| 140 | |
| 141 | memset(&p, 0, sizeof(p)); |
| 142 | p.action = TC_POLICE_RECLASSIFY; |
| 143 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 144 | if (a) /* new way of doing things */ |
| 145 | NEXT_ARG(); |
| 146 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 147 | if (argc <= 0) |
| 148 | return -1; |
| 149 | |
| 150 | while (argc > 0) { |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 151 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 152 | if (matches(*argv, "index") == 0) { |
| 153 | NEXT_ARG(); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 154 | if (get_u32(&p.index, *argv, 10)) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 155 | fprintf(stderr, "Illegal \"index\"\n"); |
| 156 | return -1; |
| 157 | } |
| 158 | } else if (matches(*argv, "burst") == 0 || |
| 159 | strcmp(*argv, "buffer") == 0 || |
| 160 | strcmp(*argv, "maxburst") == 0) { |
| 161 | NEXT_ARG(); |
| 162 | if (buffer) { |
| 163 | fprintf(stderr, "Double \"buffer/burst\" spec\n"); |
| 164 | return -1; |
| 165 | } |
| 166 | if (get_size_and_cell(&buffer, &Rcell_log, *argv) < 0) { |
| 167 | explain1("buffer"); |
| 168 | return -1; |
| 169 | } |
| 170 | } else if (strcmp(*argv, "mtu") == 0 || |
| 171 | strcmp(*argv, "minburst") == 0) { |
| 172 | NEXT_ARG(); |
| 173 | if (mtu) { |
| 174 | fprintf(stderr, "Double \"mtu/minburst\" spec\n"); |
| 175 | return -1; |
| 176 | } |
| 177 | if (get_size_and_cell(&mtu, &Pcell_log, *argv) < 0) { |
| 178 | explain1("mtu"); |
| 179 | return -1; |
| 180 | } |
| 181 | } else if (strcmp(*argv, "mpu") == 0) { |
| 182 | NEXT_ARG(); |
| 183 | if (mpu) { |
| 184 | fprintf(stderr, "Double \"mpu\" spec\n"); |
| 185 | return -1; |
| 186 | } |
| 187 | if (get_size(&mpu, *argv)) { |
| 188 | explain1("mpu"); |
| 189 | return -1; |
| 190 | } |
| 191 | } else if (strcmp(*argv, "rate") == 0) { |
| 192 | NEXT_ARG(); |
| 193 | if (p.rate.rate) { |
| 194 | fprintf(stderr, "Double \"rate\" spec\n"); |
| 195 | return -1; |
| 196 | } |
| 197 | if (get_rate(&p.rate.rate, *argv)) { |
| 198 | explain1("rate"); |
| 199 | return -1; |
| 200 | } |
| 201 | } else if (strcmp(*argv, "avrate") == 0) { |
| 202 | NEXT_ARG(); |
| 203 | if (avrate) { |
| 204 | fprintf(stderr, "Double \"avrate\" spec\n"); |
| 205 | return -1; |
| 206 | } |
| 207 | if (get_rate(&avrate, *argv)) { |
| 208 | explain1("avrate"); |
| 209 | return -1; |
| 210 | } |
| 211 | } else if (matches(*argv, "peakrate") == 0) { |
| 212 | NEXT_ARG(); |
| 213 | if (p.peakrate.rate) { |
| 214 | fprintf(stderr, "Double \"peakrate\" spec\n"); |
| 215 | return -1; |
| 216 | } |
| 217 | if (get_rate(&p.peakrate.rate, *argv)) { |
| 218 | explain1("peakrate"); |
| 219 | return -1; |
| 220 | } |
| 221 | } else if (matches(*argv, "reclassify") == 0) { |
| 222 | p.action = TC_POLICE_RECLASSIFY; |
| 223 | } else if (matches(*argv, "drop") == 0 || |
| 224 | matches(*argv, "shot") == 0) { |
| 225 | p.action = TC_POLICE_SHOT; |
| 226 | } else if (matches(*argv, "continue") == 0) { |
| 227 | p.action = TC_POLICE_UNSPEC; |
| 228 | } else if (matches(*argv, "pass") == 0) { |
| 229 | p.action = TC_POLICE_OK; |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 230 | } else if (matches(*argv, "pipe") == 0) { |
| 231 | p.action = TC_POLICE_PIPE; |
Jamal Hadi Salim | 4bfb21c | 2013-12-21 17:16:53 -0500 | [diff] [blame] | 232 | } else if (strcmp(*argv, "conform-exceed") == 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 233 | NEXT_ARG(); |
| 234 | if (get_police_result(&p.action, &presult, *argv)) { |
| 235 | fprintf(stderr, "Illegal \"action\"\n"); |
| 236 | return -1; |
| 237 | } |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 238 | } else if (matches(*argv, "overhead") == 0) { |
| 239 | NEXT_ARG(); |
| 240 | if (get_u16(&overhead, *argv, 10)) { |
| 241 | explain1("overhead"); return -1; |
| 242 | } |
Jesper Dangaard Brouer | 292f29b | 2008-04-09 23:01:01 +0200 | [diff] [blame] | 243 | } else if (matches(*argv, "linklayer") == 0) { |
| 244 | NEXT_ARG(); |
| 245 | if (get_linklayer(&linklayer, *argv)) { |
| 246 | explain1("linklayer"); return -1; |
| 247 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 248 | } else if (strcmp(*argv, "help") == 0) { |
Jamal Hadi Salim | ebf3208 | 2006-08-08 12:10:08 -0700 | [diff] [blame] | 249 | usage(); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 250 | } else { |
Stephen Hemminger | ef1d6f9 | 2008-01-02 16:34:58 -0800 | [diff] [blame] | 251 | break; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 252 | } |
| 253 | ok++; |
| 254 | argc--; argv++; |
| 255 | } |
| 256 | |
| 257 | if (!ok) |
| 258 | return -1; |
| 259 | |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 260 | if (p.rate.rate && avrate) |
| 261 | return -1; |
| 262 | |
| 263 | /* Must at least do late binding, use TB or ewma policing */ |
| 264 | if (!p.rate.rate && !avrate && !p.index) { |
| 265 | fprintf(stderr, "\"rate\" or \"avrate\" MUST be specified.\n"); |
| 266 | return -1; |
| 267 | } |
| 268 | |
| 269 | /* When the TB policer is used, burst is required */ |
| 270 | if (p.rate.rate && !buffer && !avrate) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 271 | fprintf(stderr, "\"burst\" requires \"rate\".\n"); |
| 272 | return -1; |
| 273 | } |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 274 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 275 | if (p.peakrate.rate) { |
| 276 | if (!p.rate.rate) { |
| 277 | fprintf(stderr, "\"peakrate\" requires \"rate\".\n"); |
| 278 | return -1; |
| 279 | } |
| 280 | if (!mtu) { |
| 281 | fprintf(stderr, "\"mtu\" is required, if \"peakrate\" is requested.\n"); |
| 282 | return -1; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (p.rate.rate) { |
Jesper Dangaard Brouer | d5f46f9 | 2007-09-05 10:47:47 +0200 | [diff] [blame] | 287 | p.rate.mpu = mpu; |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 288 | p.rate.overhead = overhead; |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 289 | if (tc_calc_rtable(&p.rate, rtab, Rcell_log, mtu, |
| 290 | linklayer) < 0) { |
| 291 | fprintf(stderr, "POLICE: failed to calculate rate table.\n"); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 292 | return -1; |
| 293 | } |
| 294 | p.burst = tc_calc_xmittime(p.rate.rate, buffer); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 295 | } |
| 296 | p.mtu = mtu; |
| 297 | if (p.peakrate.rate) { |
Jesper Dangaard Brouer | d5f46f9 | 2007-09-05 10:47:47 +0200 | [diff] [blame] | 298 | p.peakrate.mpu = mpu; |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 299 | p.peakrate.overhead = overhead; |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 300 | if (tc_calc_rtable(&p.peakrate, ptab, Pcell_log, mtu, |
| 301 | linklayer) < 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 302 | fprintf(stderr, "POLICE: failed to calculate peak rate table.\n"); |
| 303 | return -1; |
| 304 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 305 | } |
| 306 | |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 307 | tail = NLMSG_TAIL(n); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 308 | addattr_l(n, MAX_MSG, tca_id, NULL, 0); |
| 309 | addattr_l(n, MAX_MSG, TCA_POLICE_TBF, &p, sizeof(p)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 310 | if (p.rate.rate) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 311 | addattr_l(n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 312 | if (p.peakrate.rate) |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 313 | addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 314 | if (avrate) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 315 | addattr32(n, MAX_MSG, TCA_POLICE_AVRATE, avrate); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 316 | if (presult) |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 317 | addattr32(n, MAX_MSG, TCA_POLICE_RESULT, presult); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 318 | |
6!tgraf | 1b52a76 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 319 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 320 | res = 0; |
| 321 | |
| 322 | *argc_p = argc; |
| 323 | *argv_p = argv; |
| 324 | return res; |
| 325 | } |
| 326 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 327 | int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) |
| 328 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 329 | 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] | 330 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 331 | |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 332 | int print_police(struct action_util *a, FILE *f, struct rtattr *arg) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 333 | { |
| 334 | SPRINT_BUF(b1); |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 335 | SPRINT_BUF(b2); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 336 | struct tc_police *p; |
| 337 | struct rtattr *tb[TCA_POLICE_MAX+1]; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 338 | unsigned int buffer; |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 339 | unsigned int linklayer; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 340 | |
| 341 | if (arg == NULL) |
| 342 | return 0; |
| 343 | |
6!tgraf | 14ee9e6 | 2005-01-18 22:11:58 +0000 | [diff] [blame] | 344 | parse_rtattr_nested(tb, TCA_POLICE_MAX, arg); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 345 | |
| 346 | if (tb[TCA_POLICE_TBF] == NULL) { |
| 347 | fprintf(f, "[NULL police tbf]"); |
| 348 | return 0; |
| 349 | } |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 350 | #ifndef STOOPID_8BYTE |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 351 | if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) { |
| 352 | fprintf(f, "[truncated police tbf]"); |
| 353 | return -1; |
| 354 | } |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 355 | #endif |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 356 | p = RTA_DATA(tb[TCA_POLICE_TBF]); |
| 357 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 358 | fprintf(f, " police 0x%x ", p->index); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 359 | fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1)); |
Patrick McHardy | 76dc0aa | 2007-03-04 20:14:57 +0100 | [diff] [blame] | 360 | buffer = tc_calc_xmitsize(p->rate.rate, p->burst); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 361 | fprintf(f, "burst %s ", sprint_size(buffer, b1)); |
| 362 | fprintf(f, "mtu %s ", sprint_size(p->mtu, b1)); |
| 363 | if (show_raw) |
| 364 | fprintf(f, "[%08x] ", p->burst); |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 365 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 366 | if (p->peakrate.rate) |
| 367 | fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1)); |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 368 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 369 | if (tb[TCA_POLICE_AVRATE]) |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 370 | fprintf(f, "avrate %s ", |
| 371 | sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), |
| 372 | b1)); |
| 373 | fprintf(f, "action %s", |
| 374 | police_action_n2a(p->action, b1, sizeof(b1))); |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 375 | |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 376 | if (tb[TCA_POLICE_RESULT]) { |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 377 | __u32 action = rta_getattr_u32(tb[TCA_POLICE_RESULT]); |
| 378 | |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 379 | fprintf(f, "/%s", |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 380 | police_action_n2a(action, b1, sizeof(b1))); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 381 | } else |
| 382 | fprintf(f, " "); |
Stephen Hemminger | e6263c8 | 2016-05-31 12:22:45 -0700 | [diff] [blame] | 383 | |
Jesper Dangaard Brouer | f71f75f | 2008-03-23 23:53:57 +0100 | [diff] [blame] | 384 | fprintf(f, "overhead %ub ", p->rate.overhead); |
Jesper Dangaard Brouer | 3e92ff5 | 2013-08-30 14:02:10 +0200 | [diff] [blame] | 385 | linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK); |
| 386 | if (linklayer > TC_LINKLAYER_ETHERNET || show_details) |
| 387 | fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2)); |
Jamal Hadi Salim | ead954c | 2016-05-25 06:05:49 -0400 | [diff] [blame] | 388 | fprintf(f, "\n\tref %d bind %d", p->refcnt, p->bindcnt); |
| 389 | if (show_stats) { |
| 390 | if (tb[TCA_POLICE_TM]) { |
| 391 | struct tcf_t *tm = RTA_DATA(tb[TCA_POLICE_TM]); |
| 392 | |
| 393 | print_tm(f, tm); |
| 394 | } |
| 395 | } |
| 396 | fprintf(f, "\n"); |
| 397 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Jamal Hadi Salim | 45c6837 | 2016-05-25 06:05:48 -0400 | [diff] [blame] | 402 | int tc_print_police(FILE *f, struct rtattr *arg) |
| 403 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 404 | return print_police(&police_action_util, f, arg); |
osdl.net!shemminger | 2373fde | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 405 | } |