libnl 3.10.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 "nl-default.h"
14
15#include <netlink/cli/utils.h>
16#include <netlink/cli/rule.h>
17
18struct 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
29struct 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
39
40 return cache;
41}
42
43void 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/** @} */
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition cache_mngt.c:332
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:426