| 1 |
/* SPDX-License-Identifier: LGPL-2.1-only */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2010-2011 Thomas Graf <[email protected]> |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "nl-default.h" |
| 7 |
|
| 8 |
#include <netlink/cli/utils.h> |
| 9 |
#include <netlink/cli/tc.h> |
| 10 |
#include <netlink/route/qdisc/fifo.h> |
| 11 |
|
| 12 |
static void print_usage(void) |
| 13 |
{ |
| 14 |
printf( |
| 15 |
"Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n" |
| 16 |
"\n" |
| 17 |
"OPTIONS\n" |
| 18 |
" --help Show this help text.\n" |
| 19 |
" --limit=LIMIT Maximum queue length in number of bytes.\n" |
| 20 |
"\n" |
| 21 |
"EXAMPLE" |
| 22 |
" # Attach bfifo with a 4KB bytes limit to eth1\n" |
| 23 |
" nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n"); |
| 24 |
} |
| 25 |
|
| 26 |
static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv) |
| 27 |
{ |
| 28 |
struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc; |
| 29 |
int limit; |
| 30 |
|
| 31 |
for (;;) { |
| 32 |
int c, optidx = 0; |
| 33 |
enum { |
| 34 |
ARG_LIMIT = 257, |
| 35 |
}; |
| 36 |
static struct option long_opts[] = { |
| 37 |
{ "help", 0, 0, 'h' }, |
| 38 |
{ "limit", 1, 0, ARG_LIMIT }, |
| 39 |
{ 0, 0, 0, 0 } |
| 40 |
}; |
| 41 |
|
| 42 |
c = getopt_long(argc, argv, "h", long_opts, &optidx); |
| 43 |
if (c == -1) |
| 44 |
break; |
| 45 |
|
| 46 |
switch (c) { |
| 47 |
case 'h': |
| 48 |
print_usage(); |
| 49 |
return; |
| 50 |
|
| 51 |
case ARG_LIMIT: |
| 52 |
limit = nl_size2int(optarg); |
| 53 |
if (limit < 0) { |
| 54 |
nl_cli_fatal(limit, "Unable to parse bfifo limit " |
| 55 |
"\"%s\": Invalid format.", optarg); |
| 56 |
} |
| 57 |
|
| 58 |
rtnl_qdisc_fifo_set_limit(qdisc, limit); |
| 59 |
break; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
static struct nl_cli_tc_module bfifo_module = |
| 65 |
{ |
| 66 |
.tm_name = "bfifo", |
| 67 |
.tm_type = RTNL_TC_TYPE_QDISC, |
| 68 |
.tm_parse_argv = bfifo_parse_argv, |
| 69 |
}; |
| 70 |
|
| 71 |
static void _nl_init bfifo_init(void) |
| 72 |
{ |
| 73 |
nl_cli_tc_register(&bfifo_module); |
| 74 |
} |
| 75 |
|
| 76 |
static void _nl_exit bfifo_exit(void) |
| 77 |
{ |
| 78 |
nl_cli_tc_unregister(&bfifo_module); |
| 79 |
} |