1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2022 Stanislav Zaikin <[email protected]>
4 */
5
6 /**
7 * @ingroup cli
8 * @defgroup cli_nh nhs
9 *
10 * @{
11 */
12
13 #include "nl-default.h"
14
15 #include <linux/if.h>
16
17 #include <netlink/cli/utils.h>
18 #include <netlink/cli/nh.h>
19 #include <netlink/route/nh.h>
20
nl_cli_nh_alloc(void)21 struct rtnl_nh *nl_cli_nh_alloc(void)
22 {
23 struct rtnl_nh *nh;
24
25 nh = rtnl_nh_alloc();
26 if (!nh)
27 nl_cli_fatal(ENOMEM, "Unable to allocate nh object");
28
29 return nh;
30 }
31
nl_cli_nh_alloc_cache_family_flags(struct nl_sock * sock,int family,unsigned int flags)32 struct nl_cache *nl_cli_nh_alloc_cache_family_flags(struct nl_sock *sock,
33 int family,
34 unsigned int flags)
35 {
36 struct nl_cache *cache;
37 int err;
38
39 if ((err = rtnl_nh_alloc_cache(sock, family, &cache)) < 0)
40 nl_cli_fatal(err, "Unable to allocate nh cache: %s",
41 nl_geterror(err));
42
43 nl_cache_mngt_provide(cache);
44
45 return cache;
46 }
47
nl_cli_nh_alloc_cache_family(struct nl_sock * sock,int family)48 struct nl_cache *nl_cli_nh_alloc_cache_family(struct nl_sock *sock, int family)
49 {
50 return nl_cli_nh_alloc_cache_family_flags(sock, family, 0);
51 }
52
nl_cli_nh_alloc_cache(struct nl_sock * sock)53 struct nl_cache *nl_cli_nh_alloc_cache(struct nl_sock *sock)
54 {
55 return nl_cli_nh_alloc_cache_family(sock, AF_UNSPEC);
56 }
57
nl_cli_nh_alloc_cache_flags(struct nl_sock * sock,unsigned int flags)58 struct nl_cache *nl_cli_nh_alloc_cache_flags(struct nl_sock *sock,
59 unsigned int flags)
60 {
61 return nl_cli_nh_alloc_cache_family_flags(sock, AF_UNSPEC, flags);
62 }
63
64 /** @} */
65