libnl  3.7.0
bfifo.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
4  */
5 
6 #include <netlink/cli/utils.h>
7 #include <netlink/cli/tc.h>
8 #include <netlink/route/qdisc/fifo.h>
9 
10 static void print_usage(void)
11 {
12  printf(
13 "Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n"
14 "\n"
15 "OPTIONS\n"
16 " --help Show this help text.\n"
17 " --limit=LIMIT Maximum queue length in number of bytes.\n"
18 "\n"
19 "EXAMPLE"
20 " # Attach bfifo with a 4KB bytes limit to eth1\n"
21 " nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n");
22 }
23 
24 static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
25 {
26  struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
27  int limit;
28 
29  for (;;) {
30  int c, optidx = 0;
31  enum {
32  ARG_LIMIT = 257,
33  };
34  static struct option long_opts[] = {
35  { "help", 0, 0, 'h' },
36  { "limit", 1, 0, ARG_LIMIT },
37  { 0, 0, 0, 0 }
38  };
39 
40  c = getopt_long(argc, argv, "h", long_opts, &optidx);
41  if (c == -1)
42  break;
43 
44  switch (c) {
45  case 'h':
46  print_usage();
47  return;
48 
49  case ARG_LIMIT:
50  limit = nl_size2int(optarg);
51  if (limit < 0) {
52  nl_cli_fatal(limit, "Unable to parse bfifo limit "
53  "\"%s\": Invalid format.", optarg);
54  }
55 
56  rtnl_qdisc_fifo_set_limit(qdisc, limit);
57  break;
58  }
59  }
60 }
61 
62 static struct nl_cli_tc_module bfifo_module =
63 {
64  .tm_name = "bfifo",
65  .tm_type = RTNL_TC_TYPE_QDISC,
66  .tm_parse_argv = bfifo_parse_argv,
67 };
68 
69 static void __init bfifo_init(void)
70 {
71  nl_cli_tc_register(&bfifo_module);
72 }
73 
74 static void __exit bfifo_exit(void)
75 {
76  nl_cli_tc_unregister(&bfifo_module);
77 }
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:71
int rtnl_qdisc_fifo_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of FIFO qdisc.
Definition: fifo.c:100
long nl_size2int(const char *str)
Convert a character string to a size.
Definition: utils.c:288