From: Zbigniew Jędrzejewski-Szmek Date: Wed, 2 Jan 2019 13:30:24 +0000 (+0100) Subject: udev,network: use standard paths for .network and .link files X-Git-Tag: v242-rc1~295^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc0d40785141aeb5a11cfccd03b236703554b42e;p=thirdparty%2Fsystemd.git udev,network: use standard paths for .network and .link files This centralizes the configuration to one header file. /usr/local/lib is now included in the search list, and documentation is updated accordingly. --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 1a026727134..fc2ac4b505b 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -37,17 +37,17 @@ The main network file must have the extension .network; other extensions are ignored. Networks are applied to links whenever the links appear. - The .network files are read from the files located in the system - network directory /usr/lib/systemd/network, the volatile runtime network - directory /run/systemd/network and the local administration network - directory /etc/systemd/network. All configuration files are collectively - sorted and processed in lexical order, regardless of the directories in which they live. - However, files with identical filenames replace each other. Files in /etc - have the highest priority, files in /run take precedence over files with - the same name in /usr/lib. This can be used to override a system-supplied - configuration file with a local file if needed. As a special case, an empty file (file size 0) - or symlink with the same name pointing to /dev/null disables the - configuration file entirely (it is "masked"). + The .network files are read from the files located in the system network + directories /usr/lib/systemd/network and + /usr/local/lib/systemd/network, the volatile runtime network directory + /run/systemd/network and the local administration network directory + /etc/systemd/network. All configuration files are collectively sorted and processed + in lexical order, regardless of the directories in which they live. However, files with identical + filenames replace each other. Files in /etc have the highest priority, files in + /run take precedence over files with the same name under + /usr. This can be used to override a system-supplied configuration file with a local + file if needed. As a special case, an empty file (file size 0) or symlink with the same name pointing to + /dev/null disables the configuration file entirely (it is "masked"). Along with the network file foo.network, a "drop-in" directory foo.network.d/ may exist. All files with the suffix @@ -60,9 +60,7 @@ /run/systemd/network directories. Drop-in files in /etc take precedence over those in /run which in turn take precedence over those in /usr/lib. Drop-in files under any of these - directories take precedence over the main netdev file wherever located. (Of course, since - /run is temporary and /usr/lib is for vendors, it is - unlikely drop-ins should be used in either of those places.) + directories take precedence over the main netdev file wherever located. Note that an interface without any static IPv6 addresses configured, and neither DHCPv6 nor IPv6LL enabled, shall be considered to have no IPv6 support. IPv6 will be automatically diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h index 0c8da848c16..96623e6f097 100644 --- a/src/libsystemd-network/network-internal.h +++ b/src/libsystemd-network/network-internal.h @@ -8,7 +8,9 @@ #include "condition.h" #include "conf-parser.h" +#include "def.h" #include "set.h" +#include "strv.h" #define LINK_BRIDGE_PORT_PRIORITY_INVALID 128 #define LINK_BRIDGE_PORT_PRIORITY_MAX 63 @@ -54,3 +56,5 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t /* It is not necessary to add deserialize_dhcp_option(). Use unhexmem() instead. */ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size); + +#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network")) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 02639174687..1ad13b81a87 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -661,7 +661,7 @@ int netdev_load_one(Manager *manager, const char *filename) { }; dropin_dirname = strjoina(basename(filename), ".d"); - r = config_parse_many(filename, network_dirs, dropin_dirname, + r = config_parse_many(filename, NETWORK_DIRS, dropin_dirname, "Match\0NetDev\0", config_item_perf_lookup, network_netdev_gperf_lookup, CONFIG_PARSE_WARN|CONFIG_PARSE_RELAXED, netdev_raw); @@ -702,7 +702,7 @@ int netdev_load_one(Manager *manager, const char *filename) { if (NETDEV_VTABLE(netdev)->init) NETDEV_VTABLE(netdev)->init(netdev); - r = config_parse_many(filename, network_dirs, dropin_dirname, + r = config_parse_many(filename, NETWORK_DIRS, dropin_dirname, NETDEV_VTABLE(netdev)->sections, config_item_perf_lookup, network_netdev_gperf_lookup, CONFIG_PARSE_WARN, netdev); @@ -802,7 +802,7 @@ int netdev_load(Manager *manager) { hashmap_clear_with_destructor(manager->netdevs, netdev_unref); - r = conf_files_list_strv(&files, ".netdev", NULL, 0, network_dirs); + r = conf_files_list_strv(&files, ".netdev", NULL, 0, NETWORK_DIRS); if (r < 0) return log_error_errno(r, "Failed to enumerate netdev files: %m"); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index c8d369e2a0f..cf8aca3b29a 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -18,6 +18,7 @@ #include "fileio.h" #include "local-addresses.h" #include "netlink-util.h" +#include "network-internal.h" #include "networkd-manager.h" #include "ordered-set.h" #include "path-util.h" @@ -29,15 +30,6 @@ /* use 8 MB for receive socket kernel queue. */ #define RCVBUF_SIZE (8*1024*1024) -const char* const network_dirs[] = { - "/etc/systemd/network", - "/run/systemd/network", - "/usr/lib/systemd/network", -#if HAVE_SPLIT_USR - "/lib/systemd/network", -#endif - NULL}; - static int setup_default_address_pool(Manager *m) { AddressPool *p; int r; @@ -1485,7 +1477,7 @@ int manager_load_config(Manager *m) { int r; /* update timestamp */ - paths_check_timestamp(network_dirs, &m->network_dirs_ts_usec, true); + paths_check_timestamp(NETWORK_DIRS, &m->network_dirs_ts_usec, true); r = netdev_load(m); if (r < 0) @@ -1499,7 +1491,7 @@ int manager_load_config(Manager *m) { } bool manager_should_reload(Manager *m) { - return paths_check_timestamp(network_dirs, &m->network_dirs_ts_usec, false); + return paths_check_timestamp(NETWORK_DIRS, &m->network_dirs_ts_usec, false); } int manager_rtnl_enumerate_links(Manager *m) { diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 289ca962165..33f80bf19f5 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -18,8 +18,6 @@ #include "networkd-link.h" #include "networkd-network.h" -extern const char* const network_dirs[]; - struct Manager { sd_netlink *rtnl; /* lazy initialized */ diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 2d233223786..04ab5291084 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -211,7 +211,7 @@ int network_load_one(Manager *manager, const char *filename) { .ipv6_accept_ra_route_table = RT_TABLE_MAIN, }; - r = config_parse_many(filename, network_dirs, dropin_dirname, + r = config_parse_many(filename, NETWORK_DIRS, dropin_dirname, "Match\0" "Link\0" "Network\0" @@ -291,7 +291,7 @@ int network_load(Manager *manager) { while ((network = manager->networks)) network_free(network); - r = conf_files_list_strv(&files, ".network", NULL, 0, network_dirs); + r = conf_files_list_strv(&files, ".network", NULL, 0, NETWORK_DIRS); if (r < 0) return log_error_errno(r, "Failed to enumerate network files: %m"); diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 60da08a86ff..52a697e9f21 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -8,6 +8,7 @@ #include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" +#include "def.h" #include "device-util.h" #include "ethtool-util.h" #include "fd-util.h" @@ -36,18 +37,9 @@ struct link_config_ctx { sd_netlink *rtnl; - usec_t link_dirs_ts_usec; + usec_t network_dirs_ts_usec; }; -static const char* const link_dirs[] = { - "/etc/systemd/network", - "/run/systemd/network", - "/usr/lib/systemd/network", -#if HAVE_SPLIT_USR - "/lib/systemd/network", -#endif - NULL}; - static void link_config_free(link_config *link) { if (!link) return; @@ -216,9 +208,9 @@ int link_config_load(link_config_ctx *ctx) { } /* update timestamp */ - paths_check_timestamp(link_dirs, &ctx->link_dirs_ts_usec, true); + paths_check_timestamp(NETWORK_DIRS, &ctx->network_dirs_ts_usec, true); - r = conf_files_list_strv(&files, ".link", NULL, 0, link_dirs); + r = conf_files_list_strv(&files, ".link", NULL, 0, NETWORK_DIRS); if (r < 0) return log_error_errno(r, "failed to enumerate link files: %m"); @@ -232,7 +224,7 @@ int link_config_load(link_config_ctx *ctx) { } bool link_config_should_reload(link_config_ctx *ctx) { - return paths_check_timestamp(link_dirs, &ctx->link_dirs_ts_usec, false); + return paths_check_timestamp(NETWORK_DIRS, &ctx->network_dirs_ts_usec, false); } int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret) {