-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement initial set of backend controllers/resources to handle nftables chains/rules etc. Replace the KubeSpan nftables operations with controller-based. See #4421 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
- Loading branch information
Showing
36 changed files
with
9,755 additions
and
4,334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package network | ||
|
||
import ( | ||
"net/netip" | ||
|
||
"go4.org/netipx" | ||
) | ||
|
||
// BuildIPSet builds an IPSet from the given include and exclude prefixes. | ||
func BuildIPSet(include, exclude []netip.Prefix) (*netipx.IPSet, error) { | ||
var builder netipx.IPSetBuilder | ||
|
||
for _, pfx := range include { | ||
builder.AddPrefix(pfx) | ||
} | ||
|
||
for _, pfx := range exclude { | ||
builder.RemovePrefix(pfx) | ||
} | ||
|
||
return builder.IPSet() | ||
} | ||
|
||
// SplitIPSet splits the given IPSet into IPv4 and IPv6 ranges. | ||
func SplitIPSet(set *netipx.IPSet) (ipv4, ipv6 []netipx.IPRange) { | ||
for _, rng := range set.Ranges() { | ||
if rng.From().Is4() { | ||
ipv4 = append(ipv4, rng) | ||
} else { | ||
ipv6 = append(ipv6, rng) | ||
} | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package network_test | ||
|
||
import ( | ||
"net/netip" | ||
"testing" | ||
|
||
"github.com/siderolabs/gen/xslices" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go4.org/netipx" | ||
|
||
"github.com/siderolabs/talos/internal/app/machined/pkg/adapters/network" | ||
) | ||
|
||
func TestBuildIPSet(t *testing.T) { | ||
ipset, err := network.BuildIPSet( | ||
[]netip.Prefix{ | ||
netip.MustParsePrefix("10.0.0.0/8"), | ||
netip.MustParsePrefix("2001:db8::/32"), | ||
}, | ||
[]netip.Prefix{ | ||
netip.MustParsePrefix("10.4.0.0/16"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, | ||
[]string{"10.0.0.0-10.3.255.255", "10.5.0.0-10.255.255.255", "2001:db8::-2001:db8:ffff:ffff:ffff:ffff:ffff:ffff"}, | ||
xslices.Map(ipset.Ranges(), netipx.IPRange.String), | ||
) | ||
} | ||
|
||
func TestSplitIPSet(t *testing.T) { | ||
ipset, err := network.BuildIPSet( | ||
[]netip.Prefix{ | ||
netip.MustParsePrefix("10.0.0.0/8"), | ||
netip.MustParsePrefix("2001:db8::/32"), | ||
}, | ||
[]netip.Prefix{ | ||
netip.MustParsePrefix("10.4.0.0/16"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
v4, v6 := network.SplitIPSet(ipset) | ||
|
||
assert.Equal(t, | ||
[]string{"10.0.0.0-10.3.255.255", "10.5.0.0-10.255.255.255"}, | ||
xslices.Map(v4, netipx.IPRange.String), | ||
) | ||
|
||
assert.Equal(t, | ||
[]string{"2001:db8::-2001:db8:ffff:ffff:ffff:ffff:ffff:ffff"}, | ||
xslices.Map(v6, netipx.IPRange.String), | ||
) | ||
} |
Oops, something went wrong.