libnl 3.7.0
rule.c
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
16struct 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
27struct 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
37
38 return cache;
39}
40
41void 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/** @} */
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition: cache_mngt.c:326
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:71
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:399