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