]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/f_tcindex.c
ip: report IFLA_GSO_MAX_SIZE and IFLA_GSO_MAX_SEGS
[mirror_iproute2.git] / tc / f_tcindex.c
CommitLineData
aba5acdf
SH
1/*
2 * f_tcindex.c Traffic control index filter
3 *
4 * Written 1998,1999 by Werner Almesberger
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <syslog.h>
11#include <fcntl.h>
12#include <string.h>
13#include <netinet/in.h>
14
15#include "utils.h"
16#include "tc_util.h"
17
18static void explain(void)
19{
32a121cb
SH
20 fprintf(stderr," Usage: ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ]\n");
21 fprintf(stderr, " [ pass_on | fall_through ]\n");
22 fprintf(stderr," [ classid CLASSID ] [ action ACTION_SPEC ]\n");
aba5acdf
SH
23}
24
aba5acdf
SH
25static int tcindex_parse_opt(struct filter_util *qu, char *handle, int argc,
26 char **argv, struct nlmsghdr *n)
27{
28 struct tcmsg *t = NLMSG_DATA(n);
29 struct rtattr *tail;
30 char *end;
31
32 if (handle) {
32a121cb 33 t->tcm_handle = strtoul(handle, &end, 0);
aba5acdf
SH
34 if (*end) {
35 fprintf(stderr, "Illegal filter ID\n");
36 return -1;
37 }
38 }
39 if (!argc) return 0;
3b3ecd31 40 tail = NLMSG_TAIL(n);
32a121cb 41 addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
aba5acdf 42 while (argc) {
32a121cb 43 if (!strcmp(*argv, "hash")) {
aba5acdf
SH
44 int hash;
45
46 NEXT_ARG();
32a121cb 47 hash = strtoul(*argv, &end, 0);
aba5acdf
SH
48 if (*end || !hash || hash > 0x10000) {
49 explain();
50 return -1;
51 }
32a121cb
SH
52 addattr_l(n, 4096, TCA_TCINDEX_HASH, &hash, sizeof(hash));
53 } else if (!strcmp(*argv,"mask")) {
aba5acdf
SH
54 __u16 mask;
55
56 NEXT_ARG();
32a121cb 57 mask = strtoul(*argv, &end, 0);
aba5acdf
SH
58 if (*end) {
59 explain();
60 return -1;
61 }
32a121cb
SH
62 addattr_l(n, 4096, TCA_TCINDEX_MASK, &mask, sizeof(mask));
63 } else if (!strcmp(*argv,"shift")) {
aba5acdf
SH
64 int shift;
65
66 NEXT_ARG();
32a121cb 67 shift = strtoul(*argv, &end, 0);
aba5acdf
SH
68 if (*end) {
69 explain();
70 return -1;
71 }
32a121cb 72 addattr_l(n, 4096, TCA_TCINDEX_SHIFT, &shift,
aba5acdf 73 sizeof(shift));
32a121cb 74 } else if (!strcmp(*argv,"fall_through")) {
aba5acdf
SH
75 int value = 1;
76
32a121cb 77 addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
aba5acdf 78 sizeof(value));
32a121cb 79 } else if (!strcmp(*argv,"pass_on")) {
aba5acdf
SH
80 int value = 0;
81
32a121cb 82 addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
aba5acdf 83 sizeof(value));
32a121cb 84 } else if (!strcmp(*argv,"classid")) {
aba5acdf
SH
85 __u32 handle;
86
87 NEXT_ARG();
32a121cb 88 if (get_tc_classid(&handle, *argv)) {
aba5acdf
SH
89 fprintf(stderr, "Illegal \"classid\"\n");
90 return -1;
91 }
92 addattr_l(n, 4096, TCA_TCINDEX_CLASSID, &handle, 4);
32a121cb 93 } else if (!strcmp(*argv,"police")) {
aba5acdf
SH
94 NEXT_ARG();
95 if (parse_police(&argc, &argv, TCA_TCINDEX_POLICE, n)) {
96 fprintf(stderr, "Illegal \"police\"\n");
97 return -1;
98 }
99 continue;
32a121cb 100 } else if (!strcmp(*argv,"action")) {
08139c2f
JHS
101 NEXT_ARG();
102 if (parse_police(&argc, &argv, TCA_TCINDEX_ACT, n)) {
103 fprintf(stderr, "Illegal \"action\"\n");
104 return -1;
105 }
106 continue;
32a121cb 107 } else {
aba5acdf
SH
108 explain();
109 return -1;
110 }
111 argc--;
112 argv++;
113 }
3b3ecd31 114 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
aba5acdf
SH
115 return 0;
116}
117
118
119static int tcindex_print_opt(struct filter_util *qu, FILE *f,
120 struct rtattr *opt, __u32 handle)
121{
122 struct rtattr *tb[TCA_TCINDEX_MAX+1];
123
3b3ecd31 124 if (opt == NULL)
125 return 0;
aba5acdf 126
3b3ecd31 127 parse_rtattr_nested(tb, TCA_TCINDEX_MAX, opt);
aba5acdf 128
32a121cb 129 if (handle != ~0) fprintf(f, "handle 0x%04x ", handle);
aba5acdf
SH
130 if (tb[TCA_TCINDEX_HASH]) {
131 __u16 hash;
132
133 if (RTA_PAYLOAD(tb[TCA_TCINDEX_HASH]) < sizeof(hash))
134 return -1;
ff24746c 135 hash = rta_getattr_u16(tb[TCA_TCINDEX_HASH]);
32a121cb 136 fprintf(f, "hash %d ", hash);
aba5acdf
SH
137 }
138 if (tb[TCA_TCINDEX_MASK]) {
139 __u16 mask;
140
141 if (RTA_PAYLOAD(tb[TCA_TCINDEX_MASK]) < sizeof(mask))
142 return -1;
ff24746c 143 mask = rta_getattr_u16(tb[TCA_TCINDEX_MASK]);
32a121cb 144 fprintf(f, "mask 0x%04x ", mask);
aba5acdf
SH
145 }
146 if (tb[TCA_TCINDEX_SHIFT]) {
147 int shift;
148
149 if (RTA_PAYLOAD(tb[TCA_TCINDEX_SHIFT]) < sizeof(shift))
150 return -1;
151 shift = *(int *) RTA_DATA(tb[TCA_TCINDEX_SHIFT]);
32a121cb 152 fprintf(f, "shift %d ", shift);
aba5acdf
SH
153 }
154 if (tb[TCA_TCINDEX_FALL_THROUGH]) {
155 int fall_through;
156
157 if (RTA_PAYLOAD(tb[TCA_TCINDEX_FALL_THROUGH]) <
158 sizeof(fall_through))
159 return -1;
160 fall_through = *(int *) RTA_DATA(tb[TCA_TCINDEX_FALL_THROUGH]);
32a121cb 161 fprintf(f, fall_through ? "fall_through " : "pass_on ");
aba5acdf
SH
162 }
163 if (tb[TCA_TCINDEX_CLASSID]) {
164 SPRINT_BUF(b1);
32a121cb 165 fprintf(f, "classid %s ", sprint_tc_classid(*(__u32 *)
aba5acdf
SH
166 RTA_DATA(tb[TCA_TCINDEX_CLASSID]), b1));
167 }
168 if (tb[TCA_TCINDEX_POLICE]) {
169 fprintf(f, "\n");
170 tc_print_police(f, tb[TCA_TCINDEX_POLICE]);
171 }
08139c2f
JHS
172 if (tb[TCA_TCINDEX_ACT]) {
173 fprintf(f, "\n");
174 tc_print_police(f, tb[TCA_TCINDEX_ACT]);
175 }
aba5acdf
SH
176 return 0;
177}
178
6b7dff17
SH
179struct filter_util tcindex_filter_util = {
180 .id = "tcindex",
181 .parse_fopt = tcindex_parse_opt,
182 .print_fopt = tcindex_print_opt,
aba5acdf 183};