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
print_usage(void)12 static void print_usage(void)
13 {
14 printf(
15 "Usage: nl-qdisc-add [...] pfifo [OPTIONS]...\n"
16 "\n"
17 "OPTIONS\n"
18 " --help Show this help text.\n"
19 " --limit=LIMIT Maximum queue length in number of packets.\n"
20 "\n"
21 "EXAMPLE"
22 " # Attach pfifo with a 32 packet limit to eth1\n"
23 " nl-qdisc-add --dev=eth1 --parent=root pfifo --limit=32\n");
24 }
25
pfifo_parse_argv(struct rtnl_tc * tc,int argc,char ** argv)26 static void pfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
27 {
28 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
29
30 for (;;) {
31 int c, optidx = 0;
32 enum {
33 ARG_LIMIT = 257,
34 };
35 static struct option long_opts[] = {
36 { "help", 0, 0, 'h' },
37 { "limit", 1, 0, ARG_LIMIT },
38 { 0, 0, 0, 0 }
39 };
40
41 c = getopt_long(argc, argv, "h", long_opts, &optidx);
42 if (c == -1)
43 break;
44
45 switch (c) {
46 case 'h':
47 print_usage();
48 return;
49
50 case ARG_LIMIT:
51 rtnl_qdisc_fifo_set_limit(qdisc, nl_cli_parse_u32(optarg));
52 break;
53 }
54 }
55 }
56
57 static struct nl_cli_tc_module pfifo_module =
58 {
59 .tm_name = "pfifo",
60 .tm_type = RTNL_TC_TYPE_QDISC,
61 .tm_parse_argv = pfifo_parse_argv,
62 };
63
pfifo_init(void)64 static void _nl_init pfifo_init(void)
65 {
66 nl_cli_tc_register(&pfifo_module);
67 }
68
pfifo_exit(void)69 static void _nl_exit pfifo_exit(void)
70 {
71 nl_cli_tc_unregister(&pfifo_module);
72 }
73