summaryrefslogtreecommitdiff
path: root/lib/cli/qdisc/pfifo.c
blob: fbaa872ea07218e2c5e6a3ccf6b3f24ab3914005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* SPDX-License-Identifier: LGPL-2.1-only */
/*
 * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
 */

#include "nl-default.h"

#include <netlink/cli/utils.h>
#include <netlink/cli/tc.h>
#include <netlink/route/qdisc/fifo.h>

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_tc *tc, int argc, char **argv)
{
	struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;

	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_tc_module pfifo_module =
{
	.tm_name		= "pfifo",
	.tm_type		= RTNL_TC_TYPE_QDISC,
	.tm_parse_argv		= pfifo_parse_argv,
};

static void _nl_init pfifo_init(void)
{
	nl_cli_tc_register(&pfifo_module);
}

static void _nl_exit pfifo_exit(void)
{
	nl_cli_tc_unregister(&pfifo_module);
}