00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <netlink/cli/utils.h>
00019 #include <netlink/cli/cls.h>
00020 #include <netlink/route/cls/ematch.h>
00021
00022 struct rtnl_cls *nl_cli_cls_alloc(void)
00023 {
00024 struct rtnl_cls *cls;
00025
00026 if (!(cls = rtnl_cls_alloc()))
00027 nl_cli_fatal(ENOMEM, "Unable to allocate classifier object");
00028
00029 return cls;
00030 }
00031
00032 struct nl_cache *nl_cli_cls_alloc_cache(struct nl_sock *sock, int ifindex,
00033 uint32_t parent)
00034 {
00035 struct nl_cache *cache;
00036 int err;
00037
00038 if ((err = rtnl_cls_alloc_cache(sock, ifindex, parent, &cache)) < 0)
00039 nl_cli_fatal(err, "Unable to allocate classifier cache: %s",
00040 nl_geterror(err));
00041
00042 return cache;
00043 }
00044
00045 void nl_cli_cls_parse_proto(struct rtnl_cls *cls, char *arg)
00046 {
00047 int proto;
00048
00049 if ((proto = nl_str2ether_proto(arg)) < 0)
00050 nl_cli_fatal(proto, "Unknown protocol \"%s\".", arg);
00051
00052 rtnl_cls_set_protocol(cls, proto);
00053 }
00054
00055 struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *cls, char *arg)
00056 {
00057 struct rtnl_ematch_tree *tree;
00058 char *errstr = NULL;
00059 int err;
00060
00061 if ((err = rtnl_ematch_parse_expr(arg, &errstr, &tree)) < 0)
00062 nl_cli_fatal(err, "Unable to parse ematch expression: %s",
00063 errstr);
00064
00065 if (errstr)
00066 free(errstr);
00067
00068 return tree;
00069 }
00070
00071