]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_etf.c
man: tc-taprio.8: fix syntax error
[mirror_iproute2.git] / tc / q_etf.c
CommitLineData
7da5ef22
VCG
1/*
2 * q_etf.c Earliest TxTime First (ETF).
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: Vinicius Costa Gomes <vinicius.gomes@intel.com>
10 * Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
11 *
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <fcntl.h>
18#include <sys/ioctl.h>
19#include <sys/socket.h>
20#include <netinet/in.h>
21#include <arpa/inet.h>
22#include <string.h>
23
24#include "utils.h"
25#include "tc_util.h"
26
27#define CLOCKID_INVALID (-1)
28static const struct static_clockid {
29 const char *name;
30 clockid_t clockid;
31} clockids_sysv[] = {
32 { "REALTIME", CLOCK_REALTIME },
33 { "TAI", CLOCK_TAI },
34 { "BOOTTIME", CLOCK_BOOTTIME },
35 { "MONOTONIC", CLOCK_MONOTONIC },
36 { NULL }
37};
38
39static void explain(void)
40{
41 fprintf(stderr, "Usage: ... etf delta NANOS clockid CLOCKID [offload] [deadline_mode]\n");
42 fprintf(stderr, "CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
43}
44
45static void explain1(const char *arg, const char *val)
46{
47 fprintf(stderr, "etf: illegal value for \"%s\": \"%s\"\n", arg, val);
48}
49
50static void explain_clockid(const char *val)
51{
52 fprintf(stderr, "etf: illegal value for \"clockid\": \"%s\".\n", val);
53 fprintf(stderr, "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
54}
55
56static int get_clockid(__s32 *val, const char *arg)
57{
58 const struct static_clockid *c;
59
60 /* Drop the CLOCK_ prefix if that is being used. */
61 if (strcasestr(arg, "CLOCK_") != NULL)
62 arg += sizeof("CLOCK_") - 1;
63
64 for (c = clockids_sysv; c->name; c++) {
65 if (strcasecmp(c->name, arg) == 0) {
66 *val = c->clockid;
67
68 return 0;
69 }
70 }
71
72 return -1;
73}
74
75static const char* get_clock_name(clockid_t clockid)
76{
77 const struct static_clockid *c;
78
79 for (c = clockids_sysv; c->name; c++) {
80 if (clockid == c->clockid)
81 return c->name;
82 }
83
84 return "invalid";
85}
86
87static int etf_parse_opt(struct qdisc_util *qu, int argc,
88 char **argv, struct nlmsghdr *n, const char *dev)
89{
90 struct tc_etf_qopt opt = {
91 .clockid = CLOCKID_INVALID,
92 };
93 struct rtattr *tail;
94
95 while (argc > 0) {
96 if (matches(*argv, "offload") == 0) {
97 if (opt.flags & TC_ETF_OFFLOAD_ON) {
98 fprintf(stderr, "etf: duplicate \"offload\" specification\n");
99 return -1;
100 }
101
102 opt.flags |= TC_ETF_OFFLOAD_ON;
103 } else if (matches(*argv, "deadline_mode") == 0) {
104 if (opt.flags & TC_ETF_DEADLINE_MODE_ON) {
105 fprintf(stderr, "etf: duplicate \"deadline_mode\" specification\n");
106 return -1;
107 }
108
109 opt.flags |= TC_ETF_DEADLINE_MODE_ON;
110 } else if (matches(*argv, "delta") == 0) {
111 NEXT_ARG();
112 if (opt.delta) {
113 fprintf(stderr, "etf: duplicate \"delta\" specification\n");
114 return -1;
115 }
116 if (get_s32(&opt.delta, *argv, 0)) {
117 explain1("delta", *argv);
118 return -1;
119 }
120 } else if (matches(*argv, "clockid") == 0) {
121 NEXT_ARG();
122 if (opt.clockid != CLOCKID_INVALID) {
123 fprintf(stderr, "etf: duplicate \"clockid\" specification\n");
124 return -1;
125 }
126 if (get_clockid(&opt.clockid, *argv)) {
127 explain_clockid(*argv);
128 return -1;
129 }
130 } else if (strcmp(*argv, "help") == 0) {
131 explain();
132 return -1;
133 } else {
134 fprintf(stderr, "etf: unknown parameter \"%s\"\n", *argv);
135 explain();
136 return -1;
137 }
138 argc--; argv++;
139 }
140
141 tail = NLMSG_TAIL(n);
142 addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
143 addattr_l(n, 2024, TCA_ETF_PARMS, &opt, sizeof(opt));
144 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
145 return 0;
146}
147
148static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
149{
150 struct rtattr *tb[TCA_ETF_MAX+1];
151 struct tc_etf_qopt *qopt;
152
153 if (opt == NULL)
154 return 0;
155
156 parse_rtattr_nested(tb, TCA_ETF_MAX, opt);
157
158 if (tb[TCA_ETF_PARMS] == NULL)
159 return -1;
160
161 qopt = RTA_DATA(tb[TCA_ETF_PARMS]);
162 if (RTA_PAYLOAD(tb[TCA_ETF_PARMS]) < sizeof(*qopt))
163 return -1;
164
165 print_string(PRINT_ANY, "clockid", "clockid %s ",
166 get_clock_name(qopt->clockid));
167
168 print_uint(PRINT_ANY, "delta", "delta %d ", qopt->delta);
169 print_string(PRINT_ANY, "offload", "offload %s ",
170 (qopt->flags & TC_ETF_OFFLOAD_ON) ? "on" : "off");
171 print_string(PRINT_ANY, "deadline_mode", "deadline_mode %s",
172 (qopt->flags & TC_ETF_DEADLINE_MODE_ON) ? "on" : "off");
173
174 return 0;
175}
176
177struct qdisc_util etf_qdisc_util = {
178 .id = "etf",
179 .parse_qopt = etf_parse_opt,
180 .print_qopt = etf_print_opt,
181};