6#include <netlink/cli/utils.h>
7#include <netlink/cli/neigh.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
12static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
13static struct nl_sock *sock;
15static void print_usage(
void)
18 "Usage: nl-neigh-delete [OPTION]... [NEIGHBOUR]\n"
21 " -i, --interactive Run interactively\n"
22 " --yes Set default answer to yes\n"
23 " -q, --quiet Do not print informal notifications\n"
24 " -h, --help Show this help\n"
25 " -v, --version Show versioning information\n"
28 " -a, --addr=ADDR Destination address of neighbour\n"
29 " -l, --lladdr=ADDR Link layer address of neighbour\n"
30 " -d, --dev=DEV Device the neighbour is connected to\n"
31 " --family=FAMILY Destination address family\n"
32 " --state=STATE Neighbour state, (default = permanent)\n"
38static void delete_cb(
struct nl_object *obj,
void *arg)
40 struct rtnl_neigh *neigh = nl_object_priv(obj);
47 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
62int main(
int argc,
char *argv[])
64 struct rtnl_neigh *neigh;
65 struct nl_cache *link_cache, *neigh_cache;
67 sock = nl_cli_alloc_socket();
68 nl_cli_connect(sock, NETLINK_ROUTE);
69 link_cache = nl_cli_link_alloc_cache(sock);
70 neigh_cache = nl_cli_neigh_alloc_cache(sock);
71 neigh = nl_cli_neigh_alloc();
80 static struct option long_opts[] = {
81 {
"interactive", 0, 0,
'i' },
82 {
"yes", 0, 0, ARG_YES },
83 {
"quiet", 0, 0,
'q' },
84 {
"help", 0, 0,
'h' },
85 {
"version", 0, 0,
'v' },
86 {
"addr", 1, 0,
'a' },
87 {
"lladdr", 1, 0,
'l' },
89 {
"family", 1, 0, ARG_FAMILY },
90 {
"state", 1, 0, ARG_STATE },
94 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
99 case 'i': interactive = 1;
break;
100 case ARG_YES: default_yes = 1;
break;
101 case 'q': quiet = 1;
break;
102 case 'h': print_usage();
break;
103 case 'v': nl_cli_print_version();
break;
104 case 'a': nl_cli_neigh_parse_dst(neigh, optarg);
break;
105 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
106 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
107 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg);
break;
108 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
115 printf(
"Deleted %d neighbours\n", deleted);
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
Delete a 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.