8#include <linux/netlink.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/neigh.h>
12#include <netlink/cli/link.h>
14static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
15static struct nl_sock *sock;
17static void print_usage(
void)
20 "Usage: nl-neigh-delete [OPTION]... [NEIGHBOUR]\n"
23 " -i, --interactive Run interactively\n"
24 " --yes Set default answer to yes\n"
25 " -q, --quiet Do not print informal notifications\n"
26 " -h, --help Show this help\n"
27 " -v, --version Show versioning information\n"
30 " -a, --addr=ADDR Destination address of neighbour\n"
31 " -l, --lladdr=ADDR Link layer address of neighbour\n"
32 " -d, --dev=DEV Device the neighbour is connected to\n"
33 " --family=FAMILY Destination address family\n"
34 " --state=STATE Neighbour state, (default = permanent)\n"
40static void delete_cb(
struct nl_object *obj,
void *arg)
42 struct rtnl_neigh *neigh = nl_object_priv(obj);
49 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
64int main(
int argc,
char *argv[])
66 struct rtnl_neigh *neigh;
67 struct nl_cache *link_cache, *neigh_cache;
69 sock = nl_cli_alloc_socket();
70 nl_cli_connect(sock, NETLINK_ROUTE);
71 link_cache = nl_cli_link_alloc_cache(sock);
72 neigh_cache = nl_cli_neigh_alloc_cache(sock);
73 neigh = nl_cli_neigh_alloc();
82 static struct option long_opts[] = {
83 {
"interactive", 0, 0,
'i' },
84 {
"yes", 0, 0, ARG_YES },
85 {
"quiet", 0, 0,
'q' },
86 {
"help", 0, 0,
'h' },
87 {
"version", 0, 0,
'v' },
88 {
"addr", 1, 0,
'a' },
89 {
"lladdr", 1, 0,
'l' },
91 {
"family", 1, 0, ARG_FAMILY },
92 {
"state", 1, 0, ARG_STATE },
96 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
101 case 'i': interactive = 1;
break;
102 case ARG_YES: default_yes = 1;
break;
103 case 'q': quiet = 1;
break;
104 case 'h': print_usage();
break;
105 case 'v': nl_cli_print_version();
break;
106 case 'a': nl_cli_neigh_parse_dst(neigh, optarg);
break;
107 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
108 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
109 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg);
break;
110 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
117 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.