Skip to content
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

Switch most everything to netip in prep for ipv6 in the overlay #1173

Merged
merged 17 commits into from
Jul 31, 2024

Conversation

nbrownus
Copy link
Collaborator

@nbrownus nbrownus commented Jul 5, 2024

Open questions:

  • Relays use an empty netip.AddrPort remote which leads to logging Invalid AddrPort instead of nil like before, how do we want to deal with it?

Some things to note:

  • Most netip.Addr creations require the resulting address to be Unmap()d to avoid equality issues between 4in6 and v4 addresses. ffff:127.0.0.1 != 127.0.0.1 and its easy to get the former.
  • bart appears to be pretty slow when compared with our old cidr.Tree. We should look at performance carefully and determine if we need to resurrect that code.

calculated_remote.go Outdated Show resolved Hide resolved
@nbrownus nbrownus marked this pull request as draft July 5, 2024 14:13
control.go Show resolved Hide resolved
hostmap.go Outdated Show resolved Hide resolved
"net/netip"
)

type VpnIp uint32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving a note to consider bringing this back as type VpnIp netip.addr mostly as documentation, so we don't forget

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at least type VpnIp=netip.addr

allow_list_test.go Outdated Show resolved Hide resolved
b := net.ParseIP(a)
b, err := netip.ParseAddr(a)
if err != nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider l.Debugf?

IP: net.ParseIP(sHost),
Port: port,
}
r.outNat[c.GetUDPAddr().String()+":"+fromAddr.String()] = toAddr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk if you wanna mess with it, but I think we have the opportunity to use an AddrPort over a string here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal NAT for the e2e tests, both sides are netip.AddrPorts. Could move this to a struct containing two netip.AddrPorts to avoid the strings

}

v6 := sa.(*windows.SockaddrInet6)
return &Addr{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does golang have a htons equivalent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not, lgtm

}

// Make sure we don't have any unexpected fields
assertFields(t, []string{"VpnIp", "LocalIndex", "RemoteIndex", "RemoteAddrs", "Cert", "MessageCounter", "CurrentRemote", "CurrentRelaysToMe", "CurrentRelaysThroughMe"}, thi)
test.AssertDeepCopyEqual(t, &expectedInfo, thi)
assert.EqualValues(t, &expectedInfo, thi)
//TODO: netip.Addr reuses global memory for zone identifiers which breaks our "no reused memory check" here
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do with this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write a function to check everything but the zone?

Or, for the purpose of testing, we could (somehow?) ensure that each netip.Addr we check like this has a unique zone, but that sort of sucks

for _, ip := range c.Details.Ips {
remoteCidr.AddCIDR(&net.IPNet{IP: ip.IP, Mask: net.IPMask{255, 255, 255, 255}}, struct{}{})
//TODO: IPV6-WORK what to do when ip is invalid?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to determine failure strategy

}

if ip4 := fIp.To4(); ip4 != nil && lh.myVpnNet.Contains(fIp) {
//TODO: we could technically insert all returned ips instead of just the first one if a dns lookup was used
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include this in the change here?

@@ -146,12 +146,23 @@ func (u *StdConn) ListenOut(r EncReader, lhf LightHouseHandlerFunc, cache *firew
//metric.Update(int64(n))
for i := 0; i < n; i++ {
if u.isV4 {
udpAddr.IP = names[i][4:8]
ip, _ = netip.AddrFromSlice(names[i][4:8])
//TODO: IPV6-WORK what is not ok?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to determine what to do here

@nbrownus nbrownus changed the title WIP: switch most everything to netip in prep for ipv6 in the overlay Switch most everything to netip in prep for ipv6 in the overlay Jul 9, 2024
@nbrownus nbrownus marked this pull request as ready for review July 9, 2024 16:26
@nbrownus nbrownus merged commit e264a0f into master Jul 31, 2024
8 checks passed
@nbrownus nbrownus deleted the netip-final branch July 31, 2024 15:19
@gaissmai
Copy link

* `bart` appears to be pretty slow when compared with our old `cidr.Tree`. We should look at performance carefully and determine if we need to resurrect that code.

huch, really? I'm the author of bart and I'm pretty sure bart is one of the fastest go libraries for IPv4/IPv6 longest-prefix-match operations. Do you have benchmarks?

@wadey wadey added this to the v1.9.4 milestone Sep 3, 2024
wadey added a commit that referenced this pull request Sep 3, 2024
Non dependency changes:

- #1194
- #1191
- #1188
- #1185
- #1181
- #1173
- #1171
- #1164
- #1162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants