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