libnl 3.5.0

rule.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * src/lib/rule.c CLI Routing Rule Helpers
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
11 */
12
13 /**
14 * @ingroup cli
15 * @defgroup cli_rule Routing Rules
16 *
17 * @{
18 */
19
20 #include <netlink/cli/utils.h>
21 #include <netlink/cli/rule.h>
22
23 struct rtnl_rule *nl_cli_rule_alloc(void)
24 {
25 struct rtnl_rule *rule;
26
27 rule = rtnl_rule_alloc();
28 if (!rule)
29 nl_cli_fatal(ENOMEM, "Unable to allocate rule object");
30
31 return rule;
32 }
33
34 struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk)
35 {
36 struct nl_cache *cache;
37 int err;
38
39 if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0)
40 nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n",
41 nl_geterror(err));
42
43 nl_cache_mngt_provide(cache);
44
45 return cache;
46 }
47
48 void nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg)
49 {
50 int family;
51
52 if ((family = nl_str2af(arg)) != AF_UNSPEC)
53 rtnl_rule_set_family(rule, family);
54 }
55
56 /** @} */
rtnl_rule_alloc_cache
int rtnl_rule_alloc_cache(struct nl_sock *sock, int family, struct nl_cache **result)
Build a rule cache including all rules currently configured in the kernel.
Definition: rule.c:403
nl_cache_mngt_provide
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition: cache_mngt.c:333
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:78