-
Notifications
You must be signed in to change notification settings - Fork 34
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
Only include loopback address in responses when configured to #173
Conversation
@@ -178,6 +185,11 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade | |||
case <-c.closed: | |||
return dnsmessage.ResourceHeader{}, nil, errConnectionClosed | |||
case res := <-queryChan: | |||
// Given https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-mdns-ice-candidates#section-3.2.2-2 |
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.
I was wondering why we don't collect all responses and either way, we're not supposed to!
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.
Good catch!
conn.go
Outdated
@@ -278,7 +290,7 @@ func (c *Conn) writeToSocket(ifIndex int, b []byte, onlyLooback bool) { | |||
} | |||
} | |||
|
|||
func (c *Conn) sendAnswer(name string, ifIndex int, dst net.IP) { | |||
func (c *Conn) sendAnswer(name string, ifIndex int, addr net.IP) { |
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.
better naming
@@ -242,14 +254,14 @@ func (c *Conn) sendQuestion(name string) { | |||
c.writeToSocket(0, rawQuery, false) | |||
} | |||
|
|||
func (c *Conn) writeToSocket(ifIndex int, b []byte, onlyLooback bool) { | |||
func (c *Conn) writeToSocket(ifIndex int, b []byte, srcIfcIsLoopback bool) { |
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.
better naming
// increased the chance that we send a loopback response to a Query that is | ||
// unwillingly to use loopback addresses (the default in pion/ice). | ||
for i := 0; i < 100; i++ { | ||
_, addr, err = bServer.Query(context.TODO(), "pion-mdns-2.local") |
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.
This should prevent future mishaps but it's racy. From what we know on pion/webrtc#2625, it easily fails within 10 attempts since loopback has a higher chance of routing back to itself faster than a LAN mDNS response (I think)
@@ -95,6 +110,81 @@ func TestValidCommunicationWithAddressConfig(t *testing.T) { | |||
check(aServer.Close(), t) | |||
} | |||
|
|||
func TestValidCommunicationWithLoopbackAddressConfig(t *testing.T) { |
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.
I should have added this test originally since I was intended on increasing the chances we get loopback addresses for when I was working on some offline code.
8284b94
to
070c9b7
Compare
if err != nil { | ||
return nil, err | ||
ifaces := config.Interfaces | ||
if ifaces == nil { |
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.
Helpful for tests!
} | ||
|
||
inboundBufferSize := 0 | ||
joinErrCount := 0 | ||
ifacesToUse := make([]net.Interface, 0, len(ifaces)) | ||
for i, ifc := range ifaces { | ||
if err = conn.JoinGroup(&ifaces[i], &net.UDPAddr{IP: net.IPv4(224, 0, 0, 251)}); err != nil { | ||
if !config.IncludeLoopback && ifc.Flags&net.FlagLoopback == net.FlagLoopback { |
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.
This is the fix
829b3fe
to
03dbda5
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #173 +/- ##
==========================================
- Coverage 66.09% 61.65% -4.45%
==========================================
Files 1 1
Lines 292 412 +120
==========================================
+ Hits 193 254 +61
- Misses 70 123 +53
- Partials 29 35 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
continue | ||
var localAddress net.IP | ||
|
||
// prefer the address of the interface if we know its index, but otherwise |
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.
this took a while to figure out but will provide further network path efficiencies but really it was to fix tests on linux :)
1c2dcde
to
3503c75
Compare
t.Fatalf("Expected(%v) and Actual(%v) IP don't match", expectedIP, actualIP4) | ||
} | ||
|
||
expectedIP = []byte{0, 0, 0, 1} |
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.
the previous ipToBytes
was broken for this case
3503c75
to
4481e04
Compare
4481e04
to
ac21988
Compare
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.
Nice work Eric!
@@ -178,6 +185,11 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade | |||
case <-c.closed: | |||
return dnsmessage.ResourceHeader{}, nil, errConnectionClosed | |||
case res := <-queryChan: | |||
// Given https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-mdns-ice-candidates#section-3.2.2-2 |
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.
Good catch!
Fixes pion/webrtc#2625
Details:
This fixes a regression from 608f20b where by properly sending mDNS responses to all interfaces, we significantly increased the chance that we send a loopback response to a Query that is unwillingly to use loopback addresses (the default in pion/ice).