Skip to content

Commit

Permalink
fix(tlsmiddlebox): if RemoteAddr is IPv6 set IPV6_UNICAST_HOPS
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanius-collaris committed Mar 7, 2024
1 parent 813ba9e commit 01a74c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/experiment/tlsmiddlebox/measurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
testName = "tlsmiddlebox"
testVersion = "0.1.1"
testVersion = "0.1.2"
)

// Measurer performs the measurement.
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/tlsmiddlebox/measurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMeasurerExperimentNameVersion(t *testing.T) {
if measurer.ExperimentName() != "tlsmiddlebox" {
t.Fatal("unexpected ExperimentName")
}
if measurer.ExperimentVersion() != "0.1.1" {
if measurer.ExperimentVersion() != "0.1.2" {
t.Fatal("unexpected ExperimentVersion")
}
}
Expand Down
8 changes: 7 additions & 1 deletion internal/experiment/tlsmiddlebox/syscall_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package tlsmiddlebox
import (
"net"
"syscall"
"strings"
)

// SetTTL sets the IP TTL field for the underlying net.TCPConn
Expand All @@ -23,7 +24,12 @@ func (c *dialerTTLWrapperConn) SetTTL(ttl int) error {
return err
}
rawErr := rawConn.Control(func(fd uintptr) {
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_TTL, ttl)
isIPv6 := strings.Contains(tcpConn.RemoteAddr().String(), "[")
if isIPv6 {
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_UNICAST_HOPS, ttl)
} else {
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_TTL, ttl)
}
})
// The syscall err is given a higher priority and returned early if non-nil
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion internal/experiment/tlsmiddlebox/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package tlsmiddlebox
import (
"net"
"syscall"
"strings"
)

// SetTTL sets the IP TTL field for the underlying net.TCPConn
Expand All @@ -23,7 +24,12 @@ func (c *dialerTTLWrapperConn) SetTTL(ttl int) error {
return err
}
rawErr := rawConn.Control(func(fd uintptr) {
err = syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, syscall.IP_TTL, ttl)
isIPv6 := strings.Contains(tcpConn.RemoteAddr().String(), "[")
if isIPv6 {
err = syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, syscall.IPV6_UNICAST_HOPS, ttl)
} else {
err = syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, syscall.IP_TTL, ttl)
}
})
// The syscall err is given a higher priority and returned early if non-nil
if err != nil {
Expand Down

0 comments on commit 01a74c5

Please sign in to comment.