• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
4  */
5 
6 /**
7  * @ingroup cli
8  * @defgroup cli_rule Routing Rules
9  *
10  * @{
11  */
12 
13 #include <netlink/cli/utils.h>
14 #include <netlink/cli/rule.h>
15 
nl_cli_rule_alloc(void)16 struct rtnl_rule *nl_cli_rule_alloc(void)
17 {
18 	struct rtnl_rule *rule;
19 
20 	rule = rtnl_rule_alloc();
21 	if (!rule)
22 		nl_cli_fatal(ENOMEM, "Unable to allocate rule object");
23 
24 	return rule;
25 }
26 
nl_cli_rule_alloc_cache(struct nl_sock * sk)27 struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk)
28 {
29 	struct nl_cache *cache;
30 	int err;
31 
32 	if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0)
33 		nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n",
34 			     nl_geterror(err));
35 
36 	nl_cache_mngt_provide(cache);
37 
38 	return cache;
39 }
40 
nl_cli_rule_parse_family(struct rtnl_rule * rule,char * arg)41 void nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg)
42 {
43 	int family;
44 
45 	if ((family = nl_str2af(arg)) != AF_UNSPEC)
46 		rtnl_rule_set_family(rule, family);
47 }
48 
49 /** @} */
50