cgroup.c

00001 /*
00002  * lib/cli/cls/cgroup.c         cgroup classifier module for CLI lib
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 #include <netlink/cli/utils.h>
00013 #include <netlink/cli/tc.h>
00014 #include <netlink/cli/cls.h>
00015 #include <netlink/route/cls/cgroup.h>
00016 
00017 static void print_usage(void)
00018 {
00019         printf(
00020 "Usage: nl-cls-add [...] cgroup [OPTIONS]...\n"
00021 "\n"
00022 "OPTIONS\n"
00023 " -h, --help                Show this help text.\n"
00024 " -e, --ematch=EXPR         Ematch expression\n"
00025 "\n"
00026 "EXAMPLE"
00027 "    nl-cls-add --dev=eth0 --parent=q_root cgroup\n");
00028 }
00029 
00030 static void parse_argv(struct rtnl_tc *tc, int argc, char **argv)
00031 {
00032         struct rtnl_cls *cls = (struct rtnl_cls *) tc;
00033         struct rtnl_ematch_tree *tree;
00034 
00035         for (;;) {
00036                 int c, optidx = 0;
00037                 static struct option long_opts[] = {
00038                         { "help", 0, 0, 'h' },
00039                         { "ematch", 1, 0, 'e' },
00040                         { 0, 0, 0, 0 }
00041                 };
00042         
00043                 c = getopt_long(argc, argv, "he:", long_opts, &optidx);
00044                 if (c == -1)
00045                         break;
00046 
00047                 switch (c) {
00048                 case 'h':
00049                         print_usage();
00050                         exit(0);
00051 
00052                 case 'e':
00053                         tree = nl_cli_cls_parse_ematch(cls, optarg);
00054                         rtnl_cgroup_set_ematch(cls, tree);
00055                         break;
00056                 }
00057         }
00058 }
00059 
00060 static struct nl_cli_tc_module cgroup_module =
00061 {
00062         .tm_name                = "cgroup",
00063         .tm_type                = RTNL_TC_TYPE_CLS,
00064         .tm_parse_argv          = parse_argv,
00065 };
00066 
00067 static void __init cgroup_init(void)
00068 {
00069         nl_cli_tc_register(&cgroup_module);
00070 }
00071 
00072 static void __exit cgroup_exit(void)
00073 {
00074         nl_cli_tc_unregister(&cgroup_module);
00075 }