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_family
;
123 unsigned char dst_prefixlen
;
135 LIST_FIELDS(Route
, static_routes
);
138 typedef enum LinkState
{
139 LINK_STATE_JOINING_BRIDGE
,
140 LINK_STATE_SETTING_ADDRESSES
,
141 LINK_STATE_SETTING_ROUTES
,
142 LINK_STATE_CONFIGURED
,
145 _LINK_STATE_INVALID
= -1
153 struct ether_addr mac
;
160 Address
*dhcp_address
;
164 unsigned addr_messages
;
165 unsigned route_messages
;
167 sd_dhcp_client
*dhcp
;
174 struct udev_monitor
*udev_monitor
;
175 sd_event_source
*udev_event_source
;
179 LIST_HEAD(Network
, networks
);
182 usec_t network_dirs_ts_usec
;
187 int manager_new(Manager
**ret
);
188 void manager_free(Manager
*m
);
190 int manager_load_config(Manager
*m
);
191 bool manager_should_reload(Manager
*m
);
193 int manager_udev_enumerate_links(Manager
*m
);
194 int manager_udev_listen(Manager
*m
);
196 int manager_rtnl_listen(Manager
*m
);
198 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager
*, manager_free
);
199 #define _cleanup_manager_free_ _cleanup_(manager_freep)
203 int bridge_load(Manager
*manager
);
205 void bridge_free(Bridge
*bridge
);
207 DEFINE_TRIVIAL_CLEANUP_FUNC(Bridge
*, bridge_free
);
208 #define _cleanup_bridge_free_ _cleanup_(bridge_freep)
210 int bridge_get(Manager
*manager
, const char *name
, Bridge
**ret
);
211 int bridge_set_link(Manager
*m
, Link
*link
);
212 int bridge_join(Bridge
*bridge
, Link
*link
, sd_rtnl_message_handler_t cb
);
216 int network_load(Manager
*manager
);
218 void network_free(Network
*network
);
220 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_free
);
221 #define _cleanup_network_free_ _cleanup_(network_freep)
223 int network_get(Manager
*manager
, struct udev_device
*device
, Network
**ret
);
224 int network_apply(Manager
*manager
, Network
*network
, Link
*link
);
226 int config_parse_bridge(const char *unit
, const char *filename
, unsigned line
,
227 const char *section
, unsigned section_line
, const char *lvalue
,
228 int ltype
, const char *rvalue
, void *data
, void *userdata
);
232 const struct ConfigPerfItem
* network_gperf_lookup(const char *key
, unsigned length
);
235 int route_new_static(Network
*network
, unsigned section
, Route
**ret
);
236 int route_new_dynamic(Route
**ret
);
237 void route_free(Route
*route
);
238 int route_configure(Route
*route
, Link
*link
, sd_rtnl_message_handler_t callback
);
240 DEFINE_TRIVIAL_CLEANUP_FUNC(Route
*, route_free
);
241 #define _cleanup_route_free_ _cleanup_(route_freep)
243 int config_parse_gateway(const char *unit
, const char *filename
, unsigned line
,
244 const char *section
, unsigned section_line
, const char *lvalue
,
245 int ltype
, const char *rvalue
, void *data
, void *userdata
);
247 int config_parse_destination(const char *unit
, const char *filename
, unsigned line
,
248 const char *section
, unsigned section_line
, const char *lvalue
,
249 int ltype
, const char *rvalue
, void *data
, void *userdata
);
252 int address_new_static(Network
*network
, unsigned section
, Address
**ret
);
253 int address_new_dynamic(Address
**ret
);
254 void address_free(Address
*address
);
255 int address_configure(Address
*address
, Link
*link
, sd_rtnl_message_handler_t callback
);
256 int address_drop(Address
*address
, Link
*link
, sd_rtnl_message_handler_t callback
);
258 DEFINE_TRIVIAL_CLEANUP_FUNC(Address
*, address_free
);
259 #define _cleanup_address_free_ _cleanup_(address_freep)
261 int config_parse_address(const char *unit
, const char *filename
, unsigned line
,
262 const char *section
, unsigned section_line
, const char *lvalue
,
263 int ltype
, const char *rvalue
, void *data
, void *userdata
);
265 int config_parse_label(const char *unit
, const char *filename
, unsigned line
,
266 const char *section
, unsigned section_line
, const char *lvalue
,
267 int ltype
, const char *rvalue
, void *data
, void *userdata
);
271 int link_new(Manager
*manager
, struct udev_device
*device
, Link
**ret
);
272 void link_free(Link
*link
);
273 int link_add(Manager
*manager
, struct udev_device
*device
, Link
**ret
);
274 int link_configure(Link
*link
);
276 int link_update(Link
*link
, sd_rtnl_message
*message
);
278 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_free
);
279 #define _cleanup_link_free_ _cleanup_(link_freep)