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

libnl 3.12.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 "nl-default.h"
7
8#include <linux/netlink.h>
9
10#include <netlink/cli/utils.h>
11#include <netlink/cli/link.h>
12#include <netlink/route/link/bonding.h>
13
14int main(int argc, char *argv[])
15{
16 struct nl_sock *sock;
17 struct nl_cache *link_cache;
18 struct rtnl_link *master, *slave;
19 int err;
20
21 if (argc < 3) {
22 fprintf(stderr, "Usage: nl-link-enslave master slave\n");
23 return 1;
24 }
25
26 sock = nl_cli_alloc_socket();
27 nl_cli_connect(sock, NETLINK_ROUTE);
28 link_cache = nl_cli_link_alloc_cache(sock);
29
30 if (!(master = rtnl_link_get_by_name(link_cache, argv[1]))) {
31 fprintf(stderr, "Unknown link: %s\n", argv[1]);
32 return 1;
33 }
34
35 if (!(slave = rtnl_link_get_by_name(link_cache, argv[2]))) {
36 fprintf(stderr, "Unknown link: %s\n", argv[2]);
37 return 1;
38 }
39
40 if ((err = rtnl_link_bond_enslave(sock, master, slave)) < 0) {
41 fprintf(stderr, "Unable to enslave %s to %s: %s\n",
42 argv[2], argv[1], nl_geterror(err));
43 return 1;
44 }
45
46 return 0;
47}
48
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:570
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:1363
rtnl_link
Link object.
Definition nl-route.h:29