| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* q_etf.c Earliest TxTime First (ETF). |
| 4 |
* |
| 5 |
* Authors: Vinicius Costa Gomes <[email protected]> |
| 6 |
* Jesus Sanchez-Palencia <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <unistd.h> |
| 12 |
#include <fcntl.h> |
| 13 |
#include <sys/ioctl.h> |
| 14 |
#include <sys/socket.h> |
| 15 |
#include <netinet/in.h> |
| 16 |
#include <arpa/inet.h> |
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
#include "utils.h" |
| 20 |
#include "tc_util.h" |
| 21 |
|
| 22 |
static void explain(void) |
| 23 |
{ |
| 24 |
fprintf(stderr, |
| 25 |
"Usage: ... etf delta NANOS clockid CLOCKID [offload] [deadline_mode]\n" |
| 26 |
"CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n"); |
| 27 |
} |
| 28 |
|
| 29 |
static void explain1(const char *arg, const char *val) |
| 30 |
{ |
| 31 |
fprintf(stderr, "etf: illegal value for \"%s\": \"%s\"\n", arg, val); |
| 32 |
} |
| 33 |
|
| 34 |
static void explain_clockid(const char *val) |
| 35 |
{ |
| 36 |
fprintf(stderr, |
| 37 |
"etf: illegal value for \"clockid\": \"%s\".\n" |
| 38 |
"It must be a valid SYS-V id (i.e. CLOCK_TAI)\n", |
| 39 |
val); |
| 40 |
} |
| 41 |
|
| 42 |
static int etf_parse_opt(const struct qdisc_util *qu, int argc, |
| 43 |
char **argv, struct nlmsghdr *n, const char *dev) |
| 44 |
{ |
| 45 |
struct tc_etf_qopt opt = { |
| 46 |
.clockid = CLOCKID_INVALID, |
| 47 |
}; |
| 48 |
struct rtattr *tail; |
| 49 |
|
| 50 |
while (argc > 0) { |
| 51 |
if (matches(*argv, "offload") == 0) { |
| 52 |
if (opt.flags & TC_ETF_OFFLOAD_ON) { |
| 53 |
fprintf(stderr, "etf: duplicate \"offload\" specification\n"); |
| 54 |
return -1; |
| 55 |
} |
| 56 |
|
| 57 |
opt.flags |= TC_ETF_OFFLOAD_ON; |
| 58 |
} else if (matches(*argv, "deadline_mode") == 0) { |
| 59 |
if (opt.flags & TC_ETF_DEADLINE_MODE_ON) { |
| 60 |
fprintf(stderr, "etf: duplicate \"deadline_mode\" specification\n"); |
| 61 |
return -1; |
| 62 |
} |
| 63 |
|
| 64 |
opt.flags |= TC_ETF_DEADLINE_MODE_ON; |
| 65 |
} else if (matches(*argv, "delta") == 0) { |
| 66 |
NEXT_ARG(); |
| 67 |
if (opt.delta) { |
| 68 |
fprintf(stderr, "etf: duplicate \"delta\" specification\n"); |
| 69 |
return -1; |
| 70 |
} |
| 71 |
if (get_s32(&opt.delta, *argv, 0)) { |
| 72 |
explain1("delta", *argv); |
| 73 |
return -1; |
| 74 |
} |
| 75 |
} else if (matches(*argv, "clockid") == 0) { |
| 76 |
NEXT_ARG(); |
| 77 |
if (opt.clockid != CLOCKID_INVALID) { |
| 78 |
fprintf(stderr, "etf: duplicate \"clockid\" specification\n"); |
| 79 |
return -1; |
| 80 |
} |
| 81 |
if (get_clockid(&opt.clockid, *argv)) { |
| 82 |
explain_clockid(*argv); |
| 83 |
return -1; |
| 84 |
} |
| 85 |
} else if (strcmp(*argv, "skip_sock_check") == 0) { |
| 86 |
if (opt.flags & TC_ETF_SKIP_SOCK_CHECK) { |
| 87 |
fprintf(stderr, "etf: duplicate \"skip_sock_check\" specification\n"); |
| 88 |
return -1; |
| 89 |
} |
| 90 |
|
| 91 |
opt.flags |= TC_ETF_SKIP_SOCK_CHECK; |
| 92 |
} else if (strcmp(*argv, "help") == 0) { |
| 93 |
explain(); |
| 94 |
return -1; |
| 95 |
} else { |
| 96 |
fprintf(stderr, "etf: unknown parameter \"%s\"\n", *argv); |
| 97 |
explain(); |
| 98 |
return -1; |
| 99 |
} |
| 100 |
argc--; argv++; |
| 101 |
} |
| 102 |
|
| 103 |
tail = NLMSG_TAIL(n); |
| 104 |
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); |
| 105 |
addattr_l(n, 2024, TCA_ETF_PARMS, &opt, sizeof(opt)); |
| 106 |
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
static int etf_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 111 |
{ |
| 112 |
struct rtattr *tb[TCA_ETF_MAX+1]; |
| 113 |
struct tc_etf_qopt *qopt; |
| 114 |
|
| 115 |
if (opt == NULL) |
| 116 |
return 0; |
| 117 |
|
| 118 |
parse_rtattr_nested(tb, TCA_ETF_MAX, opt); |
| 119 |
|
| 120 |
if (tb[TCA_ETF_PARMS] == NULL) |
| 121 |
return -1; |
| 122 |
|
| 123 |
qopt = RTA_DATA(tb[TCA_ETF_PARMS]); |
| 124 |
if (RTA_PAYLOAD(tb[TCA_ETF_PARMS]) < sizeof(*qopt)) |
| 125 |
return -1; |
| 126 |
|
| 127 |
print_string(PRINT_ANY, "clockid", "clockid %s ", |
| 128 |
get_clock_name(qopt->clockid)); |
| 129 |
|
| 130 |
print_uint(PRINT_ANY, "delta", "delta %d ", qopt->delta); |
| 131 |
print_string(PRINT_ANY, "offload", "offload %s ", |
| 132 |
(qopt->flags & TC_ETF_OFFLOAD_ON) ? "on" : "off"); |
| 133 |
print_string(PRINT_ANY, "deadline_mode", "deadline_mode %s ", |
| 134 |
(qopt->flags & TC_ETF_DEADLINE_MODE_ON) ? "on" : "off"); |
| 135 |
print_string(PRINT_ANY, "skip_sock_check", "skip_sock_check %s", |
| 136 |
(qopt->flags & TC_ETF_SKIP_SOCK_CHECK) ? "on" : "off"); |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |
| 140 |
|
| 141 |
struct qdisc_util etf_qdisc_util = { |
| 142 |
.id = "etf", |
| 143 |
.parse_qopt = etf_parse_opt, |
| 144 |
.print_qopt = etf_print_opt, |
| 145 |
}; |