]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev.h
log: rearrange log function naming
[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
24#include "networkd.h"
25#include "hashmap.h"
26#include "list.h"
27#include "set.h"
3be1d7e0
TG
28#include "in-addr-util.h"
29
30typedef struct NetDevVTable NetDevVTable;
31
32typedef struct netdev_join_callback netdev_join_callback;
33
34struct netdev_join_callback {
35 sd_rtnl_message_handler_t callback;
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,
46 NETDEV_KIND_VXLAN,
47 NETDEV_KIND_IPIP,
48 NETDEV_KIND_GRE,
49 NETDEV_KIND_SIT,
50 NETDEV_KIND_VETH,
51 NETDEV_KIND_VTI,
52 NETDEV_KIND_DUMMY,
53 NETDEV_KIND_TUN,
54 NETDEV_KIND_TAP,
55 _NETDEV_KIND_MAX,
56 _NETDEV_KIND_INVALID = -1
57} NetDevKind;
58
59typedef enum NetDevState {
60 NETDEV_STATE_FAILED,
61 NETDEV_STATE_CREATING,
62 NETDEV_STATE_READY,
63 NETDEV_STATE_LINGER,
64 _NETDEV_STATE_MAX,
65 _NETDEV_STATE_INVALID = -1,
66} NetDevState;
67
aa9f1140
TG
68typedef enum NetDevCreateType {
69 NETDEV_CREATE_INDEPENDENT,
70 NETDEV_CREATE_MASTER,
71 NETDEV_CREATE_STACKED,
72 _NETDEV_CREATE_MAX,
73 _NETDEV_CREATE_INVALID = -1,
74} NetDevCreateType;
75
3be1d7e0
TG
76struct NetDev {
77 Manager *manager;
78
79 int n_ref;
80
81 char *filename;
82
83 Condition *match_host;
84 Condition *match_virt;
85 Condition *match_kernel;
86 Condition *match_arch;
87
aa9f1140
TG
88 NetDevState state;
89 NetDevKind kind;
3be1d7e0
TG
90 char *description;
91 char *ifname;
3be1d7e0 92 struct ether_addr *mac;
aa9f1140 93 size_t mtu;
3be1d7e0 94 int ifindex;
3be1d7e0
TG
95
96 LIST_HEAD(netdev_join_callback, callbacks);
97};
98
aa9f1140
TG
99#include "networkd-netdev-bridge.h"
100#include "networkd-netdev-bond.h"
101#include "networkd-netdev-vlan.h"
102#include "networkd-netdev-macvlan.h"
103#include "networkd-netdev-vxlan.h"
104#include "networkd-netdev-veth.h"
105#include "networkd-netdev-tunnel.h"
106#include "networkd-netdev-dummy.h"
107#include "networkd-netdev-tuntap.h"
108
3be1d7e0 109struct NetDevVTable {
aa9f1140
TG
110 /* How much memory does an object of this unit type need */
111 size_t object_size;
112
113 /* Config file sections this netdev kind understands, separated
114 * by NUL chars */
115 const char *sections;
3be1d7e0 116
aa9f1140
TG
117 /* This should reset all type-specific variables. This should
118 * not allocate memory, and is called with zero-initialized
119 * data. It should hence only initialize variables that need
120 * to be set != 0. */
121 void (*init)(NetDev *n);
3be1d7e0 122
aa9f1140
TG
123 /* This should free all kind-specific variables. It should be
124 * idempotent. */
125 void (*done)(NetDev *n);
126
127 /* fill in message to create netdev */
128 int (*fill_message_create)(NetDev *netdev, Link *link, sd_rtnl_message *message);
129
130 /* specifies if netdev is independent, or a master device or a stacked device */
131 NetDevCreateType create_type;
3be1d7e0
TG
132
133 /* create netdev, if not done via rtnl */
134 int (*create)(NetDev *netdev);
135
136 /* verify that compulsory configuration options were specified */
137 int (*config_verify)(NetDev *netdev, const char *filename);
138};
139
140extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
141
142#define NETDEV_VTABLE(n) netdev_vtable[(n)->kind]
143
aa9f1140
TG
144/* For casting a netdev into the various netdev kinds */
145#define DEFINE_CAST(UPPERCASE, MixedCase) \
146 static inline MixedCase* UPPERCASE(NetDev *n) { \
147 if (_unlikely_(!n || n->kind != NETDEV_KIND_##UPPERCASE)) \
148 return NULL; \
149 \
150 return (MixedCase*) n; \
151 }
152
153/* For casting the various netdev kinds into a netdev */
154#define NETDEV(n) (&(n)->meta)
155
156DEFINE_CAST(BRIDGE, Bridge);
157DEFINE_CAST(BOND, Bond);
158DEFINE_CAST(VLAN, VLan);
159DEFINE_CAST(MACVLAN, MacVlan);
160DEFINE_CAST(VXLAN, VxLan);
161DEFINE_CAST(IPIP, Tunnel);
162DEFINE_CAST(GRE, Tunnel);
163DEFINE_CAST(SIT, Tunnel);
164DEFINE_CAST(VTI, Tunnel);
165DEFINE_CAST(VETH, Veth);
166DEFINE_CAST(DUMMY, Dummy);
167DEFINE_CAST(TUN, TunTap);
168DEFINE_CAST(TAP, TunTap);
169
3be1d7e0
TG
170int netdev_load(Manager *manager);
171void netdev_drop(NetDev *netdev);
172
173NetDev *netdev_unref(NetDev *netdev);
174NetDev *netdev_ref(NetDev *netdev);
175
176DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
177#define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp)
178
179int netdev_get(Manager *manager, const char *name, NetDev **ret);
180int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
181int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
182int netdev_get_mac(const char *ifname, struct ether_addr **ret);
183int netdev_join(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
184
185const char *netdev_kind_to_string(NetDevKind d) _const_;
186NetDevKind netdev_kind_from_string(const char *d) _pure_;
187
188int 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);
189
190/* gperf */
191const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length);
192
193/* Macros which append INTERFACE= to the message */
194
79008bdd
LP
195#define log_full_netdev(level, netdev, fmt, ...) log_object_internal(level, 0, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->ifname, "%-*s: " fmt, IFNAMSIZ, netdev->ifname, ##__VA_ARGS__)
196#define log_netdev_debug(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__)
3be1d7e0
TG
197#define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__)
198#define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__)
199#define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__)
79008bdd 200#define log_netdev_error(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__)
3be1d7e0
TG
201
202#define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->ifname, __VA_ARGS__)
203
aa9f1140 204#define NETDEVIF(netdev) "INTERFACE=%s", netdev->ifname