libnl: /data/src/libnl3/src/nl-link-enslave.c Source File

libnl 3.7.0

nl-link-enslave.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
12 int main(int argc, char *argv[])
13 {
14 struct nl_sock *sock;
15 struct nl_cache *link_cache;
16 struct rtnl_link *master, *slave;
17 int err;
18
19 if (argc < 3) {
20 fprintf(stderr, "Usage: nl-link-enslave master 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 (!(master = 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 (!(slave = rtnl_link_get_by_name(link_cache, argv[2]))) {
34 fprintf(stderr, "Unknown link: %s\n", argv[2]);
35 return 1;
36 }
37
38 if ((err = rtnl_link_bond_enslave(sock, master, slave)) < 0) {
39 fprintf(stderr, "Unable to enslave %s to %s: %s\n",
40 argv[2], argv[1], nl_geterror(err));
41 return 1;
42 }
43
44 return 0;
45 }
46
rtnl_link_bond_enslave
int rtnl_link_bond_enslave(struct nl_sock *sock, struct rtnl_link *master, struct rtnl_link *slave)
Add a link to a bond (enslave)
Definition: bonding.c:157
rtnl_link_get_by_name
struct rtnl_link * rtnl_link_get_by_name(struct nl_cache *cache, const char *name)
Lookup link in cache by link name.
Definition: link.c:1337
rtnl_link
Link object.