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

Only include loopback address in responses when configured to #173

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

edaniels
Copy link
Member

@edaniels edaniels commented Feb 5, 2024

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).

@edaniels edaniels requested a review from enobufs February 5, 2024 21:26
@@ -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
Copy link
Member Author

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!

Copy link
Member

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) {
Copy link
Member Author

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) {
Copy link
Member Author

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")
Copy link
Member Author

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) {
Copy link
Member Author

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.

if err != nil {
return nil, err
ifaces := config.Interfaces
if ifaces == nil {
Copy link
Member Author

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 {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the fix

@edaniels edaniels force-pushed the fix_webrtc_2625 branch 5 times, most recently from 829b3fe to 03dbda5 Compare February 5, 2024 22:33
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

Attention: 74 lines in your changes are missing coverage. Please review.

Comparison is base (d734c96) 66.09% compared to head (d6ee9a2) 61.65%.

Files Patch % Lines
conn.go 49.65% 59 Missing and 15 partials ⚠️
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     
Flag Coverage Δ
go 61.65% <49.65%> (-4.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

continue
var localAddress net.IP

// prefer the address of the interface if we know its index, but otherwise
Copy link
Member Author

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 :)

@edaniels edaniels force-pushed the fix_webrtc_2625 branch 6 times, most recently from 1c2dcde to 3503c75 Compare February 6, 2024 15:31
t.Fatalf("Expected(%v) and Actual(%v) IP don't match", expectedIP, actualIP4)
}

expectedIP = []byte{0, 0, 0, 1}
Copy link
Member Author

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

This was referenced Feb 6, 2024
Copy link
Member

@enobufs enobufs left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

@edaniels edaniels merged commit 3ef9864 into pion:master Feb 8, 2024
11 of 13 checks passed
@edaniels edaniels deleted the fix_webrtc_2625 branch February 8, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestMulticastDNSCandidates fail probabilistically in local
2 participants