2 * src/cls-utils.c Classifier Helpers
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-2009 Thomas Graf <tgraf@suug.ch>
13 struct rtnl_cls *nlt_alloc_cls(void)
17 cls = rtnl_cls_alloc();
19 fatal(ENOMEM, "Unable to allocate classifier object");
24 void parse_dev(struct rtnl_cls *cls, struct nl_cache *link_cache, char *arg)
28 if (!(ival = rtnl_link_name2i(link_cache, arg)))
29 fatal(ENOENT, "Link \"%s\" does not exist", arg);
31 rtnl_cls_set_ifindex(cls, ival);
34 void parse_prio(struct rtnl_cls *cls, char *arg)
36 uint32_t prio = parse_u32(arg);
37 rtnl_cls_set_prio(cls, prio);
40 void parse_parent(struct rtnl_cls *cls, char *arg)
45 if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
46 fatal(err, "Unable to parse handle \"%s\": %s",
47 arg, nl_geterror(err));
49 rtnl_cls_set_parent(cls, parent);
52 void parse_handle(struct rtnl_cls *cls, char *arg)
57 if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
58 fatal(err, "Unable to parse handle \"%s\": %s",
59 arg, nl_geterror(err));
61 rtnl_cls_set_handle(cls, handle);
64 void parse_proto(struct rtnl_cls *cls, char *arg)
66 int proto = nl_str2ether_proto(arg);
68 fatal(proto, "Unable to parse protocol \"%s\": %s",
69 arg, nl_geterror(proto));
70 rtnl_cls_set_protocol(cls, proto);
73 static NL_LIST_HEAD(cls_modules);
75 struct cls_module *lookup_cls_mod(struct rtnl_cls_ops *ops)
77 struct cls_module *mod;
79 nl_list_for_each_entry(mod, &cls_modules, list) {
87 void register_cls_module(struct cls_module *mod)
89 struct rtnl_cls_ops *ops;
91 if (!(ops = __rtnl_cls_lookup_ops(mod->name)))
92 fatal(ENOENT, "Could not locate classifier module \"%s\"",
95 if (lookup_cls_mod(ops) != NULL)
96 fatal(EEXIST, "Duplicate classifier module registration.");
99 nl_list_add_tail(&mod->list, &cls_modules);
102 void unregister_cls_module(struct cls_module *mod)
104 nl_list_del(&mod->list);