]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev.h
networkd: add bridge properties
[thirdparty/systemd.git] / src / network / networkd-netdev.h
CommitLineData
3be1d7e0
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#pragma once
23
3be1d7e0 24#include "list.h"
3be1d7e0 25
fc2f9534 26typedef struct NetDev NetDev;
3be1d7e0
TG
27typedef struct NetDevVTable NetDevVTable;
28
fc2f9534
LP
29#include "networkd.h"
30#include "networkd-link.h"
31
3be1d7e0
TG
32typedef struct netdev_join_callback netdev_join_callback;
33
34struct netdev_join_callback {
1c4baffc 35 sd_netlink_message_handler_t callback;
3be1d7e0
TG
36 Link *link;
37
38 LIST_FIELDS(netdev_join_callback, callbacks);
39};
40
41typedef enum NetDevKind {
42 NETDEV_KIND_BRIDGE,
43 NETDEV_KIND_BOND,
44 NETDEV_KIND_VLAN,
45 NETDEV_KIND_MACVLAN,
f33ff02b 46 NETDEV_KIND_MACVTAP,
c4a5ddc9 47 NETDEV_KIND_IPVLAN,
3be1d7e0
TG
48 NETDEV_KIND_VXLAN,
49 NETDEV_KIND_IPIP,
50 NETDEV_KIND_GRE,
1af2536a 51 NETDEV_KIND_GRETAP,
b16492f8
SS
52 NETDEV_KIND_IP6GRE,
53 NETDEV_KIND_IP6GRETAP,
3be1d7e0
TG
54 NETDEV_KIND_SIT,
55 NETDEV_KIND_VETH,
56 NETDEV_KIND_VTI,
9011ce77 57 NETDEV_KIND_VTI6,
855ee1a1 58 NETDEV_KIND_IP6TNL,
3be1d7e0
TG
59 NETDEV_KIND_DUMMY,
60 NETDEV_KIND_TUN,
61 NETDEV_KIND_TAP,
62 _NETDEV_KIND_MAX,
63 _NETDEV_KIND_INVALID = -1
64} NetDevKind;
65
66typedef enum NetDevState {
67 NETDEV_STATE_FAILED,
68 NETDEV_STATE_CREATING,
69 NETDEV_STATE_READY,
70 NETDEV_STATE_LINGER,
71 _NETDEV_STATE_MAX,
72 _NETDEV_STATE_INVALID = -1,
73} NetDevState;
74
aa9f1140
TG
75typedef enum NetDevCreateType {
76 NETDEV_CREATE_INDEPENDENT,
77 NETDEV_CREATE_MASTER,
78 NETDEV_CREATE_STACKED,
79 _NETDEV_CREATE_MAX,
80 _NETDEV_CREATE_INVALID = -1,
81} NetDevCreateType;
82
3be1d7e0
TG
83struct NetDev {
84 Manager *manager;
85
86 int n_ref;
87
88 char *filename;
89
90 Condition *match_host;
91 Condition *match_virt;
92 Condition *match_kernel;
93 Condition *match_arch;
94
aa9f1140
TG
95 NetDevState state;
96 NetDevKind kind;
3be1d7e0
TG
97 char *description;
98 char *ifname;
3be1d7e0 99 struct ether_addr *mac;
aa9f1140 100 size_t mtu;
3be1d7e0 101 int ifindex;
3be1d7e0
TG
102
103 LIST_HEAD(netdev_join_callback, callbacks);
104};
105
aa9f1140
TG
106#include "networkd-netdev-bridge.h"
107#include "networkd-netdev-bond.h"
108#include "networkd-netdev-vlan.h"
109#include "networkd-netdev-macvlan.h"
c4a5ddc9 110#include "networkd-netdev-ipvlan.h"
aa9f1140
TG
111#include "networkd-netdev-vxlan.h"
112#include "networkd-netdev-veth.h"
113#include "networkd-netdev-tunnel.h"
114#include "networkd-netdev-dummy.h"
115#include "networkd-netdev-tuntap.h"
116
3be1d7e0 117struct NetDevVTable {
aa9f1140
TG
118 /* How much memory does an object of this unit type need */
119 size_t object_size;
120
121 /* Config file sections this netdev kind understands, separated
122 * by NUL chars */
123 const char *sections;
3be1d7e0 124
aa9f1140
TG
125 /* This should reset all type-specific variables. This should
126 * not allocate memory, and is called with zero-initialized
127 * data. It should hence only initialize variables that need
128 * to be set != 0. */
129 void (*init)(NetDev *n);
3be1d7e0 130
aa9f1140
TG
131 /* This should free all kind-specific variables. It should be
132 * idempotent. */
133 void (*done)(NetDev *n);
134
135 /* fill in message to create netdev */
1c4baffc 136 int (*fill_message_create)(NetDev *netdev, Link *link, sd_netlink_message *message);
aa9f1140
TG
137
138 /* specifies if netdev is independent, or a master device or a stacked device */
139 NetDevCreateType create_type;
3be1d7e0
TG
140
141 /* create netdev, if not done via rtnl */
142 int (*create)(NetDev *netdev);
143
540eb5f0
SS
144 /* perform additional configuration after netdev has been createad */
145 int (*post_create)(NetDev *netdev, Link *link, sd_netlink_message *message);
146
3be1d7e0
TG
147 /* verify that compulsory configuration options were specified */
148 int (*config_verify)(NetDev *netdev, const char *filename);
149};
150
151extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
152
153#define NETDEV_VTABLE(n) netdev_vtable[(n)->kind]
154
aa9f1140
TG
155/* For casting a netdev into the various netdev kinds */
156#define DEFINE_CAST(UPPERCASE, MixedCase) \
157 static inline MixedCase* UPPERCASE(NetDev *n) { \
158 if (_unlikely_(!n || n->kind != NETDEV_KIND_##UPPERCASE)) \
159 return NULL; \
160 \
161 return (MixedCase*) n; \
162 }
163
164/* For casting the various netdev kinds into a netdev */
165#define NETDEV(n) (&(n)->meta)
166
167DEFINE_CAST(BRIDGE, Bridge);
168DEFINE_CAST(BOND, Bond);
169DEFINE_CAST(VLAN, VLan);
170DEFINE_CAST(MACVLAN, MacVlan);
f33ff02b 171DEFINE_CAST(MACVTAP, MacVlan);
c4a5ddc9 172DEFINE_CAST(IPVLAN, IPVlan);
aa9f1140
TG
173DEFINE_CAST(VXLAN, VxLan);
174DEFINE_CAST(IPIP, Tunnel);
175DEFINE_CAST(GRE, Tunnel);
1af2536a 176DEFINE_CAST(GRETAP, Tunnel);
b16492f8
SS
177DEFINE_CAST(IP6GRE, Tunnel);
178DEFINE_CAST(IP6GRETAP, Tunnel);
aa9f1140
TG
179DEFINE_CAST(SIT, Tunnel);
180DEFINE_CAST(VTI, Tunnel);
9011ce77 181DEFINE_CAST(VTI6, Tunnel);
855ee1a1 182DEFINE_CAST(IP6TNL, Tunnel);
aa9f1140
TG
183DEFINE_CAST(VETH, Veth);
184DEFINE_CAST(DUMMY, Dummy);
185DEFINE_CAST(TUN, TunTap);
186DEFINE_CAST(TAP, TunTap);
187
3be1d7e0
TG
188int netdev_load(Manager *manager);
189void netdev_drop(NetDev *netdev);
190
191NetDev *netdev_unref(NetDev *netdev);
192NetDev *netdev_ref(NetDev *netdev);
193
194DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
195#define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp)
196
197int netdev_get(Manager *manager, const char *name, NetDev **ret);
1c4baffc
TG
198int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *newlink);
199int netdev_enslave(NetDev *netdev, Link *link, sd_netlink_message_handler_t callback);
3be1d7e0 200int netdev_get_mac(const char *ifname, struct ether_addr **ret);
1c4baffc 201int netdev_join(NetDev *netdev, Link *link, sd_netlink_message_handler_t cb);
3be1d7e0
TG
202
203const char *netdev_kind_to_string(NetDevKind d) _const_;
204NetDevKind netdev_kind_from_string(const char *d) _pure_;
205
206int config_parse_netdev_kind(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
207
208/* gperf */
209const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length);
210
211/* Macros which append INTERFACE= to the message */
212
f2341e0a
LP
213#define log_netdev_full(netdev, level, error, ...) \
214 ({ \
215 NetDev *_n = (netdev); \
216 _n ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _n->ifname, ##__VA_ARGS__) : \
217 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
218 })
6a7a4e4d
LP
219
220#define log_netdev_debug(netdev, ...) log_netdev_full(netdev, LOG_DEBUG, 0, ##__VA_ARGS__)
221#define log_netdev_info(netdev, ...) log_netdev_full(netdev, LOG_INFO, 0, ##__VA_ARGS__)
222#define log_netdev_notice(netdev, ...) log_netdev_full(netdev, LOG_NOTICE, 0, ##__VA_ARGS__)
223#define log_netdev_warning(netdev, ...) log_netdev_full(netdev, LOG_WARNING, 0, ## __VA_ARGS__)
224#define log_netdev_error(netdev, ...) log_netdev_full(netdev, LOG_ERR, 0, ##__VA_ARGS__)
225
226#define log_netdev_debug_errno(netdev, error, ...) log_netdev_full(netdev, LOG_DEBUG, error, ##__VA_ARGS__)
227#define log_netdev_info_errno(netdev, error, ...) log_netdev_full(netdev, LOG_INFO, error, ##__VA_ARGS__)
228#define log_netdev_notice_errno(netdev, error, ...) log_netdev_full(netdev, LOG_NOTICE, error, ##__VA_ARGS__)
229#define log_netdev_warning_errno(netdev, error, ...) log_netdev_full(netdev, LOG_WARNING, error, ##__VA_ARGS__)
230#define log_netdev_error_errno(netdev, error, ...) log_netdev_full(netdev, LOG_ERR, error, ##__VA_ARGS__)
98b32556 231
f2341e0a
LP
232#define LOG_NETDEV_MESSAGE(netdev, fmt, ...) "MESSAGE=%s: " fmt, (netdev)->ifname, ##__VA_ARGS__
233#define LOG_NETDEV_INTERFACE(netdev) "INTERFACE=%s", (netdev)->ifname