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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-01-02 14:30:24 +01:00
parent eb5f4dde96
commit dc0d407851
7 changed files with 29 additions and 45 deletions

View file

@ -37,17 +37,17 @@
<para>The main network file must have the extension <filename>.network</filename>; other <para>The main network file must have the extension <filename>.network</filename>; other
extensions are ignored. Networks are applied to links whenever the links appear.</para> extensions are ignored. Networks are applied to links whenever the links appear.</para>
<para>The <filename>.network</filename> files are read from the files located in the system <para>The <filename>.network</filename> files are read from the files located in the system network
network directory <filename>/usr/lib/systemd/network</filename>, the volatile runtime network directories <filename>/usr/lib/systemd/network</filename> and
directory <filename>/run/systemd/network</filename> and the local administration network <filename>/usr/local/lib/systemd/network</filename>, the volatile runtime network directory
directory <filename>/etc/systemd/network</filename>. All configuration files are collectively <filename>/run/systemd/network</filename> and the local administration network directory
sorted and processed in lexical order, regardless of the directories in which they live. <filename>/etc/systemd/network</filename>. All configuration files are collectively sorted and processed
However, files with identical filenames replace each other. Files in <filename>/etc</filename> in lexical order, regardless of the directories in which they live. However, files with identical
have the highest priority, files in <filename>/run</filename> take precedence over files with filenames replace each other. Files in <filename>/etc</filename> have the highest priority, files in
the same name in <filename>/usr/lib</filename>. This can be used to override a system-supplied <filename>/run</filename> take precedence over files with the same name under
configuration file with a local file if needed. As a special case, an empty file (file size 0) <filename>/usr</filename>. This can be used to override a system-supplied configuration file with a local
or symlink with the same name pointing to <filename>/dev/null</filename> disables the file if needed. As a special case, an empty file (file size 0) or symlink with the same name pointing to
configuration file entirely (it is "masked").</para> <filename>/dev/null</filename> disables the configuration file entirely (it is "masked").</para>
<para>Along with the network file <filename>foo.network</filename>, a "drop-in" directory <para>Along with the network file <filename>foo.network</filename>, a "drop-in" directory
<filename>foo.network.d/</filename> may exist. All files with the suffix <filename>foo.network.d/</filename> may exist. All files with the suffix
@ -60,9 +60,7 @@
<filename>/run/systemd/network</filename> directories. Drop-in files in <filename>/run/systemd/network</filename> directories. Drop-in files in
<filename>/etc</filename> take precedence over those in <filename>/run</filename> which in turn <filename>/etc</filename> take precedence over those in <filename>/run</filename> which in turn
take precedence over those in <filename>/usr/lib</filename>. Drop-in files under any of these take precedence over those in <filename>/usr/lib</filename>. Drop-in files under any of these
directories take precedence over the main netdev file wherever located. (Of course, since directories take precedence over the main netdev file wherever located.</para>
<filename>/run</filename> is temporary and <filename>/usr/lib</filename> is for vendors, it is
unlikely drop-ins should be used in either of those places.)</para>
<para>Note that an interface without any static IPv6 addresses configured, and neither DHCPv6 <para>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 nor IPv6LL enabled, shall be considered to have no IPv6 support. IPv6 will be automatically

View file

@ -8,7 +8,9 @@
#include "condition.h" #include "condition.h"
#include "conf-parser.h" #include "conf-parser.h"
#include "def.h"
#include "set.h" #include "set.h"
#include "strv.h"
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128 #define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63 #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. */ /* 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); 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"))

View file

@ -661,7 +661,7 @@ int netdev_load_one(Manager *manager, const char *filename) {
}; };
dropin_dirname = strjoina(basename(filename), ".d"); 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", "Match\0NetDev\0",
config_item_perf_lookup, network_netdev_gperf_lookup, config_item_perf_lookup, network_netdev_gperf_lookup,
CONFIG_PARSE_WARN|CONFIG_PARSE_RELAXED, netdev_raw); 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) if (NETDEV_VTABLE(netdev)->init)
NETDEV_VTABLE(netdev)->init(netdev); 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, NETDEV_VTABLE(netdev)->sections,
config_item_perf_lookup, network_netdev_gperf_lookup, config_item_perf_lookup, network_netdev_gperf_lookup,
CONFIG_PARSE_WARN, netdev); CONFIG_PARSE_WARN, netdev);
@ -802,7 +802,7 @@ int netdev_load(Manager *manager) {
hashmap_clear_with_destructor(manager->netdevs, netdev_unref); 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) if (r < 0)
return log_error_errno(r, "Failed to enumerate netdev files: %m"); return log_error_errno(r, "Failed to enumerate netdev files: %m");

View file

@ -18,6 +18,7 @@
#include "fileio.h" #include "fileio.h"
#include "local-addresses.h" #include "local-addresses.h"
#include "netlink-util.h" #include "netlink-util.h"
#include "network-internal.h"
#include "networkd-manager.h" #include "networkd-manager.h"
#include "ordered-set.h" #include "ordered-set.h"
#include "path-util.h" #include "path-util.h"
@ -29,15 +30,6 @@
/* use 8 MB for receive socket kernel queue. */ /* use 8 MB for receive socket kernel queue. */
#define RCVBUF_SIZE (8*1024*1024) #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) { static int setup_default_address_pool(Manager *m) {
AddressPool *p; AddressPool *p;
int r; int r;
@ -1485,7 +1477,7 @@ int manager_load_config(Manager *m) {
int r; int r;
/* update timestamp */ /* 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); r = netdev_load(m);
if (r < 0) if (r < 0)
@ -1499,7 +1491,7 @@ int manager_load_config(Manager *m) {
} }
bool manager_should_reload(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) { int manager_rtnl_enumerate_links(Manager *m) {

View file

@ -18,8 +18,6 @@
#include "networkd-link.h" #include "networkd-link.h"
#include "networkd-network.h" #include "networkd-network.h"
extern const char* const network_dirs[];
struct Manager { struct Manager {
sd_netlink *rtnl; sd_netlink *rtnl;
/* lazy initialized */ /* lazy initialized */

View file

@ -211,7 +211,7 @@ int network_load_one(Manager *manager, const char *filename) {
.ipv6_accept_ra_route_table = RT_TABLE_MAIN, .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" "Match\0"
"Link\0" "Link\0"
"Network\0" "Network\0"
@ -291,7 +291,7 @@ int network_load(Manager *manager) {
while ((network = manager->networks)) while ((network = manager->networks))
network_free(network); 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) if (r < 0)
return log_error_errno(r, "Failed to enumerate network files: %m"); return log_error_errno(r, "Failed to enumerate network files: %m");

View file

@ -8,6 +8,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "conf-files.h" #include "conf-files.h"
#include "conf-parser.h" #include "conf-parser.h"
#include "def.h"
#include "device-util.h" #include "device-util.h"
#include "ethtool-util.h" #include "ethtool-util.h"
#include "fd-util.h" #include "fd-util.h"
@ -36,18 +37,9 @@ struct link_config_ctx {
sd_netlink *rtnl; 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) { static void link_config_free(link_config *link) {
if (!link) if (!link)
return; return;
@ -216,9 +208,9 @@ int link_config_load(link_config_ctx *ctx) {
} }
/* update timestamp */ /* 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) if (r < 0)
return log_error_errno(r, "failed to enumerate link files: %m"); 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) { 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) { int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret) {