• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * src/nl-link-enslave.c     Enslave 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 
main(int argc,char * argv[])19 int main(int argc, char *argv[])
20 {
21 	struct nl_sock *sock;
22 	struct nl_cache *link_cache;
23 	struct rtnl_link *master, *slave;
24 	int err;
25 
26 	if (argc < 3) {
27 		fprintf(stderr, "Usage: nl-link-enslave master 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 (!(master = 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 (!(slave = rtnl_link_get_by_name(link_cache, argv[2]))) {
41 		fprintf(stderr, "Unknown link: %s\n", argv[2]);
42 		return 1;
43 	}
44 
45 	if ((err = rtnl_link_bond_enslave(sock, master, slave)) < 0) {
46 		fprintf(stderr, "Unable to enslave %s to %s: %s\n",
47 			argv[2], argv[1], nl_geterror(err));
48 		return 1;
49 	}
50 
51 	return 0;
52 }
53 
54