libnl 3.7.0
nl-link-release.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2011 Thomas Graf <tgraf@suug.ch>
4 */
5
6#include <netlink/cli/utils.h>
7#include <netlink/cli/link.h>
8#include <netlink/route/link/bonding.h>
9
10#include <linux/netlink.h>
11
12int main(int argc, char *argv[])
13{
14 struct nl_sock *sock;
15 struct nl_cache *link_cache;
16 struct rtnl_link *slave;
17 int err;
18
19 if (argc < 2) {
20 fprintf(stderr, "Usage: nl-link-release slave\n");
21 return 1;
22 }
23
24 sock = nl_cli_alloc_socket();
25 nl_cli_connect(sock, NETLINK_ROUTE);
26 link_cache = nl_cli_link_alloc_cache(sock);
27
28 if (!(slave = rtnl_link_get_by_name(link_cache, argv[1]))) {
29 fprintf(stderr, "Unknown link: %s\n", argv[1]);
30 return 1;
31 }
32
33 if ((err = rtnl_link_bond_release(sock, slave)) < 0) {
34 fprintf(stderr, "Unable to release slave %s: %s\n",
35 argv[1], nl_geterror(err));
36 return 1;
37 }
38
39 return 0;
40}
41
int rtnl_link_bond_release(struct nl_sock *sock, struct rtnl_link *slave)
Release a link from a bond.
Definition: bonding.c:201