2 * src/nl-neigh-delete.c Delete 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>
16 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
19 static void print_usage(void)
22 "Usage: nl-neigh-delete [OPTION]... [NEIGHBOUR]\n"
25 " -i, --interactive Run interactively\n"
26 " --yes Set default answer to yes\n"
27 " -q, --quiet Do not print informal notifications\n"
28 " -h, --help Show this help\n"
29 " -v, --version Show versioning information\n"
32 " -a, --addr=ADDR Destination address of neighbour\n"
33 " -l, --lladdr=ADDR Link layer address of neighbour\n"
34 " -d, --dev=DEV Device the neighbour is connected to\n"
35 " --family=FAMILY Destination address family\n"
36 " --state=STATE Neighbour state, (default = permanent)\n"
42 static void delete_cb(struct nl_object *obj, void *arg)
44 struct rtnl_neigh *neigh = nl_object_priv(obj);
45 struct nl_dump_params params = {
46 .dp_type = NL_DUMP_LINE,
51 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
54 if ((err = rtnl_neigh_delete(sock, neigh, 0)) < 0)
55 nl_cli_fatal(err, "Unable to delete neighbour: %s\n",
60 nl_object_dump(obj, ¶ms);
66 int main(int argc, char *argv[])
68 struct rtnl_neigh *neigh;
69 struct nl_cache *link_cache, *neigh_cache;
71 sock = nl_cli_alloc_socket();
72 nl_cli_connect(sock, NETLINK_ROUTE);
73 link_cache = nl_cli_link_alloc_cache(sock);
74 neigh_cache = nl_cli_neigh_alloc_cache(sock);
75 neigh = nl_cli_neigh_alloc();
84 static struct option long_opts[] = {
85 { "interactive", 0, 0, 'i' },
86 { "yes", 0, 0, ARG_YES },
87 { "quiet", 0, 0, 'q' },
88 { "help", 0, 0, 'h' },
89 { "version", 0, 0, 'v' },
90 { "addr", 1, 0, 'a' },
91 { "lladdr", 1, 0, 'l' },
93 { "family", 1, 0, ARG_FAMILY },
94 { "state", 1, 0, ARG_STATE },
98 c = getopt_long(argc, argv, "qhva:l:d:", long_opts, &optidx);
103 case 'i': interactive = 1; break;
104 case ARG_YES: default_yes = 1; break;
105 case 'q': quiet = 1; break;
106 case 'h': print_usage(); break;
107 case 'v': nl_cli_print_version(); break;
108 case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break;
109 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
110 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
111 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break;
112 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break;
116 nl_cache_foreach_filter(neigh_cache, OBJ_CAST(neigh), delete_cb, NULL);
119 printf("Deleted %d neighbours\n", deleted);