13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/neigh.h> 15 #include <netlink/cli/link.h> 17 #include <linux/netlink.h> 19 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
20 static struct nl_sock *sock;
22 static void print_usage(
void)
25 "Usage: nl-neigh-delete [OPTION]... [NEIGHBOUR]\n" 28 " -i, --interactive Run interactively\n" 29 " --yes Set default answer to yes\n" 30 " -q, --quiet Do not print informal notifications\n" 31 " -h, --help Show this help\n" 32 " -v, --version Show versioning information\n" 35 " -a, --addr=ADDR Destination address of neighbour\n" 36 " -l, --lladdr=ADDR Link layer address of neighbour\n" 37 " -d, --dev=DEV Device the neighbour is connected to\n" 38 " --family=FAMILY Destination address family\n" 39 " --state=STATE Neighbour state, (default = permanent)\n" 45 static void delete_cb(
struct nl_object *obj,
void *arg)
47 struct rtnl_neigh *neigh = nl_object_priv(obj);
54 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
69 int main(
int argc,
char *argv[])
71 struct rtnl_neigh *neigh;
72 struct nl_cache *link_cache, *neigh_cache;
74 sock = nl_cli_alloc_socket();
75 nl_cli_connect(sock, NETLINK_ROUTE);
76 link_cache = nl_cli_link_alloc_cache(sock);
77 neigh_cache = nl_cli_neigh_alloc_cache(sock);
78 neigh = nl_cli_neigh_alloc();
87 static struct option long_opts[] = {
88 {
"interactive", 0, 0,
'i' },
89 {
"yes", 0, 0, ARG_YES },
90 {
"quiet", 0, 0,
'q' },
91 {
"help", 0, 0,
'h' },
92 {
"version", 0, 0,
'v' },
93 {
"addr", 1, 0,
'a' },
94 {
"lladdr", 1, 0,
'l' },
96 {
"family", 1, 0, ARG_FAMILY },
97 {
"state", 1, 0, ARG_STATE },
101 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
106 case 'i': interactive = 1;
break;
107 case ARG_YES: default_yes = 1;
break;
108 case 'q': quiet = 1;
break;
109 case 'h': print_usage();
break;
110 case 'v': nl_cli_print_version();
break;
111 case 'a': nl_cli_neigh_parse_dst(neigh, optarg);
break;
112 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
113 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
114 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg);
break;
115 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
122 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.