summaryrefslogtreecommitdiff
path: root/src/lib/nh.c
blob: c1f51374b0a6795e684d5e20ad8717dfa2598f50 (plain)
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
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: LGPL-2.1-only */
/*
 * Copyright (c) 2022 Stanislav Zaikin <zstaseg@gmail.com>
 */

/**
 * @ingroup cli
 * @defgroup cli_nh nhs
 *
 * @{
 */

#include "nl-default.h"

#include <linux/if.h>

#include <netlink/cli/utils.h>
#include <netlink/cli/nh.h>
#include <netlink/route/nh.h>

struct rtnl_nh *nl_cli_nh_alloc(void)
{
	struct rtnl_nh *nh;

	nh = rtnl_nh_alloc();
	if (!nh)
		nl_cli_fatal(ENOMEM, "Unable to allocate nh object");

	return nh;
}

struct nl_cache *nl_cli_nh_alloc_cache_family_flags(struct nl_sock *sock,
						    int family,
						    unsigned int flags)
{
	struct nl_cache *cache;
	int err;

	if ((err = rtnl_nh_alloc_cache(sock, family, &cache)) < 0)
		nl_cli_fatal(err, "Unable to allocate nh cache: %s",
			     nl_geterror(err));

	nl_cache_mngt_provide(cache);

	return cache;
}

struct nl_cache *nl_cli_nh_alloc_cache_family(struct nl_sock *sock, int family)
{
	return nl_cli_nh_alloc_cache_family_flags(sock, family, 0);
}

struct nl_cache *nl_cli_nh_alloc_cache(struct nl_sock *sock)
{
	return nl_cli_nh_alloc_cache_family(sock, AF_UNSPEC);
}

struct nl_cache *nl_cli_nh_alloc_cache_flags(struct nl_sock *sock,
					     unsigned int flags)
{
	return nl_cli_nh_alloc_cache_family_flags(sock, AF_UNSPEC, flags);
}

/** @} */