libnl: /data/src/libnl3/lib/route/link/team.c Source File

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 */
27 struct rtnl_link *rtnl_link_team_alloc(void)
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 */
66 int 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
88 static struct rtnl_link_info_ops team_info_ops = {
89 .io_name = "team",
90 };
91
92 static void __init team_init(void)
93 {
94 rtnl_link_register_info(&team_info_ops);
95 }
96
97 static void __exit team_exit(void)
98 {
99 rtnl_link_unregister_info(&team_info_ops);
100 }
101
102 /** @} */
rtnl_link_register_info
int rtnl_link_register_info(struct rtnl_link_info_ops *ops)
Register operations for a link info type.
Definition: api.c:124
rtnl_link_unregister_info
int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops)
Unregister operations for a link info type.
Definition: api.c:159
rtnl_link_add
int rtnl_link_add(struct nl_sock *sk, struct rtnl_link *link, int flags)
Add virtual link.
Definition: link.c:1684
rtnl_link_get_name
char * rtnl_link_get_name(struct rtnl_link *link)
Return name of link object.
Definition: link.c:1952
rtnl_link_set_name
void rtnl_link_set_name(struct rtnl_link *link, const char *name)
Set name of link object.
Definition: link.c:1938
rtnl_link_put
void rtnl_link_put(struct rtnl_link *link)
Return a link object reference.
Definition: link.c:1919
rtnl_link_set_type
int rtnl_link_set_type(struct rtnl_link *link, const char *type)
Set type of link object.
Definition: link.c:2548
rtnl_link_alloc
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
Definition: link.c:1910
rtnl_link_team_alloc
struct rtnl_link * rtnl_link_team_alloc(void)
Allocate link object of type team.
Definition: team.c:27
rtnl_link_team_add
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
rtnl_link
Link object.