Skip to content

Commit fc2f953

Browse files
committed
networkd: split up networkd.h into per-object header files
No functional changes, just moving definitions into separate header files.
1 parent f6b8196 commit fc2f953

20 files changed

+677
-541
lines changed

Makefile.am

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,41 +5167,48 @@ libnetworkd_core_la_SOURCES = \
51675167
src/libsystemd-network/network-internal.h \
51685168
src/network/networkd.h \
51695169
src/network/networkd-link.h \
5170+
src/network/networkd-link.c \
51705171
src/network/networkd-netdev.h \
5171-
src/network/networkd-netdev-tunnel.h \
5172-
src/network/networkd-netdev-veth.h \
5173-
src/network/networkd-netdev-vxlan.h \
5174-
src/network/networkd-netdev-vlan.h \
5175-
src/network/networkd-netdev-macvlan.h \
5176-
src/network/networkd-netdev-ipvlan.h \
5177-
src/network/networkd-netdev-dummy.h \
5178-
src/network/networkd-netdev-tuntap.h \
5179-
src/network/networkd-netdev-bond.h \
5180-
src/network/networkd-netdev-bridge.h \
51815172
src/network/networkd-netdev.c \
5173+
src/network/networkd-netdev-tunnel.h \
51825174
src/network/networkd-netdev-tunnel.c \
5175+
src/network/networkd-netdev-veth.h \
51835176
src/network/networkd-netdev-veth.c \
5177+
src/network/networkd-netdev-vxlan.h \
51845178
src/network/networkd-netdev-vxlan.c \
5179+
src/network/networkd-netdev-vlan.h \
51855180
src/network/networkd-netdev-vlan.c \
5181+
src/network/networkd-netdev-macvlan.h \
51865182
src/network/networkd-netdev-macvlan.c \
5183+
src/network/networkd-netdev-ipvlan.h \
51875184
src/network/networkd-netdev-ipvlan.c \
5185+
src/network/networkd-netdev-dummy.h \
51885186
src/network/networkd-netdev-dummy.c \
5187+
src/network/networkd-netdev-tuntap.h \
51895188
src/network/networkd-netdev-tuntap.c \
5189+
src/network/networkd-netdev-bond.h \
51905190
src/network/networkd-netdev-bond.c \
5191+
src/network/networkd-netdev-bridge.h \
51915192
src/network/networkd-netdev-bridge.c \
5192-
src/network/networkd-link.c \
51935193
src/network/networkd-link-bus.c \
51945194
src/network/networkd-ipv4ll.c \
51955195
src/network/networkd-dhcp4.c \
51965196
src/network/networkd-dhcp6.c \
5197+
src/network/networkd-network.h \
51975198
src/network/networkd-network.c \
51985199
src/network/networkd-network-bus.c \
5200+
src/network/networkd-address.h \
51995201
src/network/networkd-address.c \
5202+
src/network/networkd-route.h \
52005203
src/network/networkd-route.c \
52015204
src/network/networkd-manager.c \
52025205
src/network/networkd-manager-bus.c \
5206+
src/network/networkd-fdb.h \
52035207
src/network/networkd-fdb.c \
5204-
src/network/networkd-address-pool.c
5208+
src/network/networkd-address-pool.h \
5209+
src/network/networkd-address-pool.c \
5210+
src/network/networkd-util.h \
5211+
src/network/networkd-util.c
52055212

52065213
nodist_libnetworkd_core_la_SOURCES = \
52075214
src/network/networkd-network-gperf.c \

src/network/networkd-address-pool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
along with systemd; If not, see <http://www.gnu.org/licenses/>.
2020
***/
2121

22-
2322
#include "networkd.h"
24-
#include "networkd-link.h"
23+
#include "networkd-address-pool.h"
2524

2625
int address_pool_new(
2726
Manager *m,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2+
3+
#pragma once
4+
5+
/***
6+
This file is part of systemd.
7+
8+
Copyright 2014 Lennart Poettering
9+
10+
systemd is free software; you can redistribute it and/or modify it
11+
under the terms of the GNU Lesser General Public License as published by
12+
the Free Software Foundation; either version 2.1 of the License, or
13+
(at your option) any later version.
14+
15+
systemd is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General Public License
21+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
22+
***/
23+
24+
typedef struct AddressPool AddressPool;
25+
26+
#include "networkd.h"
27+
28+
struct AddressPool {
29+
Manager *manager;
30+
31+
int family;
32+
unsigned prefixlen;
33+
34+
union in_addr_union in_addr;
35+
36+
LIST_FIELDS(AddressPool, address_pools);
37+
};
38+
39+
int address_pool_new(Manager *m, AddressPool **ret, int family, const union in_addr_union *u, unsigned prefixlen);
40+
int address_pool_new_from_string(Manager *m, AddressPool **ret, int family, const char *p, unsigned prefixlen);
41+
void address_pool_free(AddressPool *p);
42+
43+
int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found);

