-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[client] Add IPv6 reverse DNS and host configurator support #5686
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1a7e835
Fix CodeRabbit findings: hasIPv6Changed restart loop, empty peerIPs p…
lixmal 71962f8
Add IPv6 reverse DNS and host configurator support
lixmal d81cd5d
Add IPv6 support to SSH server, client config, and netflow logger
lixmal 3be5a5f
Fix CodeRabbit findings: hasIPv6Changed restart loop, empty peerIPs p…
lixmal 5fcea07
Merge branch 'client-ipv6-iface' into client-ipv6-dns
lixmal 5a29fa8
Merge branch 'client-ipv6-dns' into client-ipv6-ssh-netflow
lixmal 641e386
Merge branch 'client-ipv6-iface' into client-ipv6-dns
lixmal 0c2fbd5
Merge branch 'client-ipv6-dns' into client-ipv6-ssh-netflow
lixmal 50c0bc5
Fix connect.go lint: use SetIPv6FromCompact instead of if-else chain
lixmal bc6ed1a
Merge branch 'client-ipv6-dns' into client-ipv6-ssh-netflow
lixmal 1a6cf9d
Merge branch 'client-ipv6-iface' into client-ipv6-dns
lixmal 1cc19e7
Merge branch 'client-ipv6-dns' into client-ipv6-ssh-netflow
lixmal daeb90c
Merge pull request #5687 from netbirdio/client-ipv6-ssh-netflow
lixmal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,138 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "net/netip" | ||
| "testing" | ||
|
|
||
| "github.com/miekg/dns" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| nbdns "github.com/netbirdio/netbird/dns" | ||
| ) | ||
|
|
||
| func TestCreatePTRRecord_IPv4(t *testing.T) { | ||
| record := nbdns.SimpleRecord{ | ||
| Name: "peer1.netbird.cloud.", | ||
| Type: int(dns.TypeA), | ||
| Class: nbdns.DefaultClass, | ||
| TTL: 300, | ||
| RData: "100.64.0.5", | ||
| } | ||
| prefix := netip.MustParsePrefix("100.64.0.0/16") | ||
|
|
||
| ptr, ok := createPTRRecord(record, prefix) | ||
| require.True(t, ok) | ||
| assert.Equal(t, "5.0.64.100.in-addr.arpa.", ptr.Name) | ||
| assert.Equal(t, int(dns.TypePTR), ptr.Type) | ||
| assert.Equal(t, "peer1.netbird.cloud.", ptr.RData) | ||
| } | ||
|
|
||
| func TestCreatePTRRecord_IPv6(t *testing.T) { | ||
| record := nbdns.SimpleRecord{ | ||
| Name: "peer1.netbird.cloud.", | ||
| Type: int(dns.TypeAAAA), | ||
| Class: nbdns.DefaultClass, | ||
| TTL: 300, | ||
| RData: "fd00:1234:5678::1", | ||
| } | ||
| prefix := netip.MustParsePrefix("fd00:1234:5678::/48") | ||
|
|
||
| ptr, ok := createPTRRecord(record, prefix) | ||
| require.True(t, ok) | ||
| assert.Equal(t, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.7.6.5.4.3.2.1.0.0.d.f.ip6.arpa.", ptr.Name) | ||
| assert.Equal(t, int(dns.TypePTR), ptr.Type) | ||
| assert.Equal(t, "peer1.netbird.cloud.", ptr.RData) | ||
| } | ||
|
|
||
| func TestCreatePTRRecord_OutOfRange(t *testing.T) { | ||
| record := nbdns.SimpleRecord{ | ||
| Name: "peer1.netbird.cloud.", | ||
| Type: int(dns.TypeA), | ||
| RData: "10.0.0.1", | ||
| } | ||
| prefix := netip.MustParsePrefix("100.64.0.0/16") | ||
|
|
||
| _, ok := createPTRRecord(record, prefix) | ||
| assert.False(t, ok) | ||
| } | ||
|
|
||
| func TestGenerateReverseZoneName_IPv4(t *testing.T) { | ||
| tests := []struct { | ||
| prefix string | ||
| expected string | ||
| }{ | ||
| {"100.64.0.0/16", "64.100.in-addr.arpa."}, | ||
| {"10.0.0.0/8", "10.in-addr.arpa."}, | ||
| {"192.168.1.0/24", "1.168.192.in-addr.arpa."}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.prefix, func(t *testing.T) { | ||
| zone, err := generateReverseZoneName(netip.MustParsePrefix(tt.prefix)) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expected, zone) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateReverseZoneName_IPv6(t *testing.T) { | ||
| tests := []struct { | ||
| prefix string | ||
| expected string | ||
| }{ | ||
| {"fd00:1234:5678::/48", "8.7.6.5.4.3.2.1.0.0.d.f.ip6.arpa."}, | ||
| {"fd00::/16", "0.0.d.f.ip6.arpa."}, | ||
| {"fd12:3456:789a:bcde::/64", "e.d.c.b.a.9.8.7.6.5.4.3.2.1.d.f.ip6.arpa."}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.prefix, func(t *testing.T) { | ||
| zone, err := generateReverseZoneName(netip.MustParsePrefix(tt.prefix)) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expected, zone) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCollectPTRRecords_BothFamilies(t *testing.T) { | ||
| config := &nbdns.Config{ | ||
| CustomZones: []nbdns.CustomZone{ | ||
| { | ||
| Domain: "netbird.cloud.", | ||
| Records: []nbdns.SimpleRecord{ | ||
| {Name: "peer1.netbird.cloud.", Type: int(dns.TypeA), RData: "100.64.0.1"}, | ||
| {Name: "peer1.netbird.cloud.", Type: int(dns.TypeAAAA), RData: "fd00::1"}, | ||
| {Name: "peer2.netbird.cloud.", Type: int(dns.TypeA), RData: "100.64.0.2"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| v4Records := collectPTRRecords(config, netip.MustParsePrefix("100.64.0.0/16")) | ||
| assert.Len(t, v4Records, 2, "should collect 2 A record PTRs for the v4 prefix") | ||
|
|
||
| v6Records := collectPTRRecords(config, netip.MustParsePrefix("fd00::/64")) | ||
| assert.Len(t, v6Records, 1, "should collect 1 AAAA record PTR for the v6 prefix") | ||
| } | ||
|
|
||
| func TestAddReverseZone_IPv6(t *testing.T) { | ||
| config := &nbdns.Config{ | ||
| CustomZones: []nbdns.CustomZone{ | ||
| { | ||
| Domain: "netbird.cloud.", | ||
| Records: []nbdns.SimpleRecord{ | ||
| {Name: "peer1.netbird.cloud.", Type: int(dns.TypeAAAA), RData: "fd00:1234:5678::1"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| addReverseZone(config, netip.MustParsePrefix("fd00:1234:5678::/48")) | ||
|
|
||
| require.Len(t, config.CustomZones, 2) | ||
| reverseZone := config.CustomZones[1] | ||
| assert.Equal(t, "8.7.6.5.4.3.2.1.0.0.d.f.ip6.arpa.", reverseZone.Domain) | ||
| assert.Len(t, reverseZone.Records, 1) | ||
| assert.Equal(t, int(dns.TypePTR), reverseZone.Records[0].Type) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If have validation issue with lIPv6 or lIP then bindIP will be invalid.
The old code always used the private client for matching upstreams. This is a behavior change. If this i the expected then fine.
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.
Yes, this is a subtle intentional change. If neither lIP nor lIPv6 is valid for the upstream's address family, we fall through to the default (non-private) client instead of binding to an invalid address. In practice, if needsPrivate is true but the corresponding local IP is invalid, the configuration is broken and there's nothing useful to bind to.