2 * src/cls/basic.c Basic Classifier
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2 of the License.
8 * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/route/cls/basic.h>
13 #include <netlink/route/cls/ematch.h>
15 static void print_usage(void)
18 "Usage: ... basic [OPTIONS]...\n"
21 " -h, --help Show this help.\n"
22 " -e, --ematch=MATCH Extended match (See --ematch help).\n"
23 " -c, --classid=HANDLE Target class to classify matching packets to.\n"
28 static void basic_parse_argv(struct rtnl_cls *cls, int argc, char **argv)
33 int c, optidx = 0, err;
34 static struct option long_opts[] = {
35 { "help", 0, 0, 'h' },
36 { "ematch", 1, 0, 'e' },
37 { "classid", 1, 0, 'c' },
41 c = getopt_long(argc, argv, "he:c:", long_opts, &optidx);
54 if ((err = parse_ematch_syntax(optarg, &tree)) < 0)
55 fatal(err, "Error while parsing ematch: %s",
58 if ((err = rtnl_basic_set_ematch(cls, tree)) < 0)
59 fatal(err, "Unable to set ematch: %s",
65 if ((err = rtnl_tc_str2handle(optarg, &classid)) < 0)
66 fatal(err, "Invalid classid \"%s\": %s",
67 optarg, nl_geterror(err));
69 if ((err = rtnl_basic_set_classid(cls, classid)) < 0)
70 fatal(err, "Unable to set classid: %s",
77 static struct cls_module basic_module = {
79 .parse_argv = basic_parse_argv,
82 static void __attribute__ ((constructor)) basic_init(void)
84 register_cls_module(&basic_module);
87 static void __attribute__ ((destructor)) basic_exit(void)
89 unregister_cls_module(&basic_module);