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 | { |
| 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)) { |
| 41 | fprintf(stderr, "Illegal \"limit\"\n"); |
| 42 | return -1; |
| 43 | } |
| 44 | ok++; |
| 45 | } else if (strcmp(*argv, "help") == 0) { |
| 46 | explain(); |
| 47 | return -1; |
| 48 | } else { |
| 49 | fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 50 | 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 | |
| 61 | static 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!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 79 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 80 | struct qdisc_util bfifo_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 81 | .id = "bfifo", |
| 82 | .parse_qopt = fifo_parse_opt, |
| 83 | .print_qopt = fifo_print_opt, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 86 | struct qdisc_util pfifo_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 87 | .id = "pfifo", |
| 88 | .parse_qopt = fifo_parse_opt, |
| 89 | .print_qopt = fifo_print_opt, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 90 | }; |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 91 | |
Hagen Paul Pfeifer | f703129 | 2010-01-24 12:31:05 +0000 | [diff] [blame^] | 92 | struct 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!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 98 | 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] | 99 | struct qdisc_util pfifo_fast_qdisc_util = { |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 100 | .id = "pfifo_fast", |
| 101 | .print_qopt = prio_print_opt, |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 102 | }; |