From 18848090f99cae37ac1a3052369ab4d26ed9ada0 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Tue, 19 Oct 2010 16:51:55 +0200 Subject: pfifo/bfifo qdisc support for cli libs --- lib/Makefile.am | 6 +++- lib/cli/qdisc/bfifo.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/cli/qdisc/pfifo.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 lib/cli/qdisc/bfifo.c create mode 100644 lib/cli/qdisc/pfifo.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 0769011..386e02c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -57,8 +57,12 @@ libnl_route_la_SOURCES = \ if ENABLE_CLI nobase_pkglib_LTLIBRARIES = \ cli/qdisc/htb.la \ - cli/qdisc/blackhole.la + cli/qdisc/blackhole.la \ + cli/qdisc/pfifo.la \ + cli/qdisc/bfifo.la cli_qdisc_htb_la_LDFLAGS = -module -version-info 0:0:0 cli_qdisc_blackhole_la_LDFLAGS = -module -version-info 0:0:0 +cli_qdisc_pfifo_la_LDFLAGS = -module -version-info 0:0:0 +cli_qdisc_bfifo_la_LDFLAGS = -module -version-info 0:0:0 endif diff --git a/lib/cli/qdisc/bfifo.c b/lib/cli/qdisc/bfifo.c new file mode 100644 index 0000000..7354728 --- /dev/null +++ b/lib/cli/qdisc/bfifo.c @@ -0,0 +1,81 @@ +/* + * src/lib/bfifo.c bfifo module for CLI lib + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2010 Thomas Graf + */ + +#include +#include +#include + +static void print_usage(void) +{ + printf( +"Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n" +"\n" +"OPTIONS\n" +" --help Show this help text.\n" +" --limit=LIMIT Maximum queue length in number of bytes.\n" +"\n" +"EXAMPLE" +" # Attach bfifo with a 4KB bytes limit to eth1\n" +" nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n"); +} + +static void bfifo_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv) +{ + int limit; + + for (;;) { + int c, optidx = 0; + enum { + ARG_LIMIT = 257, + }; + static struct option long_opts[] = { + { "help", 0, 0, 'h' }, + { "limit", 1, 0, ARG_LIMIT }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "h", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage(); + return; + + case ARG_LIMIT: + limit = nl_size2int(optarg); + if (limit < 0) { + nl_cli_fatal(limit, "Unable to parse bfifo limit " + "\"%s\": Invalid format.", optarg); + } + + rtnl_qdisc_fifo_set_limit(qdisc, limit); + break; + } + } +} + +static struct nl_cli_qdisc_module bfifo_module = +{ + .qm_name = "bfifo", + .qm_parse_argv = bfifo_parse_argv, +}; + +static void __init bfifo_init(void) +{ + nl_cli_qdisc_register(&bfifo_module); +} + +static void __exit bfifo_exit(void) +{ + nl_cli_qdisc_unregister(&bfifo_module); +} diff --git a/lib/cli/qdisc/pfifo.c b/lib/cli/qdisc/pfifo.c new file mode 100644 index 0000000..4d900d8 --- /dev/null +++ b/lib/cli/qdisc/pfifo.c @@ -0,0 +1,74 @@ + +/* + * src/lib/pfifo.c pfifo module for CLI lib + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2010 Thomas Graf + */ + +#include +#include +#include + +static void print_usage(void) +{ + printf( +"Usage: nl-qdisc-add [...] pfifo [OPTIONS]...\n" +"\n" +"OPTIONS\n" +" --help Show this help text.\n" +" --limit=LIMIT Maximum queue length in number of packets.\n" +"\n" +"EXAMPLE" +" # Attach pfifo with a 32 packet limit to eth1\n" +" nl-qdisc-add --dev=eth1 --parent=root pfifo --limit=32\n"); +} + +static void pfifo_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv) +{ + for (;;) { + int c, optidx = 0; + enum { + ARG_LIMIT = 257, + }; + static struct option long_opts[] = { + { "help", 0, 0, 'h' }, + { "limit", 1, 0, ARG_LIMIT }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "h", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage(); + return; + + case ARG_LIMIT: + rtnl_qdisc_fifo_set_limit(qdisc, nl_cli_parse_u32(optarg)); + break; + } + } +} + +static struct nl_cli_qdisc_module pfifo_module = +{ + .qm_name = "pfifo", + .qm_parse_argv = pfifo_parse_argv, +}; + +static void __init pfifo_init(void) +{ + nl_cli_qdisc_register(&pfifo_module); +} + +static void __exit pfifo_exit(void) +{ + nl_cli_qdisc_unregister(&pfifo_module); +} -- cgit v0.12