src/network/networkd-address.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
#include "util.h"
2626
#include "conf-parser.h"
2727
#include "firewall-util.h"
28+
#include "netlink-util.h"
29+
2830
#include "networkd.h"
29-
#include "networkd-link.h"
31+
#include "networkd-address.h"
3032

3133
static void address_init(Address *address) {
3234
assert(address);

src/network/networkd-address.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2+
3+
#pragma once
4+
5+
/***
6+
This file is part of systemd.
7+
8+
Copyright 2013 Tom Gundersen <teg@jklm.no>
9+
10+
systemd is free software; you can redistribute it and/or modify it
11+
under the terms of the GNU Lesser General Public License as published by
12+
the Free Software Foundation; either version 2.1 of the License, or
13+
(at your option) any later version.
14+
15+
systemd is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General Public License
21+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
22+
***/
23+
24+
#include <inttypes.h>
25+
#include <stdbool.h>
26+
27+
#include "in-addr-util.h"
28+
29+
typedef struct Address Address;
30+
31+
#include "networkd.h"
32+
#include "networkd-network.h"
33+
#include "networkd-link.h"
34+
35+
#define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
36+
37+
struct Address {
38+
Network *network;
39+
unsigned section;
40+
41+
int family;
42+
unsigned char prefixlen;
43+
unsigned char scope;
44+
uint32_t flags;
45+
char *label;
46+
47+
struct in_addr broadcast;
48+
struct ifa_cacheinfo cinfo;
49+
50+
union in_addr_union in_addr;
51+
union in_addr_union in_addr_peer;
52+
53+
bool ip_masquerade_done;
54+
55+
LIST_FIELDS(Address, addresses);
56+
};
57+
58+
int address_new_static(Network *network, unsigned section, Address **ret);
59+
int address_new_dynamic(Address **ret);
60+
void address_free(Address *address);
61+
int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback);
62+
int address_update(Address *address, Link *link, sd_netlink_message_handler_t callback);
63+
int address_drop(Address *address, Link *link, sd_netlink_message_handler_t callback);
64+
int address_establish(Address *address, Link *link);
65+
int address_release(Address *address, Link *link);
66+
bool address_equal(Address *a1, Address *a2);
67+
68+
DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
69+
#define _cleanup_address_free_ _cleanup_(address_freep)
70+
71+
int config_parse_address(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);
72+
int config_parse_broadcast(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);
73+
int config_parse_label(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);

src/network/networkd-fdb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include <net/if.h>
2323
#include <net/ethernet.h>
2424

25-
#include "networkd.h"
26-
#include "networkd-link.h"
2725
#include "conf-parser.h"
2826
#include "util.h"
27+
#include "netlink-util.h"
28+
29+
#include "networkd.h"
30+
#include "networkd-fdb.h"
2931

