summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Sébastien Bour <jean-sebastien@bour.name>2016-07-09 16:55:26 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-16 10:31:58 -0400
commit047a0dacde06740050858d72c385cc07a4091feb (patch)
treed9be3919a2413d9f9c6452e675764834a419d5bd
parent38d78d1ee9f967aecda14a1c80cd664a66b976c7 (diff)
downloadsystemd-047a0dacde06740050858d72c385cc07a4091feb.tar.gz
networkd: support drop-in directories for .network files
Fixes #3655. [zj: Fix the tests.]
-rw-r--r--src/network/networkd-network.c18
-rwxr-xr-xtest/networkd-test.py30
2 files changed, 46 insertions, 2 deletions
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 49faba5b12..0b36f13be8 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -40,6 +40,10 @@ static int network_load_one(Manager *manager, const char *filename) {
_cleanup_network_free_ Network *network = NULL;
_cleanup_fclose_ FILE *file = NULL;
char *d;
+ const char *dropin_dirname;
+ _cleanup_strv_free_ char **dropin_dirs = NULL;
+ _cleanup_free_ char *dropin_dirs_nulstr = NULL;
+ size_t dropin_dirs_nulstr_size;
Route *route;
Address *address;
int r;
@@ -137,7 +141,17 @@ static int network_load_one(Manager *manager, const char *filename) {
network->arp = -1;
network->ipv6_accept_ra_use_dns = true;
- r = config_parse(NULL, filename, file,
+ dropin_dirname = strjoina("/", network->name, ".network.d");
+
+ r = strv_extend_strv_concat(&dropin_dirs, (char**) network_dirs, dropin_dirname);
+ if (r < 0)
+ return r;
+
+ r = strv_make_nulstr(dropin_dirs, &dropin_dirs_nulstr, &dropin_dirs_nulstr_size);
+ if (r < 0)
+ return r;
+
+ r = config_parse_many(filename, dropin_dirs_nulstr,
"Match\0"
"Link\0"
"Network\0"
@@ -151,7 +165,7 @@ static int network_load_one(Manager *manager, const char *filename) {
"BridgeFDB\0"
"BridgeVLAN\0",
config_item_perf_lookup, network_network_gperf_lookup,
- false, false, true, network);
+ false, network);
if (r < 0)
return r;
diff --git a/test/networkd-test.py b/test/networkd-test.py
index 57f4c04295..baa1dc2a47 100755
--- a/test/networkd-test.py
+++ b/test/networkd-test.py
@@ -456,6 +456,36 @@ Domains={p}0 {p}1 {p}2 {p}3 {p}4'''.format(p=name_prefix))
self.assertRegex(contents, 'search .*{p}0 {p}1 {p}2'.format(p=name_prefix))
self.assertIn('# Total length of all search domains is too long, remaining ones ignored.', contents)
+ def test_dropin(self):
+ # we don't use this interface for this test
+ self.if_router = None
+
+ self.writeConfig('/run/systemd/network/test.netdev', '''\
+[NetDev]
+Name=dummy0
+Kind=dummy
+MACAddress=12:34:56:78:9a:bc''')
+ self.writeConfig('/run/systemd/network/test.network', '''\
+[Match]
+Name=dummy0
+[Network]
+Address=192.168.42.100
+DNS=192.168.42.1''')
+ self.writeConfig('/run/systemd/network/test.network.d/dns.conf', '''\
+[Network]
+DNS=127.0.0.1''')
+
+ subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+
+ for timeout in range(50):
+ with open(RESOLV_CONF) as f:
+ contents = f.read()
+ if ' 127.0.0.1' in contents:
+ break
+ time.sleep(0.1)
+ self.assertIn('nameserver 192.168.42.1\n', contents)
+ self.assertIn('nameserver 127.0.0.1\n', contents)
+
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
verbosity=2))