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