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: disallow useDHCP #69302

Merged
merged 4 commits into from Oct 7, 2019
Merged

Conversation

globin
Copy link
Member

@globin globin commented Sep 23, 2019

Motivation for this change

This is preparation to switch to networkd by default in 20.03
Also intended for 19.09, does not change anything in the default config.

Things done
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @fpletz @flokli @arianvp @disassembler @lheckemann

@globin globin changed the title networkd: disallow dhcp networkd: disallow useDHCP Sep 23, 2019
@fpletz fpletz self-requested a review September 23, 2019 19:30
@fpletz
Copy link
Member

fpletz commented Sep 23, 2019

@volth Thanks for the hint. I would prefer to add a boot.initrd.network.useDHCP or something under boot.initrd.network.udhcpc. for that use case if needed. But are you really running networkd with networking.useDHCP enabled so that this becomes a real issue?

Note that this module already invokes udhcpc for interfaces that have useDHCP explicitly set, which is also the way we plan to move forward.

Also note that initrd-network does neither use our scripted networking nor dhcpcd as we do later in the running system anyway. So for now I see no immediate reason to change the initrd-network to networkd even if we switch to it by default in stage2.

@fpletz
Copy link
Member

fpletz commented Sep 23, 2019

@globin @andir Regarding 2b605e9, with this change we also can remove the 99-main.network hack altogether.

As mentioned elsewhere this functionality is inherently broken without manually poking around some other network units anyway; for example to make stuff like network-online.target work if you have more than one interface on your system (e.g. RequiredForOnline=).

@fpletz fpletz requested a review from andir September 23, 2019 20:47
@globin
Copy link
Member Author

globin commented Sep 24, 2019

Added release notes and information to the option docs.

@@ -903,6 +903,11 @@ in
Whether to use DHCP to obtain an IP address and other
configuration for all network interfaces that are not manually
configured.

Using this option is highly discouraged and also incompatible with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a bit far fetched but how do we plan to proceed with installer images if we discourage usage of this? Wouldn't it be best practice to ship the installer with an encouraged configuration? We should be a good example to users and not just tell them to not use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently working on this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does networking.interfaces."en*".useDHCP = true work? reason I ask is because setting a wildcard for matchConfig is supported for networkd.

I guess then for the installer image we can then set networking.interfaces."en*".useDHCP = true to get an IP address on all wired connections (seems like a sane default), but it won't try to ask for DHCP leases on bridges, veths etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we shouldn't solve this in this PR.

Copy link
Member Author

@globin globin Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andir I understood your comment as changing nixos-generate-config, from the conversation I've just had with @fpletz he misunderstood this, so I've added a commit to change nixos-generate-config. It adds networking.useDHCP = false; and adds networking.interfaces.<name>.useDHCP = true; for all interfaces is /sys/class/net except for lo. Virtual interfaces should not be present in our install media anyway.

This setting will be removed with the switch to systemd-networkd. The
use of per interface config is encouraged instead.
This sets networking.useDHCP to false and for all interfaces found the
per-interface useDHCP to true. This replicates the current default
behaviour and prepares for the switch to networkd.
@@ -72,6 +72,7 @@ let
testCases = {
loopback = {
name = "Loopback";
machine.networking.useDHCP = false;
Copy link
Contributor

@flokli flokli Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just strip all lines setting networking.useDHCP = false; in the tests, if we set it for each interface?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now assert useDHCP to be false in conjunction with networkd, I didn't want to change the whole test suite that for the most part doesn't use networkd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair - I misread and assumed these change networkd-based tests…

I meant to refer to any networkd-based tests hardcoding machine.networking.useDHCP.

@lheckemann
Copy link
Member

@GrahamcOfBorg test networking ipv6

@lheckemann lheckemann merged commit 0b754fb into NixOS:master Oct 7, 2019
@lheckemann lheckemann deleted the networkd-disallow-dhcp branch October 7, 2019 09:29
@lheckemann
Copy link
Member

Backported: 907bb84 da9e914 1cb925e

devhell added a commit to openlab-aux/vuizvui that referenced this pull request Oct 8, 2019
This addresses a new assertion to the way NixOS handles networks with
networkd [1].

As a result this disables `networking.useDHCP` globally on all my
machines. Explicit interface configuration, as requested by [1] will be
handled in separate commits due to separate machines, not all of which I
have access to right now.

[1] NixOS/nixpkgs#69302
devhell added a commit to openlab-aux/vuizvui that referenced this pull request Oct 8, 2019
Explicitly enable DHCP on interfaces as requested in [1].

[1]: NixOS/nixpkgs#69302
@lheckemann
Copy link
Member

Looks like I was a bit hasty with merging this — it broke evaluation for the networkd variant of the networking.virtual test.

aszlig added a commit to openlab-aux/vuizvui that referenced this pull request Oct 8, 2019
The usage of DHCP is no longer global since a while[1] and we now have
to explicitly enable it for the interfaces in question.

This actually is a good thing and makes it far less problematic if we
use tunnel interfaces and other more complicated networking
configuration.

I added the definitions for all machines where I actually know which
interfaces are in use and disabled useNetworkd for shakti, because I
don't know the interface names for that machine and the machine
currently isn't in use anyway, so we can add it later if needed.

[1]: NixOS/nixpkgs#69302

Signed-off-by: aszlig <aszlig@nix.build>
@arianvp
Copy link
Member

arianvp commented Oct 14, 2019

@lheckemann does that mean you reverted those changes for 19.09 or are they still in?

@globin
Copy link
Member Author

globin commented Oct 15, 2019

They are included. The test never ran with networkd, I simply added the useNetworkd = networkd and the failing test probably is a valid issue with our networkd config.

@lheckemann
Copy link
Member

@arianvp I fixed the evaluation but not the test, 4a03ddd

@matthewbauer
Copy link
Member

I think this makes hotplugging network devices difficult. The interface name is different depending on which port you have. It takes a long time to boot up if it is missing too (1 min 30 sec by default).

@Ma27
Copy link
Member

Ma27 commented Dec 27, 2020

Not sure if I misunderstand you, but can't you use wildcards for that purpose in networkd? With scripted networking, this is still supported IIRC.

@lheckemann
Copy link
Member

Concretely for the networkd case:

{
    systemd.network.networks."99-en-dhcp" = {
      matchConfig.Name = "en*";
      networkConfig.DHCP = "yes";
    };
}

to get DHCP on all ethernet devices.

@matthewbauer
Copy link
Member

@lheckemann Thanks! That helps.

Does nixos-generate-config (https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/tools/nixos-generate-config.pl#L570-L586) need to hardcode these interfaces at all then? If one of those interfaces no longer exists, you get stuck waiting for "network-addresses-en*" or "network-addresses-wl*" to finish (or timeout at 1m 30s) as part of network-setup.service. This could happen frequently if you're switching between ethernet and wifi but have a USB adapter.

@arianvp
Copy link
Member

arianvp commented Dec 29, 2020

A wildcard sounds fine to me instead of a fixed interface

@lheckemann
Copy link
Member

The problem with that approach is that it doesn't work with scripted networking, which is still our default.

@matthewbauer
Copy link
Member

Opened #107908 to track this.

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

Successfully merging this pull request may close these issues.

None yet

10 participants