Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networkd: surprising behaviour of .network files with only commented content #717

Closed
puleglot opened this issue Jul 24, 2015 · 8 comments
Closed
Labels

Comments

@puleglot
Copy link
Contributor

If network config contains only empty and/or commented out lines, then networkd begins to manage all interfaces:

$ sudo networkctl --all
IDX LINK             TYPE               OPERATIONAL SETUP     
  1 lo               loopback           carrier     unmanaged 
  2 tunl0            tunnel             off         unmanaged 
  3 sit0             sit                off         unmanaged 
  4 ip6tnl0          tunnel6            off         unmanaged 
  5 wlp12s0          wlan               routable    unmanaged 
  6 enp9s0           ether              no-carrier  unmanaged 

6 links listed.
$ sudo touch /etc/systemd/network/foo.network
$ sudo systemctl restart systemd-networkd.service
$ sudo networkctl --all
IDX LINK             TYPE               OPERATIONAL SETUP     
  1 lo               loopback           carrier     unmanaged 
  2 tunl0            tunnel             off         unmanaged 
  3 sit0             sit                off         unmanaged 
  4 ip6tnl0          tunnel6            off         unmanaged 
  5 wlp12s0          wlan               routable    unmanaged 
  6 enp9s0           ether              no-carrier  unmanaged 

6 links listed.
$ echo | sudo tee /etc/systemd/network/foo.network 

$ sudo systemctl restart systemd-networkd.service
$ sudo networkctl --all
IDX LINK             TYPE               OPERATIONAL SETUP     
  1 lo               loopback           carrier     configured
  2 tunl0            tunnel             carrier     configured
  3 sit0             sit                routable    configured
  4 ip6tnl0          tunnel6            degraded    configured
  5 wlp12s0          wlan               routable    configured
  6 enp9s0           ether              no-carrier  configured

6 links listed.

Real world example of problematic network config:

$ cat /etc/systemd/network/enp3s0.network 
#[Match]
#Name=enp3s0

#[Network]
#Address=192.168.1.5/24
#Gateway=192.168.1.1
#DNS=192.168.1.1
@poettering
Copy link
Member

Well. That's really expected behaviour. An empty .network file means a file with an empty match section and default settings for everything. An empty match section means it applies to every interface. hence you get the behaviour you are seeing.

It probably would make sense to document this as a caveat though, since it is indeed surprising at first.

@puleglot
Copy link
Contributor Author

Yes, I understand this. But an empty (zero sized) .network file actually gets skipped by network_load_one(). TBH, this behaviour is not consistent. :)

@keszybz
Copy link
Member

keszybz commented Jul 25, 2015

@puleglot empty network files are a special case of a general rule in systemd: empty files and symlinks to /dev/null are used to "mask" a file. This is (partially) documented in network.network(5).

OTOH, I understand how the case of fully commented-out files can be confusing. It would be nice to at least emit a warning in this case.

(If I have a file with [Match] Name=a* Name=b_, I'll match two interfaces. If I have a file with [Match] Name=a_, I'll match one interface. But then if I have a file with [Match], all interfaces will be matched.)

keszybz added a commit to keszybz/systemd that referenced this issue Jul 25, 2015
This should clear up some confusion in
systemd#717.

This basically copies the description from systemd.unit to this
man page. Masking can happen also in /run, so strike the part
about /etc, and also add the magic work "mask".
keszybz added a commit to keszybz/systemd that referenced this issue Jul 25, 2015
@puleglot
Copy link
Contributor Author

Refusing .network files with an empty [Match] section is a good idea IMHO. It really should be a required section.

@zonque zonque added the network label Jul 26, 2015
@poettering
Copy link
Member

I would warn, but not refuse I must say.

@poettering poettering changed the title networkd: network config parser bug? networkd: surprising behaviour of .network files with only commented content Jul 27, 2015
zv added a commit to zv/systemd that referenced this issue Jul 30, 2015
zv added a commit to zv/systemd that referenced this issue Jul 30, 2015
Warn user of completely commented .network file behavior
systemd#717
@teg teg closed this as completed Feb 22, 2016
Yamakuzure pushed a commit to elogind/elogind that referenced this issue Jan 3, 2017
This should clear up some confusion in
systemd/systemd#717.

This basically copies the description from systemd.unit to this
man page. Masking can happen also in /run, so strike the part
about /etc, and also add the magic work "mask".
@dkg
Copy link
Contributor

dkg commented May 27, 2019

the fact that someone as experienced as @kesyzbz could "get bit" by this problem (see #9895) suggests that the problem is in fact in the codebase and not in the user.

a non-empty .network file with no [Match] section and no other section should either be treated the same way as an empty file, or it should be treated as an error and ignored (probably, warnings should be emitted either way).

Fixing this would provide sensible guard-rails to any reasonable system administrator, and removes no functionality, because an administrator who wants this particular (very odd) behavior of configuring nothing but matching on all interfaces can always explicitly create universally-matching config file with something like this:

[Match]
Name=*

Please consider making systemd less user-hostile in this case.

@keszybz
Copy link
Member

keszybz commented May 28, 2019

We now emit a warning if no matches are found, see 84ea567. This opens the possibility to turn it into an error a few releases down the road.

keszybz added a commit to keszybz/systemd that referenced this issue Feb 4, 2020
Two releases ago we started warning about this, and I think it is now to turn
this into a hard error. People get bitten by this every once in a while, and
there doesn't see to be any legitimate use case where the same .link or
.network files should be applied to _all_ interfaces, since in particular that
configuration would apply both to lo and any other interfaces. And if for
whatever reason that is actually desired, OriginalName=* or Name=* can be
easily added to silence the warning and achieve the effect.

(The case described in systemd#12098 is particularly nasty: 'echo -n >foo.network'
creates a mask file, 'echo >foo.network' creates a "match all" file.)

Fixes systemd#717, systemd#12098 for realz now.
@sebunger
Copy link

This broke compatibility with netplan! Now you cannot configure networkd to configure all interfaces through DHCP4 via netplan anymore because netplan refuses a simple * as a name glob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants