-
-
Notifications
You must be signed in to change notification settings - Fork 14k
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/systemd-networkd: add NFTSet related options #332777
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -745,6 +745,7 @@ let | |
"ManageTemporaryAddress" | ||
"AddPrefixRoute" | ||
"AutoJoin" | ||
"NFTSet" | ||
]) | ||
(assertHasField "Address") | ||
(assertValueOneOf "PreferredLifetime" ["forever" "infinity" "0" 0]) | ||
|
@@ -754,6 +755,7 @@ let | |
(assertValueOneOf "ManageTemporaryAddress" boolValues) | ||
(assertValueOneOf "AddPrefixRoute" boolValues) | ||
(assertValueOneOf "AutoJoin" boolValues) | ||
(assertNftSet "NFTSet") | ||
]; | ||
|
||
sectionRoutingPolicyRule = checkUnitConfigWithLegacyKey "routingPolicyRuleConfig" "RoutingPolicyRule" [ | ||
|
@@ -871,6 +873,7 @@ let | |
"FallbackLeaseLifetimeSec" | ||
"Label" | ||
"Use6RD" | ||
"NFTSet" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DHCPv4 documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#NFTSet= |
||
]) | ||
(assertValueOneOf "UseDNS" boolValues) | ||
(assertValueOneOf "RoutesToDNS" boolValues) | ||
|
@@ -896,6 +899,7 @@ let | |
(assertValueOneOf "SendDecline" boolValues) | ||
(assertValueOneOf "FallbackLeaseLifetimeSec" ["forever" "infinity"]) | ||
(assertValueOneOf "Use6RD" boolValues) | ||
(assertNftSet "NFTSet") | ||
]; | ||
|
||
sectionDHCPv6 = checkUnitConfig "DHCPv6" [ | ||
|
@@ -920,6 +924,7 @@ let | |
"IAID" | ||
"UseDelegatedPrefix" | ||
"SendRelease" | ||
"NFTSet" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DHCPv6 documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#NFTSet=1 |
||
]) | ||
(assertValueOneOf "UseAddress" boolValues) | ||
(assertValueOneOf "UseDNS" boolValues) | ||
|
@@ -933,6 +938,7 @@ let | |
(assertInt "IAID") | ||
(assertValueOneOf "UseDelegatedPrefix" boolValues) | ||
(assertValueOneOf "SendRelease" boolValues) | ||
(assertNftSet "NFTSet") | ||
]; | ||
|
||
sectionDHCPPrefixDelegation = checkUnitConfig "DHCPPrefixDelegation" [ | ||
|
@@ -944,11 +950,13 @@ let | |
"Token" | ||
"ManageTemporaryAddress" | ||
"RouteMetric" | ||
"NFTSet" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DHCPPrefixDelegation documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#NFTSet=2 |
||
]) | ||
(assertValueOneOf "Announce" boolValues) | ||
(assertValueOneOf "Assign" boolValues) | ||
(assertValueOneOf "ManageTemporaryAddress" boolValues) | ||
(assertRange "RouteMetric" 0 4294967295) | ||
(assertNftSet "NFTSet") | ||
]; | ||
|
||
sectionIPv6AcceptRA = checkUnitConfig "IPv6AcceptRA" [ | ||
|
@@ -971,6 +979,7 @@ let | |
"UseRoutePrefix" | ||
"Token" | ||
"UsePREF64" | ||
"NFTSet" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IPv6AcceptRA documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#NFTSet=3 |
||
]) | ||
(assertValueOneOf "UseDNS" boolValues) | ||
(assertValueOneOf "UseDomains" (boolValues ++ ["route"])) | ||
|
@@ -982,6 +991,7 @@ let | |
(assertValueOneOf "UseGateway" boolValues) | ||
(assertValueOneOf "UseRoutePrefix" boolValues) | ||
(assertValueOneOf "UsePREF64" boolValues) | ||
(assertNftSet "NFTSet") | ||
]; | ||
|
||
sectionDHCPServer = checkUnitConfig "DHCPServer" [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# This tests systemd-networkd NFTSet option. The interface's statically | ||
# configured address is added to an nft set, and the DHCP configured address is | ||
# added to another. The sets are used by one rule that blocks connections to | ||
# the static address, and one rule that blocks connections to the DHCP address. | ||
# It is tested that the expected connections succeed or fail from another host. | ||
import ./make-test-python.nix ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The manual specifies a different way of defining tests, based on |
||
{ pkgs, ... }: | ||
{ | ||
name = "systemd-networkd-nftset"; | ||
meta = with pkgs.lib.maintainers; { | ||
maintainers = [ mvnetbiz ]; | ||
}; | ||
nodes = { | ||
router = | ||
{ ... }: | ||
{ | ||
virtualisation.vlans = [ 1 ]; | ||
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug"; | ||
networking = { | ||
useNetworkd = true; | ||
useDHCP = false; | ||
firewall.enable = false; | ||
}; | ||
systemd.network = { | ||
networks = { | ||
# systemd-networkd will load the first network unit file | ||
# that matches, ordered lexiographically by filename. | ||
# /etc/systemd/network/{40-eth1,99-main}.network already | ||
# exists. This network unit must be loaded for the test, | ||
# however, hence why this network is named such. | ||
"01-eth1" = { | ||
name = "eth1"; | ||
networkConfig = { | ||
DHCPServer = true; | ||
IPv6AcceptRA = "no"; | ||
Address = "10.0.0.1/24"; | ||
}; | ||
dhcpServerConfig = { | ||
PoolOffset = 100; | ||
PoolSize = 1; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
client = | ||
{ ... }: | ||
{ | ||
virtualisation.vlans = [ 1 ]; | ||
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug"; | ||
networking = { | ||
useNetworkd = true; | ||
useDHCP = false; | ||
firewall.enable = false; | ||
nftables = { | ||
enable = true; | ||
flushRuleset = true; | ||
ruleset = '' | ||
table inet mytable { | ||
set dhcp_set { | ||
type ipv4_addr | ||
} | ||
set static_set { | ||
type ipv4_addr | ||
} | ||
chain input { | ||
type filter hook input priority filter; policy accept; | ||
ip daddr @dhcp_set tcp dport 80 reject with tcp reset | ||
ip daddr @static_set tcp dport 8080 reject with tcp reset | ||
} | ||
} | ||
''; | ||
}; | ||
}; | ||
systemd.network.networks."01-eth" = { | ||
name = "eth1"; | ||
networkConfig = { | ||
DHCP = "ipv4"; | ||
IPv6AcceptRA = "no"; | ||
}; | ||
addresses = [ | ||
{ | ||
Address = "10.0.0.2/24"; | ||
NFTSet = "address:inet:mytable:static_set"; | ||
} | ||
]; | ||
dhcpV4Config = { | ||
NFTSet = "address:inet:mytable:dhcp_set"; | ||
}; | ||
}; | ||
services.nginx = { | ||
enable = true; | ||
virtualHosts.localhost.listen = [ | ||
{ | ||
addr = "0.0.0.0"; | ||
port = 80; | ||
} | ||
{ | ||
addr = "0.0.0.0"; | ||
port = 8080; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
testScript = | ||
{ ... }: | ||
'' | ||
start_all() | ||
router.systemctl("start network-online.target") | ||
client.systemctl("start network-online.target") | ||
router.wait_for_unit("systemd-networkd-wait-online.service") | ||
client.wait_for_unit("systemd-networkd-wait-online.service") | ||
# should be able to ping both IPs | ||
router.wait_until_succeeds("ping -c 5 10.0.0.2") | ||
router.wait_until_succeeds("ping -c 5 10.0.0.100") | ||
client.wait_for_unit("nginx.service") | ||
client.wait_for_unit("nftables.service") | ||
# should be able to get static IP, but not the DHCP IP on port 80 | ||
router.wait_until_succeeds("curl 10.0.0.2") | ||
router.wait_until_fails("curl 10.0.0.100"); | ||
# vice versa on port 8080 | ||
router.wait_until_succeeds("curl 10.0.0.100:8080") | ||
router.wait_until_fails("curl 10.0.0.2:8080"); | ||
''; | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#NFTSet=source:family:table:set
Do you think you need a validator? One seems possible given the documentation above.