libnl: /data/src/libnl3/lib/cli/cls/cgroup.c Source File

libnl 3.7.0

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