osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 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 <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 | |
| 26 | static void explain(void) |
| 27 | { |
Hagen Paul Pfeifer | f703129 | 2010-01-24 12:31:05 +0000 | [diff] [blame] | 28 | fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n"); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 29 | } |
| 30 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 31 | static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 32 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 33 | int ok = 0; |
Phil Sutter | d17b136 | 2016-07-18 16:48:42 +0200 | [diff] [blame] | 34 | struct tc_fifo_qopt opt = {}; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 35 | |
| 36 | while (argc > 0) { |
| 37 | if (strcmp(*argv, "limit") == 0) { |
| 38 | NEXT_ARG(); |
| 39 | if (get_size(&opt.limit, *argv)) { |
Kees van Reeuwijk | 3bed7bb | 2013-02-19 07:46:04 +0000 | [diff] [blame] | 40 | fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 41 | return -1; |
| 42 | } |
| 43 | ok++; |
| 44 | } else if (strcmp(*argv, "help") == 0) { |
| 45 | explain(); |
| 46 | return -1; |
| 47 | } else { |
Kees van Reeuwijk | 3bed7bb | 2013-02-19 07:46:04 +0000 | [diff] [blame] | 48 | fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 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 | |
| 60 | static 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); |
| 72 | fprintf(f, "limit %s", sprint_size(qopt->limit, b1)); |
| 73 | } else |
| 74 | fprintf(f, "limit %up", qopt->limit); |
| 75 | return 0; |
| 76 | } |
| 77 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 78 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 79 | struct qdisc_util bfifo_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 80 | .id = "bfifo", |
| 81 | .parse_qopt = fifo_parse_opt, |
| 82 | .print_qopt = fifo_print_opt, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 85 | struct qdisc_util pfifo_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 86 | .id = "pfifo", |
| 87 | .parse_qopt = fifo_parse_opt, |
| 88 | .print_qopt = fifo_print_opt, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 89 | }; |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 90 | |
Hagen Paul Pfeifer | f703129 | 2010-01-24 12:31:05 +0000 | [diff] [blame] | 91 | struct qdisc_util pfifo_head_drop_qdisc_util = { |
| 92 | .id = "pfifo_head_drop", |
| 93 | .parse_qopt = fifo_parse_opt, |
| 94 | .print_qopt = fifo_print_opt, |
| 95 | }; |
| 96 | |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 97 | extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 98 | struct qdisc_util pfifo_fast_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 99 | .id = "pfifo_fast", |
| 100 | .print_qopt = prio_print_opt, |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 101 | }; |