Debian Codegraph @

tc/q_skbprio.c

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * q_skbprio.c SKB PRIORITY QUEUE.
4 *
5 * Authors: Nishanth Devarajan, <[email protected]>
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <syslog.h>
12 #include <fcntl.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
16 #include <string.h>
17
18 #include "utils.h"
19 #include "tc_util.h"
20
21 static void explain(void)
22 {
23 fprintf(stderr, "Usage: ... <skbprio> [ limit NUMBER ]\n");
24 }
25
26 static int skbprio_parse_opt(const struct qdisc_util *qu, int argc, char **argv,
27 struct nlmsghdr *n, const char *dev)
28 {
29 int ok = 0;
30 struct tc_skbprio_qopt opt = {};
31
32 while (argc > 0) {
33 if (strcmp(*argv, "limit") == 0) {
34 NEXT_ARG();
35 if (get_size(&opt.limit, *argv)) {
36 fprintf(stderr,
37 "%s: Illegal \"limit\" value:\"%s\"\n",
38 qu->id, *argv);
39 return -1;
40 }
41 ok++;
42 }
43 else if (strcmp(*argv, "help") == 0) {
44 explain();
45 return -1;
46 } else {
47 fprintf(stderr,
48 "%s: unknown parameter \"%s\"\n",
49 qu->id, *argv);
50 explain();
51 return -1;
52 }
53 argc--; argv++;
54 }
55
56 if (ok)
57 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
58 return 0;
59 }
60
61 static int skbprio_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt)
62 {
63 struct tc_skbprio_qopt *qopt;
64
65 if (opt == NULL)
66 return 0;
67
68 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
69 return -1;
70 qopt = RTA_DATA(opt);
71
72 print_uint(PRINT_ANY, "limit", "limit %u ", qopt->limit);
73 return 0;
74 }
75
76 struct qdisc_util skbprio_qdisc_util = {
77 .id = "skbprio",
78 .parse_qopt = skbprio_parse_opt,
79 .print_qopt = skbprio_print_opt,
80 };