libnl: /data/src/libnl3/src/lib/nh.c Source File

libnl 3.10.0

nh.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2022 Stanislav Zaikin <zstaseg@gmail.com>
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
21struct 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
32struct 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
48struct 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
53struct 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
58struct 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/** @} */
nl_cache_mngt_provide
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition cache_mngt.c:332
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition utils.c:71