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 | { |
| 28 | fprintf(stderr, "Usage: ... [p|b]fifo [ limit NUMBER ]\n"); |
| 29 | } |
| 30 | |
| 31 | #define usage() return(-1) |
| 32 | |
| 33 | static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 34 | { |
| 35 | int ok=0; |
| 36 | struct tc_fifo_qopt opt; |
| 37 | memset(&opt, 0, sizeof(opt)); |
| 38 | |
| 39 | while (argc > 0) { |
| 40 | if (strcmp(*argv, "limit") == 0) { |
| 41 | NEXT_ARG(); |
| 42 | if (get_size(&opt.limit, *argv)) { |
| 43 | fprintf(stderr, "Illegal \"limit\"\n"); |
| 44 | return -1; |
| 45 | } |
| 46 | ok++; |
| 47 | } else if (strcmp(*argv, "help") == 0) { |
| 48 | explain(); |
| 49 | return -1; |
| 50 | } else { |
| 51 | fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 52 | explain(); |
| 53 | return -1; |
| 54 | } |
| 55 | argc--; argv++; |
| 56 | } |
| 57 | |
| 58 | if (ok) |
| 59 | addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 64 | { |
| 65 | struct tc_fifo_qopt *qopt; |
| 66 | |
| 67 | if (opt == NULL) |
| 68 | return 0; |
| 69 | |
| 70 | if (RTA_PAYLOAD(opt) < sizeof(*qopt)) |
| 71 | return -1; |
| 72 | qopt = RTA_DATA(opt); |
| 73 | if (strcmp(qu->id, "bfifo") == 0) { |
| 74 | SPRINT_BUF(b1); |
| 75 | fprintf(f, "limit %s", sprint_size(qopt->limit, b1)); |
| 76 | } else |
| 77 | fprintf(f, "limit %up", qopt->limit); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int fifo_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | struct qdisc_util bfifo_util = { |
| 88 | NULL, |
| 89 | "bfifo", |
| 90 | fifo_parse_opt, |
| 91 | fifo_print_opt, |
| 92 | fifo_print_xstats, |
| 93 | }; |
| 94 | |
| 95 | struct qdisc_util pfifo_util = { |
| 96 | NULL, |
| 97 | "pfifo", |
| 98 | fifo_parse_opt, |
| 99 | fifo_print_opt, |
| 100 | fifo_print_xstats, |
| 101 | }; |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 102 | |
| 103 | extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); |
| 104 | struct qdisc_util pfifo_fast_util = { |
| 105 | NULL, |
| 106 | "pfifo_fast", |
| 107 | NULL, |
| 108 | prio_print_opt, |
| 109 | fifo_print_xstats, |
| 110 | }; |