libnl 3.5.0

pfifo.c
1
2 /*
3 * src/lib/pfifo.c pfifo module for CLI lib
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
11 */
12
13 #include <netlink/cli/utils.h>
14 #include <netlink/cli/tc.h>
15 #include <netlink/route/qdisc/fifo.h>
16
17 static void print_usage(void)
18 {
19 printf(
20 "Usage: nl-qdisc-add [...] pfifo [OPTIONS]...\n"
21 "\n"
22 "OPTIONS\n"
23 " --help Show this help text.\n"
24 " --limit=LIMIT Maximum queue length in number of packets.\n"
25 "\n"
26 "EXAMPLE"
27 " # Attach pfifo with a 32 packet limit to eth1\n"
28 " nl-qdisc-add --dev=eth1 --parent=root pfifo --limit=32\n");
29 }
30
31 static void pfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
32 {
33 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
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 rtnl_qdisc_fifo_set_limit(qdisc, nl_cli_parse_u32(optarg));
57 break;
58 }
59 }
60 }
61
62 static struct nl_cli_tc_module pfifo_module =
63 {
64 .tm_name = "pfifo",
65 .tm_type = RTNL_TC_TYPE_QDISC,
66 .tm_parse_argv = pfifo_parse_argv,
67 };
68
69 static void __init pfifo_init(void)
70 {
71 nl_cli_tc_register(&pfifo_module);
72 }
73
74 static void __exit pfifo_exit(void)
75 {
76 nl_cli_tc_unregister(&pfifo_module);
77 }
nl_cli_tc_module
Definition: tc.h:28
nl_cli_parse_u32
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
Definition: utils.c:43
rtnl_qdisc_fifo_set_limit
int rtnl_qdisc_fifo_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of FIFO qdisc.
Definition: fifo.c:106