|
Packit Service |
f991dd |
/* SPDX-License-Identifier: LGPL-2.1-only */
|
|
Packit Service |
f991dd |
/*
|
|
Packit Service |
f991dd |
* src/ nl-neigh-add.c Add a neighbour
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
f991dd |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
f991dd |
* License as published by the Free Software Foundation version 2.1
|
|
Packit Service |
f991dd |
* of the License.
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
|
|
Packit Service |
f991dd |
*/
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <netlink/cli/utils.h>
|
|
Packit Service |
f991dd |
#include <netlink/cli/neigh.h>
|
|
Packit Service |
f991dd |
#include <netlink/cli/link.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <linux/netlink.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
static int quiet = 0;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
static void print_usage(void)
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
printf(
|
|
Packit Service |
f991dd |
"Usage: nl-neigh-add [OPTION]... NEIGHBOUR\n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
"Options\n"
|
|
Packit Service |
f991dd |
" --update-only Do not create neighbour, updates exclusively\n"
|
|
Packit Service |
f991dd |
" --create-only Do not update neighbour if it exists already.\n"
|
|
Packit Service |
f991dd |
" -q, --quiet Do not print informal notifications\n"
|
|
Packit Service |
f991dd |
" -h, --help Show this help\n"
|
|
Packit Service |
f991dd |
" -v, --version Show versioning information\n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
"Neighbour Options\n"
|
|
Packit Service |
f991dd |
" -a, --addr=ADDR Destination address of neighbour\n"
|
|
Packit Service |
f991dd |
" -l, --lladdr=ADDR Link layer address of neighbour\n"
|
|
Packit Service |
f991dd |
" -d, --dev=DEV Device the neighbour is connected to\n"
|
|
Packit Service |
f991dd |
" --state=STATE Neighbour state, (default = permanent)\n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
"Example\n"
|
|
Packit Service |
f991dd |
" nl-neigh-add --create-only --addr=10.0.0.1 --dev=eth0 \\\n"
|
|
Packit Service |
f991dd |
" --lladdr=AA:BB:CC:DD:EE:FF\n"
|
|
Packit Service |
f991dd |
);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
exit(0);
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
int main(int argc, char *argv[])
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
struct nl_sock *sock;
|
|
Packit Service |
f991dd |
struct rtnl_neigh *neigh;
|
|
Packit Service |
f991dd |
struct nl_cache *link_cache;
|
|
Packit Service |
f991dd |
struct nl_dump_params dp = {
|
|
Packit Service |
f991dd |
.dp_type = NL_DUMP_LINE,
|
|
Packit Service |
f991dd |
.dp_fd = stdout,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
sock = nl_cli_alloc_socket();
|
|
Packit Service |
f991dd |
nl_cli_connect(sock, NETLINK_ROUTE);
|
|
Packit Service |
f991dd |
link_cache = nl_cli_link_alloc_cache(sock);
|
|
Packit Service |
f991dd |
neigh = nl_cli_neigh_alloc();
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
for (;;) {
|
|
Packit Service |
f991dd |
int c, optidx = 0;
|
|
Packit Service |
f991dd |
enum {
|
|
Packit Service |
f991dd |
ARG_UPDATE_ONLY = 257,
|
|
Packit Service |
f991dd |
ARG_CREATE_ONLY = 258,
|
|
Packit Service |
f991dd |
ARG_STATE,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
static struct option long_opts[] = {
|
|
Packit Service |
f991dd |
{ "update-only", 0, 0, ARG_UPDATE_ONLY },
|
|
Packit Service |
f991dd |
{ "create-only", 0, 0, ARG_CREATE_ONLY },
|
|
Packit Service |
f991dd |
{ "quiet", 0, 0, 'q' },
|
|
Packit Service |
f991dd |
{ "help", 0, 0, 'h' },
|
|
Packit Service |
f991dd |
{ "version", 0, 0, 'v' },
|
|
Packit Service |
f991dd |
{ "addr", 1, 0, 'a' },
|
|
Packit Service |
f991dd |
{ "lladdr", 1, 0, 'l' },
|
|
Packit Service |
f991dd |
{ "dev", 1, 0, 'd' },
|
|
Packit Service |
f991dd |
{ "state", 1, 0, ARG_STATE },
|
|
Packit Service |
f991dd |
{ 0, 0, 0, 0 }
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
c = getopt_long(argc, argv, "qhva:l:d:", long_opts, &optidx);
|
|
Packit Service |
f991dd |
if (c == -1)
|
|
Packit Service |
f991dd |
break;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
switch (c) {
|
|
Packit Service |
f991dd |
case ARG_UPDATE_ONLY: nlflags &= ~NLM_F_CREATE; break;
|
|
Packit Service |
f991dd |
case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL; break;
|
|
Packit Service |
f991dd |
case 'q': quiet = 1; break;
|
|
Packit Service |
f991dd |
case 'h': print_usage(); break;
|
|
Packit Service |
f991dd |
case 'v': nl_cli_print_version(); break;
|
|
Packit Service |
f991dd |
case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg); break;
|
|
Packit Service |
f991dd |
case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
|
|
Packit Service |
f991dd |
case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
|
|
Packit Service |
f991dd |
case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break;
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if (!ok)
|
|
Packit Service |
f991dd |
print_usage();
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if ((err = rtnl_neigh_add(sock, neigh, nlflags)) < 0)
|
|
Packit Service |
f991dd |
nl_cli_fatal(err, "Unable to add neighbour: %s",
|
|
Packit Service |
f991dd |
nl_geterror(err));
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if (!quiet) {
|
|
Packit Service |
f991dd |
printf("Added ");
|
|
Packit Service |
f991dd |
nl_object_dump(OBJ_CAST(neigh), &dp;;
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
return 0;
|
|
Packit Service |
f991dd |
}
|