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