Skip to content

Commit

Permalink
Respect IncludeLoopback in UDPMuxDefault
Browse files Browse the repository at this point in the history
Currently, when using UDPMuxDefault with unspecified address,
the loopback address is included by default, but
agentConfig.IncludeLoopback is not respected when gathering
local candidates.

The same holds true when UDPMuxDefault is configured with a loopback
address, but agentConfig.IncludeLoopback is not explicitly set to
true.

This commit adds an extra check to gatherCandidatesLocalUDPMux()
for respecting that setting in both cases.
  • Loading branch information
dinvlad authored and Sean-Der committed Mar 20, 2024
1 parent a728446 commit 77cc354
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions agent_udpmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestMuxAgent(t *testing.T) {
NetworkTypes: []NetworkType{
NetworkTypeUDP4,
},
IncludeLoopback: addr.IP.IsLoopback(),
})
require.NoError(t, err)

Expand Down
7 changes: 7 additions & 0 deletions gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ func (a *Agent) gatherCandidatesLocalUDPMux(ctx context.Context) error { //nolin
return errInvalidAddress
}
candidateIP := udpAddr.IP

if _, ok := a.udpMux.(*UDPMuxDefault); ok && !a.includeLoopback && candidateIP.IsLoopback() {
// Unlike MultiUDPMux Default, UDPMuxDefault doesn't have
// a separate param to include loopback, so we respect agent config
continue
}

if a.mDNSMode != MulticastDNSModeQueryAndGather &&
a.extIPMapper != nil &&
a.extIPMapper.candidateType == CandidateTypeHost {
Expand Down
28 changes: 28 additions & 0 deletions gather_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func TestLoopbackCandidate(t *testing.T) {
assert.NoError(t, err)
muxWithLo, errlo := NewMultiUDPMuxFromPort(12501, UDPMuxFromPortWithLoopback())
assert.NoError(t, errlo)

unspecConn, errconn := net.ListenPacket("udp", ":0")
assert.NoError(t, errconn)
defer func() {
_ = unspecConn.Close()
}()
muxUnspecDefault := NewUDPMuxDefault(UDPMuxParams{
UDPConn: unspecConn,
})

testCases := []testCase{
{
name: "mux should not have loopback candidate",
Expand All @@ -150,6 +160,23 @@ func TestLoopbackCandidate(t *testing.T) {
},
loExpected: true,
},
{
name: "UDPMuxDefault with unspecified IP should not have loopback candidate",
agentConfig: &AgentConfig{
NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6},
UDPMux: muxUnspecDefault,
},
loExpected: false,
},
{
name: "UDPMuxDefault with unspecified IP should respect agent includeloopback",
agentConfig: &AgentConfig{
NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6},
UDPMux: muxUnspecDefault,
IncludeLoopback: true,
},
loExpected: true,
},
{
name: "includeloopback enabled",
agentConfig: &AgentConfig{
Expand Down Expand Up @@ -198,6 +225,7 @@ func TestLoopbackCandidate(t *testing.T) {

assert.NoError(t, mux.Close())
assert.NoError(t, muxWithLo.Close())
assert.NoError(t, muxUnspecDefault.Close())
}

// Assert that STUN gathering is done concurrently
Expand Down

0 comments on commit 77cc354

Please sign in to comment.