libnl  3.5.0
nl-link-release.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * src/nl-link-release.c release a link
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation version 2.1
8  * of the License.
9  *
10  * Copyright (c) 2011 Thomas Graf <tgraf@suug.ch>
11  */
12 
13 #include <netlink/cli/utils.h>
14 #include <netlink/cli/link.h>
15 #include <netlink/route/link/bonding.h>
16 
17 #include <linux/netlink.h>
18 
19 int main(int argc, char *argv[])
20 {
21  struct nl_sock *sock;
22  struct nl_cache *link_cache;
23  struct rtnl_link *slave;
24  int err;
25 
26  if (argc < 2) {
27  fprintf(stderr, "Usage: nl-link-release slave\n");
28  return 1;
29  }
30 
31  sock = nl_cli_alloc_socket();
32  nl_cli_connect(sock, NETLINK_ROUTE);
33  link_cache = nl_cli_link_alloc_cache(sock);
34 
35  if (!(slave = rtnl_link_get_by_name(link_cache, argv[1]))) {
36  fprintf(stderr, "Unknown link: %s\n", argv[1]);
37  return 1;
38  }
39 
40  if ((err = rtnl_link_bond_release(sock, slave)) < 0) {
41  fprintf(stderr, "Unable to release slave %s: %s\n",
42  argv[1], nl_geterror(err));
43  return 1;
44  }
45 
46  return 0;
47 }
48 
int rtnl_link_bond_release(struct nl_sock *sock, struct rtnl_link *slave)
Release a link from a bond.
Definition: bonding.c:208