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