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

nixos/networkd: Set Gateway= in [Network] section instead of [Route] #93589

Closed
wants to merge 0 commits into from

Conversation

duairc
Copy link
Contributor

@duairc duairc commented Jul 21, 2020

Motivation for this change

On any NixOS system I've used with networking.useNetworkd enabled, I've never been able to set gateways without manually adding the route in systemd.network.networks."40-eth0".routes. However, nixos/modules/tasks/network-interfaces-systemd.nix does seem to try to read the values of network.defaultGateway{,6}.address and add them to the network definition. The way it does it, you end up with a section like this in your network definition:

[Route]
Gateway=192.168.0.1
Gateway=dead:beef::1
GatewayOnLink=false

I'm not sure if this is expected to work or not, but in my experience, it doesn't. This PR changes it so that you end up with this instead, with separate sections for the IPv4 and IPv6 gateways:

[Route]
Gateway=192.168.0.1
GatewayOnLink=false

[Route]
Gateway=dead:beef::1
GatewayOnLink=false

This works for me.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@duairc
Copy link
Contributor Author

duairc commented Jul 21, 2020

I think I might know how this came about. If you read the man page for systemd.network(5), it lists two different Gateway= options. The first one is in the [Network] block:

Gateway=
The gateway address, which must be in the format described in inet_pton(3). This is a short-hand for a [Route] section only containing a Gateway key. This option may be specified more than once.

The second one is in the [Route] block (which is what this code sets):

Gateway=
Takes the gateway address or special value "_dhcp". If "_dhcp", then the gateway address provided by DHCP (or in the IPv6 case, provided by IPv6 RA) is used.

Notably, it doesn't say anything about being able to be specified multiple times. In addition, the top-level documentation for [Route] says "The [Route] section accepts the following keys. Specify several [Route] sections to configure several routes."

So it seems that the existing code is indeed wrong and that this fix makes sense.

The other alternative would be for NixOS to set the Gateway= option in the [Network] section instead, which may have been the original intention from reading the documentation. The GatewayOnLink=false bit seems unnecessary too because false is the default anyway.

@duairc duairc force-pushed the systemd-networkd-gateways branch from 8cdf659 to 38b7f06 Compare July 21, 2020 15:54
@duairc duairc changed the title networkd: Add a separate routeConfig section for each gateway nixos/networkd: Set Gateway= in [Network] section instead of [Route] Jul 21, 2020
@duairc
Copy link
Contributor Author

duairc commented Jul 21, 2020

I updated this pull request to set Gateway= in the [Network] section instead. I've tested it and it fixes the problem and also produces a cleaner .network file.

@duairc duairc force-pushed the systemd-networkd-gateways branch from 38b7f06 to 6d32ea3 Compare July 22, 2020 09:37
@duairc duairc marked this pull request as draft July 22, 2020 10:04
@duairc duairc marked this pull request as ready for review July 22, 2020 10:26
@stale
Copy link

stale bot commented Jun 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 26, 2021
@duairc duairc force-pushed the systemd-networkd-gateways branch from f526304 to bb0bb3b Compare April 6, 2022 19:03
@duairc duairc closed this Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 0 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant