pfifo.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * src/lib/pfifo.c pfifo 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 [...] pfifo [OPTIONS]...\n"
  18. "\n"
  19. "OPTIONS\n"
  20. " --help Show this help text.\n"
  21. " --limit=LIMIT Maximum queue length in number of packets.\n"
  22. "\n"
  23. "EXAMPLE"
  24. " # Attach pfifo with a 32 packet limit to eth1\n"
  25. " nl-qdisc-add --dev=eth1 --parent=root pfifo --limit=32\n");
  26. }
  27. static void pfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
  28. {
  29. struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
  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. c = getopt_long(argc, argv, "h", long_opts, &optidx);
  41. if (c == -1)
  42. break;
  43. switch (c) {
  44. case 'h':
  45. print_usage();
  46. return;
  47. case ARG_LIMIT:
  48. rtnl_qdisc_fifo_set_limit(qdisc, nl_cli_parse_u32(optarg));
  49. break;
  50. }
  51. }
  52. }
  53. static struct nl_cli_tc_module pfifo_module =
  54. {
  55. .tm_name = "pfifo",
  56. .tm_type = RTNL_TC_TYPE_QDISC,
  57. .tm_parse_argv = pfifo_parse_argv,
  58. };
  59. static void __init pfifo_init(void)
  60. {
  61. nl_cli_tc_register(&pfifo_module);
  62. }
  63. static void __exit pfifo_exit(void)
  64. {
  65. nl_cli_tc_unregister(&pfifo_module);
  66. }