12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/neigh.h> 14 #include <netlink/cli/link.h> 16 #include <linux/netlink.h> 18 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
19 static struct nl_sock *sock;
21 static void print_usage(
void)
24 "Usage: nl-neigh-delete [OPTION]... [NEIGHBOUR]\n" 27 " -i, --interactive Run interactively\n" 28 " --yes Set default answer to yes\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 " --family=FAMILY Destination address family\n" 38 " --state=STATE Neighbour state, (default = permanent)\n" 44 static void delete_cb(
struct nl_object *obj,
void *arg)
46 struct rtnl_neigh *neigh = nl_object_priv(obj);
53 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
68 int main(
int argc,
char *argv[])
70 struct rtnl_neigh *neigh;
71 struct nl_cache *link_cache, *neigh_cache;
73 sock = nl_cli_alloc_socket();
74 nl_cli_connect(sock, NETLINK_ROUTE);
75 link_cache = nl_cli_link_alloc_cache(sock);
76 neigh_cache = nl_cli_neigh_alloc_cache(sock);
77 neigh = nl_cli_neigh_alloc();
86 static struct option long_opts[] = {
87 {
"interactive", 0, 0,
'i' },
88 {
"yes", 0, 0, ARG_YES },
89 {
"quiet", 0, 0,
'q' },
90 {
"help", 0, 0,
'h' },
91 {
"version", 0, 0,
'v' },
92 {
"addr", 1, 0,
'a' },
93 {
"lladdr", 1, 0,
'l' },
95 {
"family", 1, 0, ARG_FAMILY },
96 {
"state", 1, 0, ARG_STATE },
100 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
105 case 'i': interactive = 1;
break;
106 case ARG_YES: default_yes = 1;
break;
107 case 'q': quiet = 1;
break;
108 case 'h': print_usage();
break;
109 case 'v': nl_cli_print_version();
break;
110 case 'a': nl_cli_neigh_parse_dst(neigh, optarg);
break;
111 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
112 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
113 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg);
break;
114 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
121 printf(
"Deleted %d neighbours\n", deleted);
Dump object briefly on one line.
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
Delete a neighbour.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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_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.