libnl 3.11.0
neigh.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
4 */
5
6/**
7 * @ingroup cli
8 * @defgroup cli_neigh Neighbour
9 *
10 * @{
11 */
12
13#include "nl-default.h"
14
15#include <netlink/cli/utils.h>
16#include <netlink/cli/neigh.h>
17
18struct rtnl_neigh *nl_cli_neigh_alloc(void)
19{
20 struct rtnl_neigh *neigh;
21
22 neigh = rtnl_neigh_alloc();
23 if (!neigh)
24 nl_cli_fatal(ENOMEM, "Unable to allocate neighbour object");
25
26 return neigh;
27}
28
29void nl_cli_neigh_parse_dst(struct rtnl_neigh *neigh, char *arg)
30{
31 struct nl_addr *a;
32 int err;
33
34 a = nl_cli_addr_parse(arg, rtnl_neigh_get_family(neigh));
35 if ((err = rtnl_neigh_set_dst(neigh, a)) < 0)
36 nl_cli_fatal(err, "Unable to set local address: %s",
37 nl_geterror(err));
38
39 nl_addr_put(a);
40}
41
42void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *neigh, char *arg)
43{
44 struct nl_addr *a;
45
46 a = nl_cli_addr_parse(arg, AF_UNSPEC);
47 rtnl_neigh_set_lladdr(neigh, a);
48 nl_addr_put(a);
49}
50
51void nl_cli_neigh_parse_dev(struct rtnl_neigh *neigh,
52 struct nl_cache *link_cache, char *arg)
53{
54 int ival;
55
56 if (!(ival = rtnl_link_name2i(link_cache, arg)))
57 nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
58
59 rtnl_neigh_set_ifindex(neigh, ival);
60}
61
62void nl_cli_neigh_parse_family(struct rtnl_neigh *neigh, char *arg)
63{
64 int family;
65
66 if ((family = nl_str2af(arg)) == AF_UNSPEC)
67 nl_cli_fatal(EINVAL,
68 "Unable to translate address family \"%s\"", arg);
69
70 rtnl_neigh_set_family(neigh, family);
71}
72
73void nl_cli_neigh_parse_state(struct rtnl_neigh *neigh, char *arg)
74{
75 int state;
76
77 if ((state = rtnl_neigh_str2state(arg)) < 0)
78 nl_cli_fatal(state, "Unable to translate state \"%s\": %s",
79 arg, state);
80
81 rtnl_neigh_set_state(neigh, state);
82}
83
84/** @} */
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
Definition addr.c:541
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition utils.c:71