]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd.h
networkd: minor fixes
[thirdparty/systemd.git] / src / network / networkd.h
CommitLineData
f579559b
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 <arpa/inet.h>
25#include <linux/rtnetlink.h>
26
27#include "sd-event.h"
28#include "sd-rtnl.h"
29#include "udev.h"
30
31#include "rtnl-util.h"
32#include "hashmap.h"
33#include "list.h"
34
35typedef struct Network Network;
36typedef struct Link Link;
37typedef struct Address Address;
38typedef struct Route Route;
39typedef struct Manager Manager;
40
41struct Network {
42 Manager *manager;
43
44 char *filename;
45
46 struct ether_addr *match_mac;
47 char *match_path;
48 char *match_driver;
49 char *match_type;
50 char *match_name;
51
52 char *description;
53
54 LIST_HEAD(Address, addresses);
55 LIST_HEAD(Route, routes);
56
6ae115c1
TG
57 Hashmap *addresses_by_section;
58 Hashmap *routes_by_section;
59
f579559b
TG
60 LIST_FIELDS(Network, networks);
61};
62
63struct Address {
64 Network *network;
6ae115c1 65 uint64_t section;
f579559b
TG
66
67 unsigned char family;
68 unsigned char prefixlen;
69 char *label;
70
8cd11a0f
TG
71 struct in_addr netmask;
72
f579559b
TG
73 union {
74 struct in_addr in;
75 struct in6_addr in6;
76 } in_addr;
77
78 LIST_FIELDS(Address, addresses);
79};
80
81struct Route {
82 Network *network;
6ae115c1 83 uint64_t section;
f579559b
TG
84
85 unsigned char family;
6ae115c1 86 unsigned char dst_prefixlen;
f579559b
TG
87
88 union {
89 struct in_addr in;
90 struct in6_addr in6;
91 } in_addr;
92
6ae115c1
TG
93 union {
94 struct in_addr in;
95 struct in6_addr in6;
96 } dst_addr;
97
f579559b
TG
98 LIST_FIELDS(Route, routes);
99};
100
f882c247
TG
101typedef enum LinkState {
102 LINK_STATE_SET_ADDRESSES,
103 LINK_STATE_ADDRESSES_SET,
104 LINK_STATE_SET_ROUTES,
105 LINK_STATE_ROUTES_SET,
106 LINK_STATE_CONFIGURED,
107 LINK_STATE_FAILED,
108 _LINK_STATE_MAX,
109 _LINK_STATE_INVALID = -1
110} LinkState;
111
f579559b
TG
112struct Link {
113 Manager *manager;
114
0617ffab 115 uint64_t ifindex;
c166a070 116 char *ifname;
8cd11a0f 117 struct ether_addr mac;
f579559b
TG
118
119 unsigned flags;
120
121 Network *network;
f882c247
TG
122
123 LinkState state;
124
125 unsigned rtnl_messages;
f579559b
TG
126};
127
128struct Manager {
129 sd_rtnl *rtnl;
130 sd_event *event;
131 struct udev *udev;
132 struct udev_monitor *udev_monitor;
133 sd_event_source *udev_event_source;
134
135 Hashmap *links;
136 LIST_HEAD(Network, networks);
137
138 char **network_dirs;
139 usec_t network_dirs_ts_usec;
140};
141
142/* Manager */
143
144int manager_new(Manager **ret);
145void manager_free(Manager *m);
146
147int manager_udev_enumerate_links(Manager *m);
148int manager_udev_listen(Manager *m);
149
f882c247
TG
150int manager_rtnl_listen(Manager *m);
151
f579559b
TG
152DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
153#define _cleanup_manager_free_ _cleanup_(manager_freep)
154
155/* Network */
156
157int network_load(Manager *manager);
158bool network_should_reload(Manager *manager);
159
160void network_free(Network *network);
161
162DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
163#define _cleanup_network_free_ _cleanup_(network_freep)
164
165int network_get(Manager *manager, struct udev_device *device, Network **ret);
166int network_apply(Manager *manager, Network *network, Link *link);
167
168const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
169
170/* Route */
6ae115c1 171int route_new(Network *network, unsigned section, Route **ret);
f579559b 172void route_free(Route *route);
f882c247 173int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
f579559b
TG
174
175DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
176#define _cleanup_route_free_ _cleanup_(route_freep)
177
178int config_parse_gateway(const char *unit, const char *filename, unsigned line,
71a61510
TG
179 const char *section, unsigned section_line, const char *lvalue,
180 int ltype, const char *rvalue, void *data, void *userdata);
f579559b 181
6ae115c1
TG
182int config_parse_destination(const char *unit, const char *filename, unsigned line,
183 const char *section, unsigned section_line, const char *lvalue,
184 int ltype, const char *rvalue, void *data, void *userdata);
185
f579559b 186/* Address */
6ae115c1 187int address_new(Network *network, unsigned section, Address **ret);
f579559b 188void address_free(Address *address);
f882c247 189int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
f579559b
TG
190
191DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
192#define _cleanup_address_free_ _cleanup_(address_freep)
193
194int config_parse_address(const char *unit, const char *filename, unsigned line,
71a61510
TG
195 const char *section, unsigned section_line, const char *lvalue,
196 int ltype, const char *rvalue, void *data, void *userdata);
f579559b 197
6ae115c1
TG
198int config_parse_label(const char *unit, const char *filename, unsigned line,
199 const char *section, unsigned section_line, const char *lvalue,
200 int ltype, const char *rvalue, void *data, void *userdata);
201
f579559b
TG
202/* Link */
203
204int link_new(Manager *manager, struct udev_device *device, Link **ret);
205void link_free(Link *link);
206int link_add(Manager *manager, struct udev_device *device);
f882c247 207int link_configure(Link *link);
f579559b
TG
208
209DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
210#define _cleanup_link_free_ _cleanup_(link_freep)