1
2
3
4
5
6
7
8
9
10
11
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <fcntl.h>
17#include <sys/socket.h>
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <string.h>
21
22#include "utils.h"
23#include "tc_util.h"
24
25static void explain(void)
26{
27 fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n");
28}
29
30static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv,
31 struct nlmsghdr *n, const char *dev)
32{
33 int ok = 0;
34 struct tc_fifo_qopt opt = {};
35
36 while (argc > 0) {
37 if (strcmp(*argv, "limit") == 0) {
38 NEXT_ARG();
39 if (get_size(&opt.limit, *argv)) {
40 fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv);
41 return -1;
42 }
43 ok++;
44 } else if (strcmp(*argv, "help") == 0) {
45 explain();
46 return -1;
47 } else {
48 fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
49 explain();
50 return -1;
51 }
52 argc--; argv++;
53 }
54
55 if (ok)
56 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
57 return 0;
58}
59
60static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
61{
62 struct tc_fifo_qopt *qopt;
63
64 if (opt == NULL)
65 return 0;
66
67 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
68 return -1;
69 qopt = RTA_DATA(opt);
70 if (strcmp(qu->id, "bfifo") == 0)
71 print_size(PRINT_ANY, "limit", "limit %s", qopt->limit);
72 else
73 print_uint(PRINT_ANY, "limit", "limit %up", qopt->limit);
74 return 0;
75}
76
77
78struct qdisc_util bfifo_qdisc_util = {
79 .id = "bfifo",
80 .parse_qopt = fifo_parse_opt,
81 .print_qopt = fifo_print_opt,
82};
83
84struct qdisc_util pfifo_qdisc_util = {
85 .id = "pfifo",
86 .parse_qopt = fifo_parse_opt,
87 .print_qopt = fifo_print_opt,
88};
89
90struct qdisc_util pfifo_head_drop_qdisc_util = {
91 .id = "pfifo_head_drop",
92 .parse_qopt = fifo_parse_opt,
93 .print_qopt = fifo_print_opt,
94};
95
96struct qdisc_util pfifo_fast_qdisc_util = {
97 .id = "pfifo_fast",
98 .print_qopt = prio_print_opt,
99};
100