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