mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/networkd: Add routes from interfaces to [Route] section of .network file
Closes https://github.com/NixOS/nixpkgs/pull/93635.
This commit is contained in:
parent
fde7c9d409
commit
ca58bd0a50
5 changed files with 97 additions and 1 deletions
|
@ -12,6 +12,10 @@ let
|
|||
i.ipv4.addresses
|
||||
++ optionals cfg.enableIPv6 i.ipv6.addresses;
|
||||
|
||||
interfaceRoutes = i:
|
||||
i.ipv4.routes
|
||||
++ optionals cfg.enableIPv6 i.ipv6.routes;
|
||||
|
||||
dhcpStr = useDHCP: if useDHCP == true || useDHCP == null then "yes" else "no";
|
||||
|
||||
slaves =
|
||||
|
@ -94,6 +98,63 @@ in
|
|||
(if i.useDHCP != null then i.useDHCP else false));
|
||||
address = forEach (interfaceIps i)
|
||||
(ip: "${ip.address}/${toString ip.prefixLength}");
|
||||
routes = forEach (interfaceRoutes i)
|
||||
(route: {
|
||||
# Most of these route options have not been tested.
|
||||
# Please fix or report any mistakes you may find.
|
||||
routeConfig =
|
||||
optionalAttrs (route.prefixLength > 0) {
|
||||
Destination = "${route.address}/${toString route.prefixLength}";
|
||||
} //
|
||||
optionalAttrs (route.options ? fastopen_no_cookie) {
|
||||
FastOpenNoCookie = route.options.fastopen_no_cookie;
|
||||
} //
|
||||
optionalAttrs (route.via != null) {
|
||||
Gateway = route.via;
|
||||
} //
|
||||
optionalAttrs (route.options ? onlink) {
|
||||
GatewayOnLink = true;
|
||||
} //
|
||||
optionalAttrs (route.options ? initrwnd) {
|
||||
InitialAdvertisedReceiveWindow = route.options.initrwnd;
|
||||
} //
|
||||
optionalAttrs (route.options ? initcwnd) {
|
||||
InitialCongestionWindow = route.options.initcwnd;
|
||||
} //
|
||||
optionalAttrs (route.options ? pref) {
|
||||
IPv6Preference = route.options.pref;
|
||||
} //
|
||||
optionalAttrs (route.options ? mtu) {
|
||||
MTUBytes = route.options.mtu;
|
||||
} //
|
||||
optionalAttrs (route.options ? metric) {
|
||||
Metric = route.options.metric;
|
||||
} //
|
||||
optionalAttrs (route.options ? src) {
|
||||
PreferredSource = route.options.src;
|
||||
} //
|
||||
optionalAttrs (route.options ? protocol) {
|
||||
Protocol = route.options.protocol;
|
||||
} //
|
||||
optionalAttrs (route.options ? quickack) {
|
||||
QuickAck = route.options.quickack;
|
||||
} //
|
||||
optionalAttrs (route.options ? scope) {
|
||||
Scope = route.options.scope;
|
||||
} //
|
||||
optionalAttrs (route.options ? from) {
|
||||
Source = route.options.from;
|
||||
} //
|
||||
optionalAttrs (route.options ? table) {
|
||||
Table = route.options.table;
|
||||
} //
|
||||
optionalAttrs (route.options ? advmss) {
|
||||
TCPAdvertisedMaximumSegmentSize = route.options.advmss;
|
||||
} //
|
||||
optionalAttrs (route.options ? ttl-propagate) {
|
||||
TTLPropagate = route.options.ttl-propagate == "enabled";
|
||||
};
|
||||
});
|
||||
networkConfig.IPv6PrivacyExtensions = "kernel";
|
||||
linkConfig = optionalAttrs (i.macAddress != null) {
|
||||
MACAddress = i.macAddress;
|
||||
|
|
|
@ -103,6 +103,11 @@ let
|
|||
description = ''
|
||||
Other route options. See the symbol <literal>OPTIONS</literal>
|
||||
in the <literal>ip-route(8)</literal> manual page for the details.
|
||||
You may also specify <literal>metric</literal>,
|
||||
<literal>src</literal>, <literal>protocol</literal>,
|
||||
<literal>scope</literal>, <literal>from</literal>
|
||||
and <literal>table</literal>, which are technically
|
||||
not route options, in the sense used in the manual.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -208,6 +213,14 @@ let
|
|||
type = with types; listOf (submodule (routeOpts 4));
|
||||
description = ''
|
||||
List of extra IPv4 static routes that will be assigned to the interface.
|
||||
<warning><para>If the route type is the default <literal>unicast</literal>, then the scope
|
||||
is set differently depending on the value of <option>networking.useNetworkd</option>:
|
||||
the script-based backend sets it to <literal>link</literal>, while networkd sets
|
||||
it to <literal>global</literal>.</para></warning>
|
||||
If you want consistency between the two implementations,
|
||||
set the scope of the route manually with
|
||||
<literal>networking.interfaces.eth0.ipv4.routes = [{ options.scope = "global"; }]</literal>
|
||||
for example.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue