]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: rework headers to avoid circular includes
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Apr 2016 02:52:04 +0000 (22:52 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Apr 2016 23:01:28 +0000 (19:01 -0400)
Header files were organized in a way where the includer would add various
typedefs used by the includee before including it, resulting in a tangled
web of dependencies between files.

Replace this with the following logic:

          networkd.h
         /          \
networkd-link.h      \
networkd-ipv4ll.h--\__\
networkd-fdb.h         \
networkd-network.h    netword-netdev-*.h
networkd-route.h           \
                      networkd-netdev.h

If a pointer to a structure defined in a different header file is needed,
use a typedef line instead of including the whole header.

29 files changed:
src/network/networkd-address-pool.h
src/network/networkd-address.h
src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c
src/network/networkd-fdb.h
src/network/networkd-ipv4ll.c
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-lldp-tx.c
src/network/networkd-ndisc.c
src/network/networkd-netdev-bond.c
src/network/networkd-netdev-bond.h
src/network/networkd-netdev-bridge.c
src/network/networkd-netdev-bridge.h
src/network/networkd-netdev-dummy.h
src/network/networkd-netdev-gperf.gperf
src/network/networkd-netdev-ipvlan.h
src/network/networkd-netdev-macvlan.h
src/network/networkd-netdev-tunnel.h
src/network/networkd-netdev-tuntap.c
src/network/networkd-netdev-tuntap.h
src/network/networkd-netdev-veth.h
src/network/networkd-netdev-vlan.h
src/network/networkd-netdev-vxlan.c
src/network/networkd-netdev-vxlan.h
src/network/networkd-netdev.h
src/network/networkd-network.h
src/network/networkd-route.h
src/network/networkd.h

index 8e1378ff4059163733bff7ff72d717a865b77591..af30decfe0373e78db6332cabca42e460ec0853f 100644 (file)
@@ -22,7 +22,9 @@
 typedef struct AddressPool AddressPool;
 
 #include "in-addr-util.h"
-#include "networkd.h"
+#include "list.h"
+
+typedef struct Manager Manager;
 
 struct AddressPool {
         Manager *manager;
index 338f6eb9a2d8f4c978b11cd2d0bf5e40a0da58af..3b5285abf04d9014c2d4065910a24bf23e5a8d3e 100644 (file)
@@ -28,10 +28,12 @@ typedef struct Address Address;
 
 #include "networkd-link.h"
 #include "networkd-network.h"
-#include "networkd.h"
 
 #define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
 
+typedef struct Network Network;
+typedef struct Link Link;
+
 struct Address {
         Network *network;
         unsigned section;
index c5b61abc9e58f072463852087bee0b2ba6f960e9..d31ea4d06639a0b557fb44a57d6a60e90fe8bc31 100644 (file)
@@ -24,7 +24,7 @@
 #include "dhcp-lease-internal.h"
 #include "hostname-util.h"
 #include "network-internal.h"
-#include "networkd-link.h"
+#include "networkd.h"
 
 static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m,
                                void *userdata) {
index d4b2fbfc57cdbac939e457a3f3040d97a57a491d..b9c4b8962c88b2a80cfca3e952d53b30da9f73c9 100644 (file)
@@ -23,7 +23,7 @@
 #include "sd-dhcp6-client.h"
 
 #include "network-internal.h"
-#include "networkd-link.h"
+#include "networkd.h"
 
 static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link);
 
index 89b3e2940554746c80807fde751be28b151d5ccf..84410714f530da4edde6b8ec0dc9505df6f508c4 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-typedef struct FdbEntry FdbEntry;
+#include "list.h"
+#include "macro.h"
 
-#include "networkd-network.h"
-#include "networkd.h"
+typedef struct Network Network;
+typedef struct FdbEntry FdbEntry;
+typedef struct Link Link;
 
 struct FdbEntry {
         Network *network;
index e05fd3eea7bbbb61b0dc0ddb996de094f339587f..35c9b0647320b6a4304bf5ceeb58c21542cac79b 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/if.h>
 
 #include "network-internal.h"
-#include "networkd-link.h"
+#include "networkd.h"
 
 static int ipv4ll_address_lost(Link *link) {
         _cleanup_address_free_ Address *address = NULL;
index 5fc513bfdad9906a5eac984aaa2a4cfbfe5baf2a..a88e4c34ed0553d59bd358a53064ca7045ce2dd0 100644 (file)
@@ -28,9 +28,8 @@
 #include "fileio.h"
 #include "netlink-util.h"
 #include "network-internal.h"
-#include "networkd-link.h"
+#include "networkd.h"
 #include "networkd-lldp-tx.h"
-#include "networkd-netdev.h"
 #include "set.h"
 #include "socket-util.h"
 #include "stdio-util.h"
index f2a64ca9b5a80162b7f143ef87c71f7a0ec2d3f2..86139be55757a9026da13e12ec5990b7bf4ca928 100644 (file)
 
 #include <endian.h>
 
+#include "sd-bus.h"
 #include "sd-dhcp-client.h"
 #include "sd-dhcp-server.h"
 #include "sd-dhcp6-client.h"
 #include "sd-ipv4ll.h"
 #include "sd-lldp.h"
 #include "sd-ndisc.h"
+#include "sd-netlink.h"
 
-typedef struct Link Link;
+#include "list.h"
+#include "set.h"
 
 typedef enum LinkState {
         LINK_STATE_PENDING,
@@ -54,11 +57,11 @@ typedef enum LinkOperationalState {
         _LINK_OPERSTATE_INVALID = -1
 } LinkOperationalState;
 
-#include "networkd-address.h"
-#include "networkd-network.h"
-#include "networkd.h"
+typedef struct Manager Manager;
+typedef struct Network Network;
+typedef struct Address Address;
 
-struct Link {
+typedef struct Link {
         Manager *manager;
 
         int n_ref;
@@ -122,7 +125,7 @@ struct Link {
 
         Hashmap *bound_by_links;
         Hashmap *bound_to_links;
-};
+} Link;
 
 Link *link_unref(Link *link);
 Link *link_ref(Link *link);
index 6bde04bc32300e77f044445de5ebc504a617411a..03b694c3f1c520bdf0430e6a29df1bd70c1eba8c 100644 (file)
 #include <inttypes.h>
 #include <string.h>
 
+#include "alloc-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "hostname-util.h"
-#include "networkd-lldp-tx.h"
 #include "random-util.h"
 #include "socket-util.h"
 #include "string-util.h"
 #include "unaligned.h"
 
+#include "networkd.h"
+#include "networkd-lldp-tx.h"
+
 #define LLDP_MULTICAST_ADDR { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e }
 
 /* The LLDP spec calls this "txFastInit", see 9.2.5.19 */
index 4577292e444b2f3543531a181b4e11bb69912ba3..b22c58bfe530e079639e4310ec24c8b9dd8735fd 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "sd-ndisc.h"
 
-#include "networkd-link.h"
+#include "networkd.h"
 
 static int ndisc_netlink_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
index 6b9cbcded6ba7bb4e260256108dd9dc8319b3c1d..7913b0088eb80f30c19d7748a45d434533ce1e2d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "alloc-util.h"
 #include "conf-parser.h"
+#include "extract-word.h"
 #include "missing.h"
 #include "networkd-netdev-bond.h"
 #include "string-table.h"
index cb6baea24f034685be5a47a06d62ea75b08c1976..b941edb3445da131965a0550802322c64b2a631f 100644 (file)
@@ -20,8 +20,7 @@
 ***/
 
 #include "in-addr-util.h"
-
-typedef struct Bond Bond;
+#include "list.h"
 
 #include "networkd-netdev.h"
 
@@ -106,7 +105,7 @@ typedef struct ArpIpTarget {
         LIST_FIELDS(struct ArpIpTarget, arp_ip_target);
 } ArpIpTarget;
 
-struct Bond {
+typedef struct Bond {
         NetDev meta;
 
         BondMode mode;
@@ -133,8 +132,9 @@ struct Bond {
 
         int n_arp_ip_targets;
         ArpIpTarget *arp_ip_targets;
-};
+} Bond;
 
+DEFINE_NETDEV_CAST(BOND, Bond);
 extern const NetDevVTable bond_vtable;
 
 const char *bond_mode_to_string(BondMode d) _const_;
index 3f91b2eaeab3819f6535002afe5e87b76446cd24..3e44dd7960b29b7988cbae4eb57ad19b5a20b04d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "missing.h"
 #include "netlink-util.h"
+#include "networkd.h"
 #include "networkd-netdev-bridge.h"
 
 /* callback for brige netdev's parameter set */
index 3f6f1d0502571e791bae55852372833cc00541e7..b921439f02fee421940f45da31c8113d9c2c6195 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-typedef struct Bridge Bridge;
-
 #include "networkd-netdev.h"
 
-struct Bridge {
+typedef struct Bridge {
         NetDev meta;
 
         int mcast_querier;
@@ -31,6 +29,7 @@ struct Bridge {
         usec_t forward_delay;
         usec_t hello_time;
         usec_t max_age;
-};
+} Bridge;
 
+DEFINE_NETDEV_CAST(BRIDGE, Bridge);
 extern const NetDevVTable bridge_vtable;
index 42da62ebe4b03b454c6984c2e0d6f5f06b136fef..efe302267e00a10f7a98c6d977ca04388f944862 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-typedef struct Dummy Dummy;
-
 #include "networkd-netdev.h"
 
-struct Dummy {
+typedef struct Dummy {
         NetDev meta;
-};
+} Dummy;
 
+DEFINE_NETDEV_CAST(DUMMY, Dummy);
 extern const NetDevVTable dummy_vtable;
index 15a787a9e3bf1f4b3e035dcd7ad78cfa1478a158..1ebd0fdf2093530060ce449ab1d77c5abeaa7d0c 100644 (file)
@@ -1,11 +1,17 @@
 %{
 #include <stddef.h>
 #include "conf-parser.h"
-#include "networkd-netdev.h"
-#include "networkd-netdev-tunnel.h"
+#include "network-internal.h"
 #include "networkd-netdev-bond.h"
+#include "networkd-netdev-ipvlan.h"
 #include "networkd-netdev-macvlan.h"
-#include "network-internal.h"
+#include "networkd-netdev-tunnel.h"
+#include "networkd-netdev-tuntap.h"
+#include "networkd-netdev-veth.h"
+#include "networkd-netdev-vlan.h"
+#include "networkd-netdev-vxlan.h"
+#include "networkd-netdev-bridge.h"
+#include "networkd-netdev.h"
 %}
 struct ConfigPerfItem;
 %null_strings
index 4bd0b67866ebc51d8b19ccce8fe9a2e8e38678ed..10d407984431459b0cd29be4eccfbb74e5a32552 100644 (file)
@@ -19,8 +19,6 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-typedef struct IPVlan IPVlan;
-
 #include "missing.h"
 #include "networkd-netdev.h"
 
@@ -31,12 +29,13 @@ typedef enum IPVlanMode {
         _NETDEV_IPVLAN_MODE_INVALID = -1
 } IPVlanMode;
 
-struct IPVlan {
+typedef struct IPVlan {
         NetDev meta;
 
         IPVlanMode mode;
-};
+} IPVlan;
 
+DEFINE_NETDEV_CAST(IPVLAN, IPVlan);
 extern const NetDevVTable ipvlan_vtable;
 
 const char *ipvlan_mode_to_string(IPVlanMode d) _const_;
index 622ef9ef53b04ca827e2133f3c9525b51d03fa3b..3663f4f051ad51ad7050f200ba579c75440a9570 100644 (file)
@@ -38,6 +38,8 @@ struct MacVlan {
         MacVlanMode mode;
 };
 
+DEFINE_NETDEV_CAST(MACVLAN, MacVlan);
+DEFINE_NETDEV_CAST(MACVTAP, MacVlan);
 extern const NetDevVTable macvlan_vtable;
 extern const NetDevVTable macvtap_vtable;
 
index 0d41f80a3c22d93b71570814166f7fcc7276719c..7d31e7b68702c2c443bc28b4f4f656f98628db94 100644 (file)
@@ -19,7 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-typedef struct Tunnel Tunnel;
+#include "in-addr-util.h"
 
 #include "networkd-netdev.h"
 
@@ -37,7 +37,7 @@ typedef enum IPv6FlowLabel {
         _NETDEV_IPV6_FLOWLABEL_INVALID = -1,
 } IPv6FlowLabel;
 
-struct Tunnel {
+typedef struct Tunnel {
         NetDev meta;
 
         uint8_t encap_limit;
@@ -56,8 +56,17 @@ struct Tunnel {
 
         bool pmtudisc;
         bool copy_dscp;
-};
-
+} Tunnel;
+
+DEFINE_NETDEV_CAST(IPIP, Tunnel);
+DEFINE_NETDEV_CAST(GRE, Tunnel);
+DEFINE_NETDEV_CAST(GRETAP, Tunnel);
+DEFINE_NETDEV_CAST(IP6GRE, Tunnel);
+DEFINE_NETDEV_CAST(IP6GRETAP, Tunnel);
+DEFINE_NETDEV_CAST(SIT, Tunnel);
+DEFINE_NETDEV_CAST(VTI, Tunnel);
+DEFINE_NETDEV_CAST(VTI6, Tunnel);
+DEFINE_NETDEV_CAST(IP6TNL, Tunnel);
 extern const NetDevVTable ipip_vtable;
 extern const NetDevVTable sit_vtable;
 extern const NetDevVTable vti_vtable;
index 32917fe6d5e44282d1b2eb6f3a72ce2a202fc400..088a4d8d321aa5b824d2a7e058c6df0609cbfc92 100644 (file)
     along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <net/if.h>
-#include <sys/ioctl.h>
+#include <fcntl.h>
 #include <linux/if_tun.h>
+#include <net/if.h>
 #include <netinet/if_ether.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 #include "alloc-util.h"
 #include "fd-util.h"
index cbb7ee05a6bc65dab328eaf44e455a329d29a37d..120f00a3539ae19269e7cbaf2eddc8b6f88c8cc7 100644 (file)
@@ -34,5 +34,7 @@ struct TunTap {
         bool vnet_hdr;
 };
 
+DEFINE_NETDEV_CAST(TUN, TunTap);
+DEFINE_NETDEV_CAST(TAP, TunTap);
 extern const NetDevVTable tun_vtable;
 extern const NetDevVTable tap_vtable;
index ae5785783c0c212229e30be56c3f03ea76d3e167..e69bfbc8f03258b9a7b2527377784e0c4ab264e1 100644 (file)
@@ -30,4 +30,5 @@ struct Veth {
         struct ether_addr *mac_peer;
 };
 
+DEFINE_NETDEV_CAST(VETH, Veth);
 extern const NetDevVTable veth_vtable;
index 1de6a1cc36fd41e03fb7523e57ecbc6d8207de31..73aacf4a0f8ae15f1825293d579b9bdc11fac3a6 100644 (file)
@@ -31,4 +31,5 @@ struct VLan {
         uint64_t id;
 };
 
+DEFINE_NETDEV_CAST(VLAN, VLan);
 extern const NetDevVTable vlan_vtable;
index dabbd97c87da24f30aa897abb1942e942178777a..724f9861be11455876045ecd5c02b93c4dcaa417 100644 (file)
 
 #include "conf-parser.h"
 #include "alloc-util.h"
+#include "extract-word.h"
 #include "parse-util.h"
 #include "missing.h"
+
 #include "networkd-link.h"
 #include "networkd-netdev-vxlan.h"
 
index a4bb44635a32d755333fc9996e8284ab5dabb8ad..4614c66fd1e132c4f40cb6ecdba1f157bb842127 100644 (file)
@@ -55,6 +55,7 @@ struct VxLan {
         struct ifla_vxlan_port_range port_range;
 };
 
+DEFINE_NETDEV_CAST(VXLAN, VxLan);
 extern const NetDevVTable vxlan_vtable;
 
 int config_parse_vxlan_group_address(const char *unit,
index 7ea825fcb460f5174b991933e21896fd61feb9b5..20244c03099801f02a1bc9cd2464809d8058b7e4 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "list.h"
-
-typedef struct NetDev NetDev;
-typedef struct NetDevVTable NetDevVTable;
+#include "sd-netlink.h"
 
-#include "networkd-link.h"
-#include "networkd.h"
+#include "list.h"
+#include "time-util.h"
 
 typedef struct netdev_join_callback netdev_join_callback;
+typedef struct Link Link;
 
 struct netdev_join_callback {
         sd_netlink_message_handler_t callback;
@@ -78,7 +76,10 @@ typedef enum NetDevCreateType {
         _NETDEV_CREATE_INVALID = -1,
 } NetDevCreateType;
 
-struct NetDev {
+typedef struct Manager Manager;
+typedef struct Condition Condition;
+
+typedef struct NetDev {
         Manager *manager;
 
         int n_ref;
@@ -99,20 +100,9 @@ struct NetDev {
         int ifindex;
 
         LIST_HEAD(netdev_join_callback, callbacks);
-};
+} NetDev;
 
-#include "networkd-netdev-bond.h"
-#include "networkd-netdev-bridge.h"
-#include "networkd-netdev-dummy.h"
-#include "networkd-netdev-ipvlan.h"
-#include "networkd-netdev-macvlan.h"
-#include "networkd-netdev-tunnel.h"
-#include "networkd-netdev-tuntap.h"
-#include "networkd-netdev-veth.h"
-#include "networkd-netdev-vlan.h"
-#include "networkd-netdev-vxlan.h"
-
-struct NetDevVTable {
+typedef struct NetDevVTable {
         /* How much memory does an object of this unit type need */
         size_t object_size;
 
@@ -144,14 +134,14 @@ struct NetDevVTable {
 
         /* verify that compulsory configuration options were specified */
         int (*config_verify)(NetDev *netdev, const char *filename);
-};
+} NetDevVTable;
 
 extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
 
 #define NETDEV_VTABLE(n) netdev_vtable[(n)->kind]
 
 /* For casting a netdev into the various netdev kinds */
-#define DEFINE_CAST(UPPERCASE, MixedCase)                                   \
+#define DEFINE_NETDEV_CAST(UPPERCASE, MixedCase)                            \
         static inline MixedCase* UPPERCASE(NetDev *n) {                     \
                 if (_unlikely_(!n || n->kind != NETDEV_KIND_##UPPERCASE))   \
                         return NULL;                                        \
@@ -162,27 +152,6 @@ extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
 /* For casting the various netdev kinds into a netdev */
 #define NETDEV(n) (&(n)->meta)
 
-DEFINE_CAST(BRIDGE, Bridge);
-DEFINE_CAST(BOND, Bond);
-DEFINE_CAST(VLAN, VLan);
-DEFINE_CAST(MACVLAN, MacVlan);
-DEFINE_CAST(MACVTAP, MacVlan);
-DEFINE_CAST(IPVLAN, IPVlan);
-DEFINE_CAST(VXLAN, VxLan);
-DEFINE_CAST(IPIP, Tunnel);
-DEFINE_CAST(GRE, Tunnel);
-DEFINE_CAST(GRETAP, Tunnel);
-DEFINE_CAST(IP6GRE, Tunnel);
-DEFINE_CAST(IP6GRETAP, Tunnel);
-DEFINE_CAST(SIT, Tunnel);
-DEFINE_CAST(VTI, Tunnel);
-DEFINE_CAST(VTI6, Tunnel);
-DEFINE_CAST(IP6TNL, Tunnel);
-DEFINE_CAST(VETH, Veth);
-DEFINE_CAST(DUMMY, Dummy);
-DEFINE_CAST(TUN, TunTap);
-DEFINE_CAST(TAP, TunTap);
-
 int netdev_load(Manager *manager);
 void netdev_drop(NetDev *netdev);
 
index 15417f48280f00ef3ab2eaced79b1691143dad79..9b8096f9aee3a8c2e5ebadd092350cb830544b93 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "sd-bus.h"
+#include "udev.h"
+
 #include "condition.h"
+#include "dhcp-identifier.h"
+#include "hashmap.h"
 #include "resolve-util.h"
 
-typedef struct Network Network;
-
-#include "dhcp-identifier.h"
 #include "networkd-address.h"
 #include "networkd-fdb.h"
 #include "networkd-netdev.h"
 #include "networkd-route.h"
 #include "networkd-util.h"
-#include "networkd.h"
 
 #define DHCP_ROUTE_METRIC 1024
 #define IPV4LL_ROUTE_METRIC 2048
@@ -67,6 +68,8 @@ typedef enum LLDPMode {
         _LLDP_MODE_INVALID = -1,
 } LLDPMode;
 
+typedef struct Manager Manager;
+
 struct Network {
         Manager *manager;
 
index a4a4bf265377b9c822c986dcd4f6becb04a2fc0a..59843162f037cee18ec5f5d845219660d1a141e4 100644 (file)
@@ -22,7 +22,6 @@
 typedef struct Route Route;
 
 #include "networkd-network.h"
-#include "networkd.h"
 
 struct Route {
         Network *network;
index 72a2438ac8db5d5f88fffe2c71448f3dffb30d80..39826a440de7e4221921ab03b866c40e84114dc0 100644 (file)
 #include "sd-bus.h"
 #include "sd-event.h"
 #include "sd-netlink.h"
+#include "udev.h"
 
+#include "dhcp-identifier.h"
 #include "hashmap.h"
 #include "list.h"
-#include "udev.h"
 
-typedef struct Manager Manager;
-
-#include "dhcp-identifier.h"
 #include "networkd-address-pool.h"
 #include "networkd-link.h"
+#include "networkd-netdev-bond.h"
+#include "networkd-netdev-bridge.h"
+#include "networkd-netdev-dummy.h"
+#include "networkd-netdev-ipvlan.h"
+#include "networkd-netdev-macvlan.h"
+#include "networkd-netdev-tunnel.h"
+#include "networkd-netdev-tuntap.h"
+#include "networkd-netdev-veth.h"
+#include "networkd-netdev-vlan.h"
+#include "networkd-netdev-vlan.h"
+#include "networkd-netdev-vxlan.h"
 #include "networkd-network.h"
 #include "networkd-util.h"
 
+extern const char* const network_dirs[];
+
 struct Manager {
         sd_netlink *rtnl;
         sd_event *event;
@@ -71,10 +82,6 @@ struct Manager {
         uint8_t dhcp_duid[MAX_DUID_LEN];
 };
 
-extern const char* const network_dirs[];
-
-/* Manager */
-
 extern const sd_bus_vtable manager_vtable[];
 
 int manager_new(Manager **ret);