1/*
2 * src/lib/bfifo.c     	bfifo module for CLI lib
3 *
4 *	This library is free software; you can redistribute it and/or
5 *	modify it under the terms of the GNU Lesser General Public
6 *	License as published by the Free Software Foundation version 2.1
7 *	of the License.
8 *
9 * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
10 */
11
12#include <netlink/cli/utils.h>
13#include <netlink/cli/tc.h>
14#include <netlink/route/qdisc/fifo.h>
15
16static void print_usage(void)
17{
18	printf(
19"Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n"
20"\n"
21"OPTIONS\n"
22"     --help                Show this help text.\n"
23"     --limit=LIMIT         Maximum queue length in number of bytes.\n"
24"\n"
25"EXAMPLE"
26"    # Attach bfifo with a 4KB bytes limit to eth1\n"
27"    nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n");
28}
29
30static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
31{
32	struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
33	int limit;
34
35	for (;;) {
36		int c, optidx = 0;
37		enum {
38			ARG_LIMIT = 257,
39		};
40		static struct option long_opts[] = {
41			{ "help", 0, 0, 'h' },
42			{ "limit", 1, 0, ARG_LIMIT },
43			{ 0, 0, 0, 0 }
44		};
45
46		c = getopt_long(argc, argv, "h", long_opts, &optidx);
47		if (c == -1)
48			break;
49
50		switch (c) {
51		case 'h':
52			print_usage();
53			return;
54
55		case ARG_LIMIT:
56			limit = nl_size2int(optarg);
57			if (limit < 0) {
58				nl_cli_fatal(limit, "Unable to parse bfifo limit "
59					"\"%s\": Invalid format.", optarg);
60			}
61
62			rtnl_qdisc_fifo_set_limit(qdisc, limit);
63			break;
64		}
65 	}
66}
67
68static struct nl_cli_tc_module bfifo_module =
69{
70	.tm_name		= "bfifo",
71	.tm_type		= RTNL_TC_TYPE_QDISC,
72	.tm_parse_argv		= bfifo_parse_argv,
73};
74
75static void __init bfifo_init(void)
76{
77	nl_cli_tc_register(&bfifo_module);
78}
79
80static void __exit bfifo_exit(void)
81{
82	nl_cli_tc_unregister(&bfifo_module);
83}
84