cgroup.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * lib/cli/cls/cgroup.c cgroup classifier 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/cli/cls.h>
  14. #include <netlink/route/cls/cgroup.h>
  15. static void print_usage(void)
  16. {
  17. printf(
  18. "Usage: nl-cls-add [...] cgroup [OPTIONS]...\n"
  19. "\n"
  20. "OPTIONS\n"
  21. " -h, --help Show this help text.\n"
  22. " -e, --ematch=EXPR Ematch expression\n"
  23. "\n"
  24. "EXAMPLE"
  25. " nl-cls-add --dev=eth0 --parent=q_root cgroup\n");
  26. }
  27. static void parse_argv(struct rtnl_tc *tc, int argc, char **argv)
  28. {
  29. struct rtnl_cls *cls = (struct rtnl_cls *) tc;
  30. struct rtnl_ematch_tree *tree;
  31. for (;;) {
  32. int c, optidx = 0;
  33. static struct option long_opts[] = {
  34. { "help", 0, 0, 'h' },
  35. { "ematch", 1, 0, 'e' },
  36. { 0, 0, 0, 0 }
  37. };
  38. c = getopt_long(argc, argv, "he:", long_opts, &optidx);
  39. if (c == -1)
  40. break;
  41. switch (c) {
  42. case 'h':
  43. print_usage();
  44. exit(0);
  45. case 'e':
  46. tree = nl_cli_cls_parse_ematch(cls, optarg);
  47. rtnl_cgroup_set_ematch(cls, tree);
  48. break;
  49. }
  50. }
  51. }
  52. static struct nl_cli_tc_module cgroup_module =
  53. {
  54. .tm_name = "cgroup",
  55. .tm_type = RTNL_TC_TYPE_CLS,
  56. .tm_parse_argv = parse_argv,
  57. };
  58. static void __init cgroup_init(void)
  59. {
  60. nl_cli_tc_register(&cgroup_module);
  61. }
  62. static void __exit cgroup_exit(void)
  63. {
  64. nl_cli_tc_unregister(&cgroup_module);
  65. }