1ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf/* 2ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * src/cls/cgroup.c Control Groups Classifier 3ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * 4ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * This library is free software; you can redistribute it and/or 5ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * modify it under the terms of the GNU General Public License as 6ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * published by the Free Software Foundation version 2 of the License. 7ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * 8ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf * Copyright (c) 2009 Thomas Graf <tgraf@suug.ch> 9ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf */ 10ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 11ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf#include "utils.h" 12ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf#include <netlink/route/cls/cgroup.h> 13ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf#include <netlink/route/cls/ematch.h> 14ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 15ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Grafstatic void print_usage(void) 16ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf{ 17ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf printf( 18ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf"Usage: ... cgroup [OPTIONS]...\n" 19ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf"\n" 20ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf"Options\n" 21ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf" -h, --help Show this help.\n" 22ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf" -e, --ematch=MATCH Extended match (See --ematch help).\n" 23ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf" -c, --classid=HANDLE Target class to classify matching packets to.\n" 24ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf ); 25ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf exit(0); 26ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf} 27ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 28ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Grafstatic void basic_parse_argv(struct rtnl_cls *cls, int argc, char **argv) 29ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf{ 30ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf for (;;) { 31ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf int c, optidx = 0; 32ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf static struct option long_opts[] = { 33ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf { "help", 0, 0, 'h' }, 34ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf { "ematch", 1, 0, 'e' }, 35ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf { "classid", 1, 0, 'c' }, 36ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf { 0, 0, 0, 0 } 37ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf }; 38ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 39ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf c = getopt_long(argc, argv, "he:c:", long_opts, &optidx); 40ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf if (c == -1) 41ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf break; 42ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 43ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf switch (c) { 44ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf case '?': 45ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf exit(NLE_INVAL); 46ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 47ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf case 'h': 48ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf print_usage(); 49ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 50ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf#if 0 51ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf case 'e': 52ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf if ((err = parse_ematch_syntax(optarg, &tree)) < 0) 53ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf fatal(err, "Error while parsing ematch: %s", 54ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf nl_geterror(err)); 55ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 56ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf if ((err = rtnl_basic_set_ematch(cls, tree)) < 0) 57ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf fatal(err, "Unable to set ematch: %s", 58ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf nl_geterror(err)); 59ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf break; 60ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf#endif 61ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf } 62ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf } 63ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf} 64ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 65ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Grafstatic struct cls_module cgroup_module = { 66ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf .name = "cgroup", 67ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf .parse_argv = basic_parse_argv, 68ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf}; 69ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 70ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Grafstatic void __init cgroup_init(void) 71ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf{ 72ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf register_cls_module(&cgroup_module); 73ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf} 74ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf 75ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Grafstatic void __exit cgroup_exit(void) 76ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf{ 77ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf unregister_cls_module(&cgroup_module); 78ef858fb492dfe98e3ae194264fbc73649cf8493aThomas Graf} 79