1 /* 2 * src/lib/cls.c CLI Classifier Helpers 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation version 2.1 7 * of the License. 8 * 9 * Copyright (c) 2010-2011 Thomas Graf <tgraf (at) suug.ch> 10 */ 11 12 /** 13 * @ingroup cli 14 * @defgroup cli_cls Classifiers 15 * @{ 16 */ 17 18 #include <netlink/cli/utils.h> 19 #include <netlink/cli/cls.h> 20 #include <netlink/route/cls/ematch.h> 21 22 struct rtnl_cls *nl_cli_cls_alloc(void) 23 { 24 struct rtnl_cls *cls; 25 26 if (!(cls = rtnl_cls_alloc())) 27 nl_cli_fatal(ENOMEM, "Unable to allocate classifier object"); 28 29 return cls; 30 } 31 32 struct nl_cache *nl_cli_cls_alloc_cache(struct nl_sock *sock, int ifindex, 33 uint32_t parent) 34 { 35 struct nl_cache *cache; 36 int err; 37 38 if ((err = rtnl_cls_alloc_cache(sock, ifindex, parent, &cache)) < 0) 39 nl_cli_fatal(err, "Unable to allocate classifier cache: %s", 40 nl_geterror(err)); 41 42 return cache; 43 } 44 45 void nl_cli_cls_parse_proto(struct rtnl_cls *cls, char *arg) 46 { 47 int proto; 48 49 if ((proto = nl_str2ether_proto(arg)) < 0) 50 nl_cli_fatal(proto, "Unknown protocol \"%s\".", arg); 51 52 rtnl_cls_set_protocol(cls, proto); 53 } 54 55 struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *cls, char *arg) 56 { 57 struct rtnl_ematch_tree *tree; 58 char *errstr = NULL; 59 int err; 60 61 if ((err = rtnl_ematch_parse_expr(arg, &errstr, &tree)) < 0) 62 nl_cli_fatal(err, "Unable to parse ematch expression: %s", 63 errstr); 64 65 if (errstr) 66 free(errstr); 67 68 return tree; 69 } 70 71 /** @} */ 72