]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/f_matchall.c
man: tc-taprio.8: fix syntax error
[mirror_iproute2.git] / tc / f_matchall.c
CommitLineData
d5cbf3ff
YG
1/*
2 * f_matchall.c Match-all Classifier
3 *
4 * This program is free software; you can distribute 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: Jiri Pirko <jiri@mellanox.com>, Yotam Gigi <yotamg@mellanox.com>
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
d5cbf3ff
YG
16#include <fcntl.h>
17#include <sys/socket.h>
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <string.h>
21#include <linux/if.h>
22
23#include "utils.h"
24#include "tc_util.h"
25
26static void explain(void)
27{
28 fprintf(stderr, "Usage: ... matchall [skip_sw | skip_hw]\n");
29 fprintf(stderr, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
30 fprintf(stderr, "\n");
31 fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
32 fprintf(stderr, " FILTERID := X:Y:Z\n");
33 fprintf(stderr, " ACTION_SPEC := ... look at individual actions\n");
34 fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
35}
36
37static int matchall_parse_opt(struct filter_util *qu, char *handle,
38 int argc, char **argv, struct nlmsghdr *n)
39{
40 struct tcmsg *t = NLMSG_DATA(n);
41 struct rtattr *tail;
42 __u32 flags = 0;
43 long h = 0;
44
45 if (handle) {
46 h = strtol(handle, NULL, 0);
47 if (h == LONG_MIN || h == LONG_MAX) {
48 fprintf(stderr, "Illegal handle \"%s\", must be numeric.\n",
49 handle);
50 return -1;
51 }
52 }
53 t->tcm_handle = h;
54
55 if (argc == 0)
56 return 0;
57
58 tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
59 addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
60
61 while (argc > 0) {
62 if (matches(*argv, "classid") == 0 ||
63 strcmp(*argv, "flowid") == 0) {
64 unsigned int handle;
65
66 NEXT_ARG();
67 if (get_tc_classid(&handle, *argv)) {
68 fprintf(stderr, "Illegal \"classid\"\n");
69 return -1;
70 }
71 addattr_l(n, MAX_MSG, TCA_MATCHALL_CLASSID, &handle, 4);
72 } else if (matches(*argv, "action") == 0) {
73 NEXT_ARG();
74 if (parse_action(&argc, &argv, TCA_MATCHALL_ACT, n)) {
75 fprintf(stderr, "Illegal \"action\"\n");
76 return -1;
77 }
78 continue;
79
80 } else if (strcmp(*argv, "skip_hw") == 0) {
81 NEXT_ARG();
82 flags |= TCA_CLS_FLAGS_SKIP_HW;
83 continue;
84 } else if (strcmp(*argv, "skip_sw") == 0) {
85 NEXT_ARG();
86 flags |= TCA_CLS_FLAGS_SKIP_SW;
87 continue;
88 } else if (strcmp(*argv, "help") == 0) {
89 explain();
90 return -1;
91 } else {
92 fprintf(stderr, "What is \"%s\"?\n", *argv);
93 explain();
94 return -1;
95 }
96 argc--; argv++;
97 }
98
99 if (flags) {
100 if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW |
101 TCA_CLS_FLAGS_SKIP_SW))) {
102 fprintf(stderr,
103 "skip_hw and skip_sw are mutually exclusive\n");
104 return -1;
105 }
106 addattr_l(n, MAX_MSG, TCA_MATCHALL_FLAGS, &flags, 4);
107 }
108
109 tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
110 return 0;
111}
112
113static int matchall_print_opt(struct filter_util *qu, FILE *f,
114 struct rtattr *opt, __u32 handle)
115{
116 struct rtattr *tb[TCA_MATCHALL_MAX+1];
117
118 if (opt == NULL)
119 return 0;
120
121 parse_rtattr_nested(tb, TCA_MATCHALL_MAX, opt);
122
123 if (handle)
619ca351 124 print_uint(PRINT_ANY, "handle", "handle 0x%x ", handle);
d5cbf3ff
YG
125
126 if (tb[TCA_MATCHALL_CLASSID]) {
127 SPRINT_BUF(b1);
619ca351 128 print_string(PRINT_ANY, "flowid", "flowid %s ",
d5cbf3ff
YG
129 sprint_tc_classid(rta_getattr_u32(tb[TCA_MATCHALL_CLASSID]), b1));
130 }
131
afdc1fed
OG
132 if (tb[TCA_MATCHALL_FLAGS]) {
133 __u32 flags = rta_getattr_u32(tb[TCA_MATCHALL_FLAGS]);
134
135 if (flags & TCA_CLS_FLAGS_SKIP_HW)
619ca351 136 print_bool(PRINT_ANY, "skip_hw", "\n skip_hw", true);
afdc1fed 137 if (flags & TCA_CLS_FLAGS_SKIP_SW)
619ca351 138 print_bool(PRINT_ANY, "skip_sw", "\n skip_sw", true);
e57285b8
OG
139
140 if (flags & TCA_CLS_FLAGS_IN_HW)
619ca351 141 print_bool(PRINT_ANY, "in_hw", "\n in_hw", true);
e57285b8 142 else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
619ca351 143 print_bool(PRINT_ANY, "not_in_hw", "\n not_in_hw", true);
afdc1fed
OG
144 }
145
d5cbf3ff 146 if (tb[TCA_MATCHALL_ACT])
9e713525 147 tc_print_action(f, tb[TCA_MATCHALL_ACT], 0);
d5cbf3ff
YG
148
149 return 0;
150}
151
152struct filter_util matchall_filter_util = {
153 .id = "matchall",
154 .parse_fopt = matchall_parse_opt,
155 .print_fopt = matchall_print_opt,
156};