6#include <netlink/cli/utils.h>
7#include <netlink/cli/neigh.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
14static void print_usage(
void)
17 "Usage: nl-neigh-add [OPTION]... NEIGHBOUR\n"
20 " --update-only Do not create neighbour, updates exclusively\n"
21 " --create-only Do not update neighbour if it exists already.\n"
22 " -q, --quiet Do not print informal notifications\n"
23 " -h, --help Show this help\n"
24 " -v, --version Show versioning information\n"
27 " -a, --addr=ADDR Destination address of neighbour\n"
28 " -l, --lladdr=ADDR Link layer address of neighbour\n"
29 " -d, --dev=DEV Device the neighbour is connected to\n"
30 " --state=STATE Neighbour state, (default = permanent)\n"
33 " nl-neigh-add --create-only --addr=10.0.0.1 --dev=eth0 \\\n"
34 " --lladdr=AA:BB:CC:DD:EE:FF\n"
40int main(
int argc,
char *argv[])
43 struct rtnl_neigh *neigh;
44 struct nl_cache *link_cache;
49 int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
51 sock = nl_cli_alloc_socket();
52 nl_cli_connect(sock, NETLINK_ROUTE);
53 link_cache = nl_cli_link_alloc_cache(sock);
54 neigh = nl_cli_neigh_alloc();
59 ARG_UPDATE_ONLY = 257,
60 ARG_CREATE_ONLY = 258,
63 static struct option long_opts[] = {
64 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
65 {
"create-only", 0, 0, ARG_CREATE_ONLY },
66 {
"quiet", 0, 0,
'q' },
67 {
"help", 0, 0,
'h' },
68 {
"version", 0, 0,
'v' },
69 {
"addr", 1, 0,
'a' },
70 {
"lladdr", 1, 0,
'l' },
72 {
"state", 1, 0, ARG_STATE },
76 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
81 case ARG_UPDATE_ONLY: nlflags &= ~NLM_F_CREATE;
break;
82 case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL;
break;
83 case 'q': quiet = 1;
break;
84 case 'h': print_usage();
break;
85 case 'v': nl_cli_print_version();
break;
86 case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg);
break;
87 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
88 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
89 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
Add a new neighbour.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.