blob: f7fc88b38818faae6329eea360e8ba34ebcd906b [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
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 <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_util.h"
25
26static void explain(void)
27{
Hagen Paul Pfeiferf7031292010-01-24 12:31:05 +000028 fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n");
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000029}
30
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000031static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
32{
Stephen Hemminger32a121c2016-03-21 11:48:36 -070033 int ok = 0;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000034 struct tc_fifo_qopt opt;
Stephen Hemminger32a121c2016-03-21 11:48:36 -070035
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000036 memset(&opt, 0, sizeof(opt));
37
38 while (argc > 0) {
39 if (strcmp(*argv, "limit") == 0) {
40 NEXT_ARG();
41 if (get_size(&opt.limit, *argv)) {
Kees van Reeuwijk3bed7bb2013-02-19 07:46:04 +000042 fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000043 return -1;
44 }
45 ok++;
46 } else if (strcmp(*argv, "help") == 0) {
47 explain();
48 return -1;
49 } else {
Kees van Reeuwijk3bed7bb2013-02-19 07:46:04 +000050 fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000051 explain();
52 return -1;
53 }
54 argc--; argv++;
55 }
56
57 if (ok)
58 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
59 return 0;
60}
61
62static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
63{
64 struct tc_fifo_qopt *qopt;
65
66 if (opt == NULL)
67 return 0;
68
69 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
70 return -1;
71 qopt = RTA_DATA(opt);
72 if (strcmp(qu->id, "bfifo") == 0) {
73 SPRINT_BUF(b1);
74 fprintf(f, "limit %s", sprint_size(qopt->limit, b1));
75 } else
76 fprintf(f, "limit %up", qopt->limit);
77 return 0;
78}
79
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000080
net[shemminger]!kaber95812b52004-09-28 18:35:49 +000081struct qdisc_util bfifo_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +000082 .id = "bfifo",
83 .parse_qopt = fifo_parse_opt,
84 .print_qopt = fifo_print_opt,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000085};
86
net[shemminger]!kaber95812b52004-09-28 18:35:49 +000087struct qdisc_util pfifo_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +000088 .id = "pfifo",
89 .parse_qopt = fifo_parse_opt,
90 .print_qopt = fifo_print_opt,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000091};
osdl.org!shemminger78d55b62004-06-02 20:22:08 +000092
Hagen Paul Pfeiferf7031292010-01-24 12:31:05 +000093struct qdisc_util pfifo_head_drop_qdisc_util = {
94 .id = "pfifo_head_drop",
95 .parse_qopt = fifo_parse_opt,
96 .print_qopt = fifo_print_opt,
97};
98
osdl.org!shemminger78d55b62004-06-02 20:22:08 +000099extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
net[shemminger]!kaber95812b52004-09-28 18:35:49 +0000100struct qdisc_util pfifo_fast_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +0000101 .id = "pfifo_fast",
102 .print_qopt = prio_print_opt,
osdl.org!shemminger78d55b62004-06-02 20:22:08 +0000103};