]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_fifo.c
Merge branch 'tc-ets-qdisc' into next
[mirror_iproute2.git] / tc / q_fifo.c
CommitLineData
aba5acdf
SH
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>
aba5acdf
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
22#include "utils.h"
23#include "tc_util.h"
24
25static void explain(void)
26{
f703129d 27 fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n");
aba5acdf
SH
28}
29
859af0a5
SH
30static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv,
31 struct nlmsghdr *n, const char *dev)
aba5acdf 32{
32a121cb 33 int ok = 0;
d17b136f 34 struct tc_fifo_qopt opt = {};
aba5acdf
SH
35
36 while (argc > 0) {
37 if (strcmp(*argv, "limit") == 0) {
38 NEXT_ARG();
39 if (get_size(&opt.limit, *argv)) {
3bed7bb7 40 fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv);
aba5acdf
SH
41 return -1;
42 }
43 ok++;
44 } else if (strcmp(*argv, "help") == 0) {
45 explain();
46 return -1;
47 } else {
3bed7bb7 48 fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
aba5acdf
SH
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 SPRINT_BUF(b1);
650a10e0
JK
72 print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
73 print_string(PRINT_FP, NULL, "limit %s",
74 sprint_size(qopt->limit, b1));
75 } else {
76 print_uint(PRINT_ANY, "limit", "limit %up", qopt->limit);
77 }
aba5acdf
SH
78 return 0;
79}
80
aba5acdf 81
95812b56 82struct qdisc_util bfifo_qdisc_util = {
f2f99e2e
SH
83 .id = "bfifo",
84 .parse_qopt = fifo_parse_opt,
85 .print_qopt = fifo_print_opt,
aba5acdf
SH
86};
87
95812b56 88struct qdisc_util pfifo_qdisc_util = {
f2f99e2e
SH
89 .id = "pfifo",
90 .parse_qopt = fifo_parse_opt,
91 .print_qopt = fifo_print_opt,
aba5acdf 92};
78d55b6e 93
f703129d
HPP
94struct qdisc_util pfifo_head_drop_qdisc_util = {
95 .id = "pfifo_head_drop",
96 .parse_qopt = fifo_parse_opt,
97 .print_qopt = fifo_print_opt,
98};
99
95812b56 100struct qdisc_util pfifo_fast_qdisc_util = {
f2f99e2e
SH
101 .id = "pfifo_fast",
102 .print_qopt = prio_print_opt,
78d55b6e 103};