1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
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.
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.
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/>.
24 #include <arpa/inet.h>
25 #include <linux/rtnetlink.h>
29 #include "sd-dhcp-client.h"
32 #include "rtnl-util.h"
36 typedef struct Bridge Bridge;
37 typedef struct Network Network;
38 typedef struct Link Link;
39 typedef struct Address Address;
40 typedef struct Route Route;
41 typedef struct Manager Manager;
43 typedef struct bridge_join_callback bridge_join_callback;
45 struct bridge_join_callback {
46 sd_rtnl_message_handler_t callback;
49 LIST_FIELDS(bridge_join_callback, callbacks);
52 typedef enum BridgeState {
54 BRIDGE_STATE_CREATING,
58 _BRIDGE_STATE_INVALID = -1,
72 LIST_HEAD(bridge_join_callback, callbacks);
80 struct ether_addr *match_mac;
90 LIST_HEAD(Address, static_addresses);
91 LIST_HEAD(Route, static_routes);
93 Hashmap *addresses_by_section;
94 Hashmap *routes_by_section;
96 LIST_FIELDS(Network, networks);
103 unsigned char family;
104 unsigned char prefixlen;
107 struct in_addr netmask;
114 LIST_FIELDS(Address, static_addresses);
121 unsigned char family;
122 unsigned char dst_prefixlen;
134 LIST_FIELDS(Route, static_routes);
137 typedef enum LinkState {
138 LINK_STATE_JOINING_BRIDGE,
139 LINK_STATE_SETTING_ADDRESSES,
140 LINK_STATE_SETTING_ROUTES,
141 LINK_STATE_CONFIGURED,
144 _LINK_STATE_INVALID = -1
152 struct ether_addr mac;
159 Address *dhcp_address;
163 unsigned addr_messages;
164 unsigned route_messages;
166 sd_dhcp_client *dhcp;
173 struct udev_monitor *udev_monitor;
174 sd_event_source *udev_event_source;
178 LIST_HEAD(Network, networks);
181 usec_t network_dirs_ts_usec;
186 int manager_new(Manager **ret);
187 void manager_free(Manager *m);
189 int manager_load_config(Manager *m);
190 bool manager_should_reload(Manager *m);
192 int manager_udev_enumerate_links(Manager *m);
193 int manager_udev_listen(Manager *m);
195 int manager_rtnl_listen(Manager *m);
197 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
198 #define _cleanup_manager_free_ _cleanup_(manager_freep)
202 int bridge_load(Manager *manager);
204 void bridge_free(Bridge *bridge);
206 DEFINE_TRIVIAL_CLEANUP_FUNC(Bridge*, bridge_free);
207 #define _cleanup_bridge_free_ _cleanup_(bridge_freep)
209 int bridge_get(Manager *manager, const char *name, Bridge **ret);
210 int bridge_set_link(Manager *m, Link *link);
211 int bridge_join(Bridge *bridge, Link *link, sd_rtnl_message_handler_t cb);
215 int network_load(Manager *manager);
217 void network_free(Network *network);
219 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
220 #define _cleanup_network_free_ _cleanup_(network_freep)
222 int network_get(Manager *manager, struct udev_device *device, Network **ret);
223 int network_apply(Manager *manager, Network *network, Link *link);
225 int config_parse_bridge(const char *unit, const char *filename, unsigned line,
226 const char *section, unsigned section_line, const char *lvalue,
227 int ltype, const char *rvalue, void *data, void *userdata);
231 const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
234 int route_new_static(Network *network, unsigned section, Route **ret);
235 int route_new_dynamic(Route **ret);
236 void route_free(Route *route);
237 int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
239 DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
240 #define _cleanup_route_free_ _cleanup_(route_freep)
242 int config_parse_gateway(const char *unit, const char *filename, unsigned line,
243 const char *section, unsigned section_line, const char *lvalue,
244 int ltype, const char *rvalue, void *data, void *userdata);
246 int config_parse_destination(const char *unit, const char *filename, unsigned line,
247 const char *section, unsigned section_line, const char *lvalue,
248 int ltype, const char *rvalue, void *data, void *userdata);
251 int address_new_static(Network *network, unsigned section, Address **ret);
252 int address_new_dynamic(Address **ret);
253 void address_free(Address *address);
254 int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
255 int address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback);
257 DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
258 #define _cleanup_address_free_ _cleanup_(address_freep)
260 int config_parse_address(const char *unit, const char *filename, unsigned line,
261 const char *section, unsigned section_line, const char *lvalue,
262 int ltype, const char *rvalue, void *data, void *userdata);
264 int config_parse_label(const char *unit, const char *filename, unsigned line,
265 const char *section, unsigned section_line, const char *lvalue,
266 int ltype, const char *rvalue, void *data, void *userdata);
270 int link_new(Manager *manager, struct udev_device *device, Link **ret);
271 void link_free(Link *link);
272 int link_add(Manager *manager, struct udev_device *device, Link **ret);
273 int link_configure(Link *link);
275 int link_update(Link *link, sd_rtnl_message *message);
277 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
278 #define _cleanup_link_free_ _cleanup_(link_freep)