File: rule.c

package info (click to toggle)
libnl3 3.4.0-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,120 kB
  • sloc: ansic: 57,494; sh: 4,447; python: 3,702; makefile: 888; yacc: 478; cpp: 454; lex: 210
file content (55 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * src/lib/rule.c     CLI Routing Rule Helpers
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
 */

/**
 * @ingroup cli
 * @defgroup cli_rule Routing Rules
 *
 * @{
 */

#include <netlink/cli/utils.h>
#include <netlink/cli/rule.h>

struct rtnl_rule *nl_cli_rule_alloc(void)
{
	struct rtnl_rule *rule;

	rule = rtnl_rule_alloc();
	if (!rule)
		nl_cli_fatal(ENOMEM, "Unable to allocate rule object");

	return rule;
}

struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk)
{
	struct nl_cache *cache;
	int err;

	if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0)
		nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n",
			     nl_geterror(err));

	nl_cache_mngt_provide(cache);

	return cache;
}

void nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg)
{
	int family;

	if ((family = nl_str2af(arg)) != AF_UNSPEC)
		rtnl_rule_set_family(rule, family);
}

/** @} */