13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/neigh.h> 15 #include <netlink/cli/link.h> 17 #include <linux/netlink.h> 21 static void print_usage(
void)
24 "Usage: nl-neigh-add [OPTION]... NEIGHBOUR\n" 27 " --update-only Do not create neighbour, updates exclusively\n" 28 " --create-only Do not update neighbour if it exists already.\n" 29 " -q, --quiet Do not print informal notifications\n" 30 " -h, --help Show this help\n" 31 " -v, --version Show versioning information\n" 34 " -a, --addr=ADDR Destination address of neighbour\n" 35 " -l, --lladdr=ADDR Link layer address of neighbour\n" 36 " -d, --dev=DEV Device the neighbour is connected to\n" 37 " --state=STATE Neighbour state, (default = permanent)\n" 40 " nl-neigh-add --create-only --addr=10.0.0.1 --dev=eth0 \\\n" 41 " --lladdr=AA:BB:CC:DD:EE:FF\n" 47 int main(
int argc,
char *argv[])
50 struct rtnl_neigh *neigh;
51 struct nl_cache *link_cache;
56 int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
58 sock = nl_cli_alloc_socket();
59 nl_cli_connect(sock, NETLINK_ROUTE);
60 link_cache = nl_cli_link_alloc_cache(sock);
61 neigh = nl_cli_neigh_alloc();
66 ARG_UPDATE_ONLY = 257,
67 ARG_CREATE_ONLY = 258,
70 static struct option long_opts[] = {
71 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
72 {
"create-only", 0, 0, ARG_CREATE_ONLY },
73 {
"quiet", 0, 0,
'q' },
74 {
"help", 0, 0,
'h' },
75 {
"version", 0, 0,
'v' },
76 {
"addr", 1, 0,
'a' },
77 {
"lladdr", 1, 0,
'l' },
79 {
"state", 1, 0, ARG_STATE },
83 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
88 case ARG_UPDATE_ONLY: nlflags &= ~NLM_F_CREATE;
break;
89 case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL;
break;
90 case 'q': quiet = 1;
break;
91 case 'h': print_usage();
break;
92 case 'v': nl_cli_print_version();
break;
93 case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg);
break;
94 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
95 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
96 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.