| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* q_fifo.c FIFO. |
| 4 |
* |
| 5 |
* Authors: Alexey Kuznetsov, <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <unistd.h> |
| 11 |
#include <fcntl.h> |
| 12 |
#include <sys/socket.h> |
| 13 |
#include <netinet/in.h> |
| 14 |
#include <arpa/inet.h> |
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
#include "utils.h" |
| 18 |
#include "tc_util.h" |
| 19 |
|
| 20 |
static void explain(void) |
| 21 |
{ |
| 22 |
fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n"); |
| 23 |
} |
| 24 |
|
| 25 |
static int fifo_parse_opt(const struct qdisc_util *qu, int argc, char **argv, |
| 26 |
struct nlmsghdr *n, const char *dev) |
| 27 |
{ |
| 28 |
int ok = 0; |
| 29 |
struct tc_fifo_qopt opt = {}; |
| 30 |
|
| 31 |
while (argc > 0) { |
| 32 |
if (strcmp(*argv, "limit") == 0) { |
| 33 |
NEXT_ARG(); |
| 34 |
if (get_size(&opt.limit, *argv)) { |
| 35 |
fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv); |
| 36 |
return -1; |
| 37 |
} |
| 38 |
ok++; |
| 39 |
} else if (strcmp(*argv, "help") == 0) { |
| 40 |
explain(); |
| 41 |
return -1; |
| 42 |
} else { |
| 43 |
fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv); |
| 44 |
explain(); |
| 45 |
return -1; |
| 46 |
} |
| 47 |
argc--; argv++; |
| 48 |
} |
| 49 |
|
| 50 |
if (ok) |
| 51 |
addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
static int fifo_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 56 |
{ |
| 57 |
struct tc_fifo_qopt *qopt; |
| 58 |
|
| 59 |
if (opt == NULL) |
| 60 |
return 0; |
| 61 |
|
| 62 |
if (RTA_PAYLOAD(opt) < sizeof(*qopt)) |
| 63 |
return -1; |
| 64 |
qopt = RTA_DATA(opt); |
| 65 |
if (strcmp(qu->id, "bfifo") == 0) |
| 66 |
print_size(PRINT_ANY, "limit", "limit %s", qopt->limit); |
| 67 |
else |
| 68 |
print_uint(PRINT_ANY, "limit", "limit %up", qopt->limit); |
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
struct qdisc_util bfifo_qdisc_util = { |
| 74 |
.id = "bfifo", |
| 75 |
.parse_qopt = fifo_parse_opt, |
| 76 |
.print_qopt = fifo_print_opt, |
| 77 |
}; |
| 78 |
|
| 79 |
struct qdisc_util pfifo_qdisc_util = { |
| 80 |
.id = "pfifo", |
| 81 |
.parse_qopt = fifo_parse_opt, |
| 82 |
.print_qopt = fifo_print_opt, |
| 83 |
}; |
| 84 |
|
| 85 |
struct qdisc_util pfifo_head_drop_qdisc_util = { |
| 86 |
.id = "pfifo_head_drop", |
| 87 |
.parse_qopt = fifo_parse_opt, |
| 88 |
.print_qopt = fifo_print_opt, |
| 89 |
}; |
| 90 |
|
| 91 |
struct qdisc_util pfifo_fast_qdisc_util = { |
| 92 |
.id = "pfifo_fast", |
| 93 |
.print_qopt = prio_print_opt, |
| 94 |
}; |