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