mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Respect IncludeLoopback in UDPMuxDefault
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.
This commit is contained in:
@@ -49,6 +49,7 @@ func TestMuxAgent(t *testing.T) {
|
||||
NetworkTypes: []NetworkType{
|
||||
NetworkTypeUDP4,
|
||||
},
|
||||
IncludeLoopback: addr.IP.IsLoopback(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
@@ -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{
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user