]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_fifo.c
tc: B.W limits can now be specified in %.
[mirror_iproute2.git] / tc / q_fifo.c
1 /*
2 * q_fifo.c FIFO.
3 *
4 * This program is free software; you can redistribute 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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
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
25 static void explain(void)
26 {
27 fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n");
28 }
29
30 static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
31 {
32 int ok = 0;
33 struct tc_fifo_qopt opt = {};
34
35 while (argc > 0) {
36 if (strcmp(*argv, "limit") == 0) {
37 NEXT_ARG();
38 if (get_size(&opt.limit, *argv)) {
39 fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv);
40 return -1;
41 }
42 ok++;
43 } else if (strcmp(*argv, "help") == 0) {
44 explain();
45 return -1;
46 } else {
47 fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
48 explain();
49 return -1;
50 }
51 argc--; argv++;
52 }
53
54 if (ok)
55 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
56 return 0;
57 }
58
59 static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
60 {
61 struct tc_fifo_qopt *qopt;
62
63 if (opt == NULL)
64 return 0;
65
66 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
67 return -1;
68 qopt = RTA_DATA(opt);
69 if (strcmp(qu->id, "bfifo") == 0) {
70 SPRINT_BUF(b1);
71 fprintf(f, "limit %s", sprint_size(qopt->limit, b1));
72 } else
73 fprintf(f, "limit %up", qopt->limit);
74 return 0;
75 }
76
77
78 struct qdisc_util bfifo_qdisc_util = {
79 .id = "bfifo",
80 .parse_qopt = fifo_parse_opt,
81 .print_qopt = fifo_print_opt,
82 };
83
84 struct qdisc_util pfifo_qdisc_util = {
85 .id = "pfifo",
86 .parse_qopt = fifo_parse_opt,
87 .print_qopt = fifo_print_opt,
88 };
89
90 struct 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
96 extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
97 struct qdisc_util pfifo_fast_qdisc_util = {
98 .id = "pfifo_fast",
99 .print_qopt = prio_print_opt,
100 };