xref: /aosp_15_r20/external/libnl/lib/cli/cls/cgroup.c (revision 4dc78e53d49367fa8e61b07018507c90983a077d)
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2010-2011 Thomas Graf <[email protected]>
4  */
5 
6 #include "nl-default.h"
7 
8 #include <netlink/cli/utils.h>
9 #include <netlink/cli/tc.h>
10 #include <netlink/cli/cls.h>
11 #include <netlink/route/cls/cgroup.h>
12 
print_usage(void)13 static void print_usage(void)
14 {
15 	printf(
16 "Usage: nl-cls-add [...] cgroup [OPTIONS]...\n"
17 "\n"
18 "OPTIONS\n"
19 " -h, --help                Show this help text.\n"
20 " -e, --ematch=EXPR         Ematch expression\n"
21 "\n"
22 "EXAMPLE"
23 "    nl-cls-add --dev=eth0 --parent=q_root cgroup\n");
24 }
25 
parse_argv(struct rtnl_tc * tc,int argc,char ** argv)26 static void parse_argv(struct rtnl_tc *tc, int argc, char **argv)
27 {
28 	struct rtnl_cls *cls = (struct rtnl_cls *) tc;
29 	struct rtnl_ematch_tree *tree;
30 
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 
39 		c = getopt_long(argc, argv, "he:", long_opts, &optidx);
40 		if (c == -1)
41 			break;
42 
43 		switch (c) {
44 		case 'h':
45 			print_usage();
46 			exit(0);
47 
48 		case 'e':
49 			tree = nl_cli_cls_parse_ematch(cls, optarg);
50 			rtnl_cgroup_set_ematch(cls, tree);
51 			break;
52 		}
53 	}
54 }
55 
56 static struct nl_cli_tc_module cgroup_module =
57 {
58 	.tm_name		= "cgroup",
59 	.tm_type		= RTNL_TC_TYPE_CLS,
60 	.tm_parse_argv		= parse_argv,
61 };
62 
cgroup_init(void)63 static void _nl_init cgroup_init(void)
64 {
65 	nl_cli_tc_register(&cgroup_module);
66 }
67 
cgroup_exit(void)68 static void _nl_exit cgroup_exit(void)
69 {
70 	nl_cli_tc_unregister(&cgroup_module);
71 }
72