blob: c9ab123f0b5d50661e71d33f1786b4729abf45a8 [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{
33 int ok=0;
34 struct tc_fifo_qopt opt;
35 memset(&opt, 0, sizeof(opt));
36
37 while (argc > 0) {
38 if (strcmp(*argv, "limit") == 0) {
39 NEXT_ARG();
40 if (get_size(&opt.limit, *argv)) {
Kees van Reeuwijk3bed7bb2013-02-19 07:46:04 +000041 fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000042 return -1;
43 }
44 ok++;
45 } else if (strcmp(*argv, "help") == 0) {
46 explain();
47 return -1;
48 } else {
Kees van Reeuwijk3bed7bb2013-02-19 07:46:04 +000049 fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000050 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
61static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
62{
63 struct tc_fifo_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 if (strcmp(qu->id, "bfifo") == 0) {
72 SPRINT_BUF(b1);
73 fprintf(f, "limit %s", sprint_size(qopt->limit, b1));
74 } else
75 fprintf(f, "limit %up", qopt->limit);
76 return 0;
77}
78
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000079
net[shemminger]!kaber95812b52004-09-28 18:35:49 +000080struct qdisc_util bfifo_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +000081 .id = "bfifo",
82 .parse_qopt = fifo_parse_opt,
83 .print_qopt = fifo_print_opt,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000084};
85
net[shemminger]!kaber95812b52004-09-28 18:35:49 +000086struct qdisc_util pfifo_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +000087 .id = "pfifo",
88 .parse_qopt = fifo_parse_opt,
89 .print_qopt = fifo_print_opt,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000090};
osdl.org!shemminger78d55b62004-06-02 20:22:08 +000091
Hagen Paul Pfeiferf7031292010-01-24 12:31:05 +000092struct qdisc_util pfifo_head_drop_qdisc_util = {
93 .id = "pfifo_head_drop",
94 .parse_qopt = fifo_parse_opt,
95 .print_qopt = fifo_print_opt,
96};
97
osdl.org!shemminger78d55b62004-06-02 20:22:08 +000098extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
net[shemminger]!kaber95812b52004-09-28 18:35:49 +000099struct qdisc_util pfifo_fast_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +0000100 .id = "pfifo_fast",
101 .print_qopt = prio_print_opt,
osdl.org!shemminger78d55b62004-06-02 20:22:08 +0000102};