mdns icon indicating copy to clipboard operation
mdns copied to clipboard

Querying does not work for cases when advertising is delegated to another host.

Open akamensky opened this issue 4 years ago • 2 comments

Your environment.

  • Version: v0.0.5
  • Browser: N/A
  • Other Information - N/A

What did you do?

I have a code that advertises A records on behalf of other hosts. Simple code to do that is (this code runs on a host with a different IP address):

package main

import (
	"github.com/davecheney/mdns"
	"fmt"
	"time"
)

func main() {
	err := mdns.Publish("test.local 60 IN A 10.0.1.0")
	if err != nil {
		panic(err)
	}
	fmt.Println("ok")
	time.Sleep(60 * time.Minute)
}

Then query it using code as in examples:

package main

import (
	"context"
	"fmt"
	"net"

	"github.com/pion/mdns"
	"golang.org/x/net/ipv4"
)

func main() {
	addr, err := net.ResolveUDPAddr("udp", mdns.DefaultAddress)
	if err != nil {
		panic(err)
	}

	l, err := net.ListenUDP("udp4", addr)
	if err != nil {
		panic(err)
	}

	server, err := mdns.Server(ipv4.NewPacketConn(l), &mdns.Config{})
	if err != nil {
		panic(err)
	}
	answer, src, err := server.Query(context.TODO(), "test.local")
	if err != nil {
		panic(err)
	}
	fmt.Println(answer)
	fmt.Println(src)
	fmt.Println(err)
}

What did you expect?

Querying using this library should work. It works using avahi client and it works using macos dns-sd. I expect that while the above code is running, querying using this library for "test.local" returns correct result.

What happened?

It hangs indefinitely.

akamensky avatar Sep 08 '21 16:09 akamensky

If you apply https://github.com/pion/mdns/pull/70 does it work?

Most of my attention is on https://github.com/pion/webrtc, but will try my best to get this working!

Sean-Der avatar Sep 08 '21 18:09 Sean-Der

No, #70 does not fix it. I checked and the code returns here conn.go#L297 For some reason it sees it as empty response. Which it is not.

Debugging the code: err == "parsing/packing of this section has completed" in that if statement. But no error is returned back and no response is captured.

Running tcpdump I do see:

21:29:07.409061 enp2s0f0 M   IP 10.0.0.185.5353 > 224.0.0.251.5353: 0 A (QM)? test.local. (31)
21:29:07.409408 enp2s0f0 Out IP 10.0.0.3.5353 > 10.0.0.185.5353: 0- [0q] 1/0/0 A 10.0.1.0 (41)

So the question is sent and answer is sent back.

akamensky avatar Sep 09 '21 13:09 akamensky

@akamensky if you're still interested, can you check if this is still an issue?

edaniels avatar May 02 '23 06:05 edaniels

Looked into this. This does not work because when we listen to DefaultAddress = "224.0.0.0:5353", we will only ever get multicast responses back. In order to address this, we need to have Query begin using a unicast socket for queries. This will be more efficient and correct. When we do this, the client side is okay to listen on "0.0.0.0:0", since there does not need to be a dedicated way to listen for questions, just answers. This way, we are allowed to receive answers both from our joined multicast groups and unicast.

So, this will be fixed with https://github.com/pion/mdns/issues/155 which comes behind https://github.com/pion/mdns/issues/69

edaniels avatar Feb 06 '24 22:02 edaniels

Verified #176 fixes this but need a review

edaniels avatar Feb 08 '24 14:02 edaniels