summaryrefslogtreecommitdiffstats
path: root/src/cls/cgroup.c
blob: ad0392f703aaba1d3db8ac33a1073f11cc750607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * src/cls/cgroup.c	Control Groups Classifier
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation version 2 of the License.
 *
 * Copyright (c) 2009 Thomas Graf <tgraf@suug.ch>
 */

#include "utils.h"
#include <netlink/route/cls/cgroup.h>
#include <netlink/route/cls/ematch.h>

static void print_usage(void)
{
	printf(
"Usage: ... cgroup [OPTIONS]...\n"
"\n"
"Options\n"
" -h, --help                Show this help.\n"
" -e, --ematch=MATCH        Extended match (See --ematch help).\n"
" -c, --classid=HANDLE      Target class to classify matching packets to.\n"
	);
	exit(0);
}

static void basic_parse_argv(struct rtnl_cls *cls, int argc, char **argv)
{
	for (;;) {
		int c, optidx = 0;
		static struct option long_opts[] = {
			{ "help", 0, 0, 'h' },
			{ "ematch", 1, 0, 'e' },
			{ "classid", 1, 0, 'c' },
			{ 0, 0, 0, 0 }
		};
	
		c = getopt_long(argc, argv, "he:c:", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case '?':
			exit(NLE_INVAL);

		case 'h':
			print_usage();

#if 0
		case 'e':
			if ((err = parse_ematch_syntax(optarg, &tree)) < 0)
				fatal(err, "Error while parsing ematch: %s",
				      nl_geterror(err));

			if ((err = rtnl_basic_set_ematch(cls, tree)) < 0)
				fatal(err, "Unable to set ematch: %s",
					nl_geterror(err));
			break;
#endif
		}
 	}
}

static struct cls_module cgroup_module = {
	.name		= "cgroup",
	.parse_argv	= basic_parse_argv,
};

static void __init cgroup_init(void)
{
	register_cls_module(&cgroup_module);
}

static void __exit cgroup_exit(void)
{
	unregister_cls_module(&cgroup_module);
}