libnl 3.7.0
team.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2015 Jonas Johansson <jonasj76@gmail.com>
4 */
5
6/**
7 * @ingroup link
8 * @defgroup team Team
9 *
10 * @details
11 * \b Link Type Name: "team"
12 *
13 * @route_doc{link_team, Team Documentation}
14 * @{
15 */
16
17#include <netlink-private/netlink.h>
18#include <netlink/netlink.h>
19#include <netlink-private/route/link/api.h>
20#include <netlink/route/link/team.h>
21
22/**
23 * Allocate link object of type team
24 *
25 * @return Allocated link object or NULL.
26 */
28{
29 struct rtnl_link *link;
30
31 if (!(link = rtnl_link_alloc()))
32 return NULL;
33
34 if (rtnl_link_set_type(link, "team") < 0) {
35 rtnl_link_put(link);
36 return NULL;
37 }
38
39 return link;
40}
41
42/**
43 * Create a new kernel team device
44 * @arg sock netlink socket
45 * @arg name name of team device or NULL
46 * @arg opts team options (currently unused)
47 *
48 * Creates a new team device in the kernel. If no name is
49 * provided, the kernel will automatically pick a name of the
50 * form "type%d" (e.g. team0, vlan1, etc.)
51 *
52 * The \a opts argument is currently unused. In the future, it
53 * may be used to carry additional team options to be set
54 * when creating the team device.
55 *
56 * @note When letting the kernel assign a name, it will become
57 * difficult to retrieve the interface afterwards because
58 * you have to guess the name the kernel has chosen. It is
59 * therefore not recommended to not provide a device name.
60 *
61 * @see rtnl_link_team_enslave()
62 * @see rtnl_link_team_release()
63 *
64 * @return 0 on success or a negative error code
65 */
66int rtnl_link_team_add(struct nl_sock *sock, const char *name,
67 struct rtnl_link *opts)
68{
69 struct rtnl_link *link;
70 int err;
71
72 if (!(link = rtnl_link_team_alloc()))
73 return -NLE_NOMEM;
74
75 if (!name && opts)
76 name = rtnl_link_get_name(opts);
77
78 if (name)
79 rtnl_link_set_name(link, name);
80
81 err = rtnl_link_add(sock, link, NLM_F_CREATE);
82
83 rtnl_link_put(link);
84
85 return err;
86}
87
88static struct rtnl_link_info_ops team_info_ops = {
89 .io_name = "team",
90};
91
92static void __init team_init(void)
93{
94 rtnl_link_register_info(&team_info_ops);
95}
96
97static void __exit team_exit(void)
98{
99 rtnl_link_unregister_info(&team_info_ops);
100}
101
102/** @} */
struct rtnl_link * rtnl_link_team_alloc(void)
Allocate link object of type team.
Definition: team.c:27
int rtnl_link_team_add(struct nl_sock *sock, const char *name, struct rtnl_link *opts)
Create a new kernel team device.
Definition: team.c:66