3032
/* create a new FDB entry or get an existing one. */
3133
int fdb_entry_new_static(Network *const network,

src/network/networkd-fdb.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2+
3+
#pragma once
4+
5+
/***
6+
This file is part of systemd.
7+
8+
Copyright (C) 2014 Intel Corporation. All rights reserved.
9+
10+
systemd is free software; you can redistribute it and/or modify it
11+
under the terms of the GNU Lesser General Public License as published by
12+
the Free Software Foundation; either version 2.1 of the License, or
13+
(at your option) any later version.
14+
15+
systemd is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General Public License
21+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
22+
***/
23+
24+
typedef struct FdbEntry FdbEntry;
25+
26+
#include "networkd.h"
27+
#include "networkd-network.h"
28+
29+
struct FdbEntry {
30+
Network *network;
31+
unsigned section;
32+
33+
struct ether_addr *mac_addr;
34+
uint16_t vlan_id;
35+
36+
LIST_FIELDS(FdbEntry, static_fdb_entries);
37+
};
38+
39+
int fdb_entry_new_static(Network *const network, const unsigned section, FdbEntry **ret);
40+
void fdb_entry_free(FdbEntry *fdb_entry);
41+
int fdb_entry_configure(Link *const link, FdbEntry *const fdb_entry);
42+
43+
DEFINE_TRIVIAL_CLEANUP_FUNC(FdbEntry*, fdb_entry_free);
44+
#define _cleanup_fdbentry_free_ _cleanup_(fdb_entry_freep)
45+
46+
int config_parse_fdb_hwaddr(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);
47+
int config_parse_fdb_vlan_id(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);

src/network/networkd-link.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#include "socket-util.h"
3030
#include "bus-util.h"
3131
#include "udev-util.h"
32+
#include "netlink-util.h"
3233
#include "dhcp-lease-internal.h"
3334
#include "network-internal.h"
35+
3436
#include "networkd-link.h"
3537
#include "networkd-netdev.h"
3638

src/network/networkd-link.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
22

3+
#pragma once
4+
35
/***
46
This file is part of systemd.
57
@@ -19,11 +21,16 @@
1921
along with systemd; If not, see <http://www.gnu.org/licenses/>.
2022
***/
2123

22-
#pragma once
23-
2424
#include <endian.h>
2525

26-
#include "networkd.h"
26+
#include "sd-dhcp-client.h"
27+
#include "sd-dhcp-server.h"
28+
#include "sd-ipv4ll.h"
29+
#include "sd-icmp6-nd.h"
30+
#include "sd-dhcp6-client.h"
31+
#include "sd-lldp.h"
32+
33+
typedef struct Link Link;
2734

2835
typedef enum LinkState {
2936
LINK_STATE_PENDING,
@@ -38,6 +45,21 @@ typedef enum LinkState {
3845
_LINK_STATE_INVALID = -1
3946
} LinkState;
4047

48+
typedef enum LinkOperationalState {
49+
LINK_OPERSTATE_OFF,
50+
LINK_OPERSTATE_NO_CARRIER,
51+
LINK_OPERSTATE_DORMANT,
52+
LINK_OPERSTATE_CARRIER,
53+
LINK_OPERSTATE_DEGRADED,
54+
LINK_OPERSTATE_ROUTABLE,
55+
_LINK_OPERSTATE_MAX,
56+
_LINK_OPERSTATE_INVALID = -1
57+
} LinkOperationalState;
58+
59+
#include "networkd.h"
60+
#include "networkd-network.h"
61+
#include "networkd-address.h"
62+
4163
struct Link {
4264
Manager *manager;
4365

@@ -131,6 +153,9 @@ bool link_dhcp6_enabled(Link *link);
131153
const char* link_state_to_string(LinkState s) _const_;
132154
LinkState link_state_from_string(const char *s) _pure_;
133155

156+
const char* link_operstate_to_string(LinkOperationalState s) _const_;
157+
LinkOperationalState link_operstate_from_string(const char *s) _pure_;
158+
134159
extern const sd_bus_vtable link_vtable[];
135160

136161
int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);

src/network/networkd-manager.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
#include <sys/socket.h>
2323
#include <linux/if.h>
2424

25+
#include "sd-netlink.h"
26+
#include "sd-daemon.h"
27+
2528
#include "conf-parser.h"
2629
#include "path-util.h"
27-
#include "networkd.h"
28-
#include "networkd-netdev.h"
29-
#include "networkd-link.h"
3030
#include "libudev-private.h"
3131
#include "udev-util.h"
3232
#include "netlink-util.h"
3333
#include "bus-util.h"
3434
#include "def.h"
3535
#include "virt.h"
36+
#include "set.h"
3637

37-
#include "sd-netlink.h"
38-
#include "sd-daemon.h"
38+
#include "networkd.h"
3939

4040
/* use 8 MB for receive socket kernel queue. */
4141
#define RCVBUF_SIZE (8*1024*1024)
@@ -845,37 +845,3 @@ int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, uni
845845

846846
return 0;
847847
}
848-
849-
const char *address_family_boolean_to_string(AddressFamilyBoolean b) {
850-
if (b == ADDRESS_FAMILY_YES ||
851-
b == ADDRESS_FAMILY_NO)
852-
return yes_no(b == ADDRESS_FAMILY_YES);
853-
854-
if (b == ADDRESS_FAMILY_IPV4)
855-
return "ipv4";
856-
if (b == ADDRESS_FAMILY_IPV6)
857-
return "ipv6";
858-
859-
return NULL;
860-
}
861-
862-
AddressFamilyBoolean address_family_boolean_from_string(const char *s) {
863-
int r;
864-
865-
/* Make this a true superset of a boolean */
866-
867-
r = parse_boolean(s);
868-
if (r > 0)
869-
return ADDRESS_FAMILY_YES;
870-
if (r == 0)
871-
return ADDRESS_FAMILY_NO;
872-
873-
if (streq(s, "ipv4"))
874-
return ADDRESS_FAMILY_IPV4;
875-
if (streq(s, "ipv6"))
876-
return ADDRESS_FAMILY_IPV6;
877-
878-
return _ADDRESS_FAMILY_BOOLEAN_INVALID;
879-
}
880-
881-
DEFINE_CONFIG_PARSE_ENUM(config_parse_address_family_boolean, address_family_boolean, AddressFamilyBoolean, "Failed to parse option");

0 commit comments

Comments
 (0)