| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* tc_stab.c "tc qdisc ... stab *". |
| 4 |
* |
| 5 |
* Authors: Jussi Kivilinna, <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <unistd.h> |
| 11 |
#include <fcntl.h> |
| 12 |
#include <math.h> |
| 13 |
#include <sys/socket.h> |
| 14 |
#include <sys/param.h> |
| 15 |
#include <netinet/in.h> |
| 16 |
#include <arpa/inet.h> |
| 17 |
#include <string.h> |
| 18 |
#include <malloc.h> |
| 19 |
|
| 20 |
#include "utils.h" |
| 21 |
#include "tc_util.h" |
| 22 |
#include "tc_core.h" |
| 23 |
#include "tc_common.h" |
| 24 |
|
| 25 |
static void stab_help(void) |
| 26 |
{ |
| 27 |
fprintf(stderr, |
| 28 |
"Usage: ... stab [ mtu BYTES ] [ tsize SLOTS ] [ mpu BYTES ]\n" |
| 29 |
" [ overhead BYTES ] [ linklayer TYPE ] ...\n" |
| 30 |
" mtu : max packet size we create rate map for {2047}\n" |
| 31 |
" tsize : how many slots should size table have {512}\n" |
| 32 |
" mpu : minimum packet size used in rate computations\n" |
| 33 |
" overhead : per-packet size overhead used in rate computations\n" |
| 34 |
" linklayer : adapting to a linklayer e.g. atm\n" |
| 35 |
"Example: ... stab overhead 20 linklayer atm\n"); |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
int check_size_table_opts(struct tc_sizespec *s) |
| 40 |
{ |
| 41 |
return s->linklayer >= LINKLAYER_ETHERNET || s->mpu != 0 || |
| 42 |
s->overhead != 0; |
| 43 |
} |
| 44 |
|
| 45 |
int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp) |
| 46 |
{ |
| 47 |
char **argv = *argvp; |
| 48 |
int argc = *argcp; |
| 49 |
struct tc_sizespec s = {}; |
| 50 |
|
| 51 |
NEXT_ARG(); |
| 52 |
if (matches(*argv, "help") == 0) { |
| 53 |
stab_help(); |
| 54 |
return -1; |
| 55 |
} |
| 56 |
while (argc > 0) { |
| 57 |
if (matches(*argv, "mtu") == 0) { |
| 58 |
NEXT_ARG(); |
| 59 |
if (s.mtu) |
| 60 |
duparg("mtu", *argv); |
| 61 |
if (get_u32(&s.mtu, *argv, 10)) |
| 62 |
invarg("mtu", "invalid mtu"); |
| 63 |
} else if (matches(*argv, "mpu") == 0) { |
| 64 |
NEXT_ARG(); |
| 65 |
if (s.mpu) |
| 66 |
duparg("mpu", *argv); |
| 67 |
if (get_u32(&s.mpu, *argv, 10)) |
| 68 |
invarg("mpu", "invalid mpu"); |
| 69 |
} else if (matches(*argv, "overhead") == 0) { |
| 70 |
NEXT_ARG(); |
| 71 |
if (s.overhead) |
| 72 |
duparg("overhead", *argv); |
| 73 |
if (get_integer(&s.overhead, *argv, 10)) |
| 74 |
invarg("overhead", "invalid overhead"); |
| 75 |
} else if (matches(*argv, "tsize") == 0) { |
| 76 |
NEXT_ARG(); |
| 77 |
if (s.tsize) |
| 78 |
duparg("tsize", *argv); |
| 79 |
if (get_u32(&s.tsize, *argv, 10)) |
| 80 |
invarg("tsize", "invalid table size"); |
| 81 |
} else if (matches(*argv, "linklayer") == 0) { |
| 82 |
NEXT_ARG(); |
| 83 |
if (s.linklayer != LINKLAYER_UNSPEC) |
| 84 |
duparg("linklayer", *argv); |
| 85 |
if (get_linklayer(&s.linklayer, *argv)) |
| 86 |
invarg("linklayer", "invalid linklayer"); |
| 87 |
} else |
| 88 |
break; |
| 89 |
argc--; argv++; |
| 90 |
} |
| 91 |
|
| 92 |
if (!check_size_table_opts(&s)) |
| 93 |
return -1; |
| 94 |
|
| 95 |
*sp = s; |
| 96 |
*argvp = argv; |
| 97 |
*argcp = argc; |
| 98 |
return 0; |
| 99 |
} |
| 100 |
|
| 101 |
void print_size_table(struct rtattr *rta) |
| 102 |
{ |
| 103 |
struct rtattr *tb[TCA_STAB_MAX + 1]; |
| 104 |
|
| 105 |
SPRINT_BUF(b1); |
| 106 |
|
| 107 |
parse_rtattr_nested(tb, TCA_STAB_MAX, rta); |
| 108 |
|
| 109 |
if (tb[TCA_STAB_BASE]) { |
| 110 |
struct tc_sizespec s = {0}; |
| 111 |
|
| 112 |
memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]), |
| 113 |
MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s))); |
| 114 |
|
| 115 |
open_json_object("stab"); |
| 116 |
print_string(PRINT_FP, NULL, " ", NULL); |
| 117 |
|
| 118 |
if (s.linklayer) |
| 119 |
print_string(PRINT_ANY, "linklayer", |
| 120 |
"linklayer %s ", |
| 121 |
sprint_linklayer(s.linklayer, b1)); |
| 122 |
if (s.overhead) |
| 123 |
print_int(PRINT_ANY, "overhead", |
| 124 |
"overhead %d ", s.overhead); |
| 125 |
if (s.mpu) |
| 126 |
print_uint(PRINT_ANY, "mpu", |
| 127 |
"mpu %u ", s.mpu); |
| 128 |
if (s.mtu) |
| 129 |
print_uint(PRINT_ANY, "mtu", |
| 130 |
"mtu %u ", s.mtu); |
| 131 |
if (s.tsize) |
| 132 |
print_uint(PRINT_ANY, "tsize", |
| 133 |
"tsize %u ", s.tsize); |
| 134 |
close_json_object(); |
| 135 |
} |
| 136 |
} |