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>
31 #include "rtnl-util.h"
35 typedef struct Bridge Bridge;
36 typedef struct Network Network;
37 typedef struct Link Link;
38 typedef struct Address Address;
39 typedef struct Route Route;
40 typedef struct Manager Manager;
42 typedef struct bridge_join_callback bridge_join_callback;
44 struct bridge_join_callback {
45 sd_rtnl_message_handler_t callback;
48 LIST_FIELDS(bridge_join_callback, callbacks);
51 typedef enum BridgeState {
53 BRIDGE_STATE_CREATING,
57 _BRIDGE_STATE_INVALID = -1,
71 LIST_HEAD(bridge_join_callback, callbacks);
79 struct ether_addr *match_mac;
88 LIST_HEAD(Address, addresses);
89 LIST_HEAD(Route, routes);
91 Hashmap *addresses_by_section;
92 Hashmap *routes_by_section;
94 LIST_FIELDS(Network, networks);
101 unsigned char family;
102 unsigned char prefixlen;
105 struct in_addr netmask;
112 LIST_FIELDS(Address, addresses);
119 unsigned char family;
120 unsigned char dst_prefixlen;
132 LIST_FIELDS(Route, routes);
135 typedef enum LinkState {
136 LINK_STATE_JOINING_BRIDGE,
137 LINK_STATE_SETTING_ADDRESSES,
138 LINK_STATE_SETTING_ROUTES,
139 LINK_STATE_CONFIGURED,
142 _LINK_STATE_INVALID = -1
150 struct ether_addr mac;
158 unsigned rtnl_messages;
165 struct udev_monitor *udev_monitor;
166 sd_event_source *udev_event_source;
170 LIST_HEAD(Network, networks);
173 usec_t network_dirs_ts_usec;
178 int manager_new(Manager **ret);
179 void manager_free(Manager *m);
181 int manager_load_config(Manager *m);
182 bool manager_should_reload(Manager *m);
184 int manager_udev_enumerate_links(Manager *m);
185 int manager_udev_listen(Manager *m);
187 int manager_rtnl_listen(Manager *m);
189 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
190 #define _cleanup_manager_free_ _cleanup_(manager_freep)
194 int bridge_load(Manager *manager);
196 void bridge_free(Bridge *bridge);
198 DEFINE_TRIVIAL_CLEANUP_FUNC(Bridge*, bridge_free);
199 #define _cleanup_bridge_free_ _cleanup_(bridge_freep)
201 int bridge_get(Manager *manager, const char *name, Bridge **ret);
202 int bridge_set_link(Manager *m, Link *link);
203 int bridge_join(Bridge *bridge, Link *link, sd_rtnl_message_handler_t cb);
207 int network_load(Manager *manager);
209 void network_free(Network *network);
211 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
212 #define _cleanup_network_free_ _cleanup_(network_freep)
214 int network_get(Manager *manager, struct udev_device *device, Network **ret);
215 int network_apply(Manager *manager, Network *network, Link *link);
217 int config_parse_bridge(const char *unit, const char *filename, unsigned line,
218 const char *section, unsigned section_line, const char *lvalue,
219 int ltype, const char *rvalue, void *data, void *userdata);
223 const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
226 int route_new(Network *network, unsigned section, Route **ret);
227 void route_free(Route *route);
228 int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
230 DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
231 #define _cleanup_route_free_ _cleanup_(route_freep)
233 int config_parse_gateway(const char *unit, const char *filename, unsigned line,
234 const char *section, unsigned section_line, const char *lvalue,
235 int ltype, const char *rvalue, void *data, void *userdata);
237 int config_parse_destination(const char *unit, const char *filename, unsigned line,
238 const char *section, unsigned section_line, const char *lvalue,
239 int ltype, const char *rvalue, void *data, void *userdata);
242 int address_new(Network *network, unsigned section, Address **ret);
243 void address_free(Address *address);
244 int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
246 DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
247 #define _cleanup_address_free_ _cleanup_(address_freep)
249 int config_parse_address(const char *unit, const char *filename, unsigned line,
250 const char *section, unsigned section_line, const char *lvalue,
251 int ltype, const char *rvalue, void *data, void *userdata);
253 int config_parse_label(const char *unit, const char *filename, unsigned line,
254 const char *section, unsigned section_line, const char *lvalue,
255 int ltype, const char *rvalue, void *data, void *userdata);
259 int link_new(Manager *manager, struct udev_device *device, Link **ret);
260 void link_free(Link *link);
261 int link_add(Manager *manager, struct udev_device *device);
262 int link_configure(Link *link);
264 int link_update(Link *link, sd_rtnl_message *message);
266 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
267 #define _cleanup_link_free_ _cleanup_(link_freep)