bfifo.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <netlink/cli/utils.h>
  12. #include <netlink/cli/tc.h>
  13. #include <netlink/route/qdisc/fifo.h>
  14. static void print_usage(void)
  15. {
  16. printf(
  17. "Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n"
  18. "\n"
  19. "OPTIONS\n"
  20. " --help Show this help text.\n"
  21. " --limit=LIMIT Maximum queue length in number of bytes.\n"
  22. "\n"
  23. "EXAMPLE"
  24. " # Attach bfifo with a 4KB bytes limit to eth1\n"
  25. " nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n");
  26. }
  27. static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
  28. {
  29. struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
  30. int limit;
  31. for (;;) {
  32. int c, optidx = 0;
  33. enum {
  34. ARG_LIMIT = 257,
  35. };
  36. static struct option long_opts[] = {
  37. { "help", 0, 0, 'h' },
  38. { "limit", 1, 0, ARG_LIMIT },
  39. { 0, 0, 0, 0 }
  40. };
  41. c = getopt_long(argc, argv, "h", long_opts, &optidx);
  42. if (c == -1)
  43. break;
  44. switch (c) {
  45. case 'h':
  46. print_usage();
  47. return;
  48. case ARG_LIMIT:
  49. limit = nl_size2int(optarg);
  50. if (limit < 0) {
  51. nl_cli_fatal(limit, "Unable to parse bfifo limit "
  52. "\"%s\": Invalid format.", optarg);
  53. }
  54. rtnl_qdisc_fifo_set_limit(qdisc, limit);
  55. break;
  56. }
  57. }
  58. }
  59. static struct nl_cli_tc_module bfifo_module =
  60. {
  61. .tm_name = "bfifo",
  62. .tm_type = RTNL_TC_TYPE_QDISC,
  63. .tm_parse_argv = bfifo_parse_argv,
  64. };
  65. static void __init bfifo_init(void)
  66. {
  67. nl_cli_tc_register(&bfifo_module);
  68. }
  69. static void __exit bfifo_exit(void)
  70. {
  71. nl_cli_tc_unregister(&bfifo_module);
  72. }