Skip to content

Commit d0435ba

Browse files
committedSep 28, 2017
network-interfaces: device routes for default gateway
Iff interface is set, it makes sense to add device route by default.
1 parent 0a6fca1 commit d0435ba

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed
 

‎nixos/modules/tasks/network-interfaces-scripted.nix

+14-6
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,32 @@ let
122122
123123
# Set the default gateway.
124124
${optionalString (cfg.defaultGateway != null && cfg.defaultGateway.address != "") ''
125-
# FIXME: get rid of "|| true" (necessary to make it idempotent).
126-
ip route add default ${optionalString (cfg.defaultGateway.metric != null)
125+
${optionalString (cfg.defaultGateway.interface != null) ''
126+
ip route replace ${cfg.defaultGateway.address} dev ${cfg.defaultGateway.interface} ${optionalString (cfg.defaultGateway.metric != null)
127+
"metric ${toString cfg.defaultGateway.metric}"
128+
} proto static
129+
''}
130+
ip route replace default ${optionalString (cfg.defaultGateway.metric != null)
127131
"metric ${toString cfg.defaultGateway.metric}"
128132
} via "${cfg.defaultGateway.address}" ${
129133
optionalString (cfg.defaultGatewayWindowSize != null)
130134
"window ${toString cfg.defaultGatewayWindowSize}"} ${
131135
optionalString (cfg.defaultGateway.interface != null)
132-
"dev ${cfg.defaultGateway.interface}"} proto static || true
136+
"dev ${cfg.defaultGateway.interface}"} proto static
133137
''}
134138
${optionalString (cfg.defaultGateway6 != null && cfg.defaultGateway6.address != "") ''
135-
# FIXME: get rid of "|| true" (necessary to make it idempotent).
136-
ip -6 route add ::/0 ${optionalString (cfg.defaultGateway6.metric != null)
139+
${optionalString (cfg.defaultGateway6.interface != null) ''
140+
ip -6 route replace ${cfg.defaultGateway6.address} dev ${cfg.defaultGateway6.interface} ${optionalString (cfg.defaultGateway6.metric != null)
141+
"metric ${toString cfg.defaultGateway6.metric}"
142+
} proto static
143+
''}
144+
ip -6 route replace default ${optionalString (cfg.defaultGateway6.metric != null)
137145
"metric ${toString cfg.defaultGateway6.metric}"
138146
} via "${cfg.defaultGateway6.address}" ${
139147
optionalString (cfg.defaultGatewayWindowSize != null)
140148
"window ${toString cfg.defaultGatewayWindowSize}"} ${
141149
optionalString (cfg.defaultGateway6.interface != null)
142-
"dev ${cfg.defaultGateway6.interface}"} proto static || true
150+
"dev ${cfg.defaultGateway6.interface}"} proto static
143151
''}
144152
'';
145153
};

0 commit comments

Comments
 (0)
Please sign in to comment.