2 * src/ nl-neigh-add.c Add a neighbour
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/neigh.h>
14 #include <netlink/cli/link.h>
18 static void print_usage(void)
21 "Usage: nl-neigh-add [OPTION]... NEIGHBOUR\n"
24 " --update-only Do not create neighbour, updates exclusively\n"
25 " --create-only Do not update neighbour if it exists already.\n"
26 " -q, --quiet Do not print informal notifications\n"
27 " -h, --help Show this help\n"
28 " -v, --version Show versioning information\n"
31 " -a, --addr=ADDR Destination address of neighbour\n"
32 " -l, --lladdr=ADDR Link layer address of neighbour\n"
33 " -d, --dev=DEV Device the neighbour is connected to\n"
34 " --state=STATE Neighbour state, (default = permanent)\n"
37 " nl-neigh-add --create-only --addr=10.0.0.1 --dev=eth0 \\\n"
38 " --lladdr=AA:BB:CC:DD:EE:FF\n"
44 int main(int argc, char *argv[])
47 struct rtnl_neigh *neigh;
48 struct nl_cache *link_cache;
49 struct nl_dump_params dp = {
50 .dp_type = NL_DUMP_LINE,
53 int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
55 sock = nl_cli_alloc_socket();
56 nl_cli_connect(sock, NETLINK_ROUTE);
57 link_cache = nl_cli_link_alloc_cache(sock);
58 neigh = nl_cli_neigh_alloc();
63 ARG_UPDATE_ONLY = 257,
64 ARG_CREATE_ONLY = 258,
67 static struct option long_opts[] = {
68 { "update-only", 0, 0, ARG_UPDATE_ONLY },
69 { "create-only", 0, 0, ARG_CREATE_ONLY },
70 { "quiet", 0, 0, 'q' },
71 { "help", 0, 0, 'h' },
72 { "version", 0, 0, 'v' },
73 { "addr", 1, 0, 'a' },
74 { "lladdr", 1, 0, 'l' },
76 { "state", 1, 0, ARG_STATE },
80 c = getopt_long(argc, argv, "qhva:l:d:", long_opts, &optidx);
85 case ARG_UPDATE_ONLY: nlflags &= ~NLM_F_CREATE; break;
86 case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL; break;
87 case 'q': quiet = 1; break;
88 case 'h': print_usage(); break;
89 case 'v': nl_cli_print_version(); break;
90 case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg); break;
91 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
92 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
93 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break;
100 if ((err = rtnl_neigh_add(sock, neigh, nlflags)) < 0)
101 nl_cli_fatal(err, "Unable to add neighbour: %s",
106 nl_object_dump(OBJ_CAST(neigh), &dp);