]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/f_basic.c
man: tc-taprio.8: fix syntax error
[mirror_iproute2.git] / tc / f_basic.c
CommitLineData
c428e91b
SH
1/*
2 * f_basic.c Basic Classifier
3 *
84d66882 4 * This program is free software; you can distribute it and/or
c428e91b
SH
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: Thomas Graf <tgraf@suug.ch>
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
c428e91b
SH
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#include "m_ematch.h"
26
27static void explain(void)
28{
32a121cb 29 fprintf(stderr, "Usage: ... basic [ match EMATCH_TREE ]\n");
c428e91b
SH
30 fprintf(stderr, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
31 fprintf(stderr, "\n");
32 fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
33 fprintf(stderr, " FILTERID := X:Y:Z\n");
863ecb04 34 fprintf(stderr, " ACTION_SPEC := ... look at individual actions\n");
e9acc242 35 fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
c428e91b
SH
36}
37
38static int basic_parse_opt(struct filter_util *qu, char *handle,
39 int argc, char **argv, struct nlmsghdr *n)
40{
41 struct tcmsg *t = NLMSG_DATA(n);
42 struct rtattr *tail;
43 long h = 0;
44
c428e91b
SH
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 }
c428e91b
SH
53 t->tcm_handle = h;
54
285e7768
WC
55 if (argc == 0)
56 return 0;
57
32a121cb 58 tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
c428e91b
SH
59 addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
60
61 while (argc > 0) {
62 if (matches(*argv, "match") == 0) {
63 NEXT_ARG();
64 if (parse_ematch(&argc, &argv, TCA_BASIC_EMATCHES, n)) {
65 fprintf(stderr, "Illegal \"ematch\"\n");
66 return -1;
67 }
68 continue;
69 } else if (matches(*argv, "classid") == 0 ||
70 strcmp(*argv, "flowid") == 0) {
32a121cb
SH
71 unsigned int handle;
72
c428e91b
SH
73 NEXT_ARG();
74 if (get_tc_classid(&handle, *argv)) {
75 fprintf(stderr, "Illegal \"classid\"\n");
76 return -1;
77 }
78 addattr_l(n, MAX_MSG, TCA_BASIC_CLASSID, &handle, 4);
79 } else if (matches(*argv, "action") == 0) {
80 NEXT_ARG();
81 if (parse_action(&argc, &argv, TCA_BASIC_ACT, n)) {
82 fprintf(stderr, "Illegal \"action\"\n");
83 return -1;
84 }
85 continue;
86
87 } else if (matches(*argv, "police") == 0) {
88 NEXT_ARG();
89 if (parse_police(&argc, &argv, TCA_BASIC_POLICE, n)) {
90 fprintf(stderr, "Illegal \"police\"\n");
91 return -1;
92 }
93 continue;
94 } else if (strcmp(*argv, "help") == 0) {
95 explain();
96 return -1;
97 } else {
98 fprintf(stderr, "What is \"%s\"?\n", *argv);
99 explain();
100 return -1;
101 }
102 argc--; argv++;
103 }
104
32a121cb 105 tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
c428e91b
SH
106 return 0;
107}
108
109static int basic_print_opt(struct filter_util *qu, FILE *f,
110 struct rtattr *opt, __u32 handle)
111{
112 struct rtattr *tb[TCA_BASIC_MAX+1];
113
114 if (opt == NULL)
115 return 0;
116
117 parse_rtattr_nested(tb, TCA_BASIC_MAX, opt);
118
119 if (handle)
120 fprintf(f, "handle 0x%x ", handle);
121
122 if (tb[TCA_BASIC_CLASSID]) {
123 SPRINT_BUF(b1);
124 fprintf(f, "flowid %s ",
ff24746c 125 sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1));
c428e91b
SH
126 }
127
128 if (tb[TCA_BASIC_EMATCHES])
129 print_ematch(f, tb[TCA_BASIC_EMATCHES]);
130
131 if (tb[TCA_BASIC_POLICE]) {
132 fprintf(f, "\n");
133 tc_print_police(f, tb[TCA_BASIC_POLICE]);
134 }
135
136 if (tb[TCA_BASIC_ACT]) {
9e713525 137 tc_print_action(f, tb[TCA_BASIC_ACT], 0);
c428e91b
SH
138 }
139
140 return 0;
141}
142
143struct filter_util basic_filter_util = {
144 .id = "basic",
145 .parse_fopt = basic_parse_opt,
146 .print_fopt = basic_print_opt,
147};