GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — patch to support mDNS and multicast to servers by ka2ddo · Pull Request #148 · dnsjava/dnsjava

Conversation

@ka2ddo

@ka2ddo ka2ddo commented Jan 6, 2021

Copy link
Copy Markdown

changes so that multicast IP addresses can be used for the DNS "server", so that mDNS servers can be queried to support DNS-SD (Service Discovery).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ka2ddo added 3 commits January 6, 2021 15:46
@ka2ddo
Update SimpleResolver.java
504fe0d
add conditional logic to support receiving either a byte array of one answer (existing unicast server behavior), or an ArrayList containing one or more byte arrays (multiple responses to multicast query from multiple mDNS servers).
@ka2ddo
Update NioUdpClient.java
fce0cf8
Add support to wait for multiple answers to arrive if and only if the address of the DNS server is a multicast address.
@ka2ddo
Update SimpleResolver.java
544182b
fix misleading text in logging message where the handling has changed.
@ibauersachs ibauersachs linked an issue Jan 6, 2021 that may be closed by this pull request
Add support for mDNS by allowing multicast server address #147
Open
@ibauersachs

ibauersachs commented Jan 6, 2021

Copy link
Copy Markdown
Member

Thanks for creating a PR! I need to read the mDNS spec to see if this is correct, which will take me a while.

In the meantime, this doesn't even compile and from a first look you seem to have done a lot of code duplication when parsing the answer(s). Please simplify this, e.g. by extracting the validation and parsing into a method that you can call multiple times.

Also, the non-generic response from transaction/multitransaction and later casting is something I'd like to avoid. sendrecv could just return a Future<List<byte[]>> where the single transaction always returns a list with a single entry. Distinguishing if answers should be combined or not can still be done based on the server's destination address.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ka2ddo

ka2ddo commented Jan 6, 2021 via email

Copy link
Copy Markdown
Author
OK. I was trying to minimize changes to existing (unicast) logic so I wouldn't break anything. But I can rework it to reduce code redundancy. Andrew
…
________________________________________ From: Ingo Bauersachs <[email protected]> Sent: Wednesday, January 6, 2021 5:19 PM To: dnsjava/dnsjava Cc: Andrew Pavlin; Author Subject: Re: [dnsjava/dnsjava] patch to support mDNS and multicast to servers (#148) Thanks for creating a PR! I need to read the mDNS spec to see if this is correct, which will take me a while. In the meantime, this doesn't even compile and from a first look you seem to have done a lot of code duplication when parsing the answer(s). Please simplify this, e.g. by extracting the validation and parsing into a method that you can call multiple times. Also, the non-generic response from transaction/multitransaction and later casting is something I'd like to avoid. sendrecv could just return a Future<List<byte[]>> where the single transaction always returns a list with a single entry. Distinguishing if answers should be combined or not can still be done based on the server's destination address. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#148 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTJNLGDIR2OPIHKUNF3SYTOYZANCNFSM4VYCJ7VA>.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ka2ddo added 2 commits January 7, 2021 09:16
@ka2ddo
reduce duplicate code in mDNS support changes
855b7be
Refactor the mDNS changes to reduce duplicate code.
@ka2ddo
reduce duplicated code in mDNS changes
1cf8fb8
refactor most of the duplicated code for error-checking a received query response datagram into a method object.
@ka2ddo

ka2ddo commented Jan 7, 2021 via email

Copy link
Copy Markdown
Author
This is bizarre. The code compiles, but something about a format check in the source code in your maven script caused it to be rejected. And I copied the format that was already in those source files. So I looked at the error from the pull request build, so I am making a third change to my branch of the code base to keep the format-checking Maven plugin from griping.
…
________________________________________ From: Ingo Bauersachs <[email protected]> Sent: Wednesday, January 6, 2021 5:19 PM To: dnsjava/dnsjava Cc: Andrew Pavlin; Author Subject: Re: [dnsjava/dnsjava] patch to support mDNS and multicast to servers (#148) Thanks for creating a PR! I need to read the mDNS spec to see if this is correct, which will take me a while. In the meantime, this doesn't even compile and from a first look you seem to have done a lot of code duplication when parsing the answer(s). Please simplify this, e.g. by extracting the validation and parsing into a method that you can call multiple times. Also, the non-generic response from transaction/multitransaction and later casting is something I'd like to avoid. sendrecv could just return a Future<List<byte[]>> where the single transaction always returns a list with a single entry. Distinguishing if answers should be combined or not can still be done based on the server's destination address. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#148 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTJNLGDIR2OPIHKUNF3SYTOYZANCNFSM4VYCJ7VA>.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ka2ddo added 2 commits January 7, 2021 09:44
@ka2ddo
resolve format complaints in mDNS-modified code
cc916e5
resolve maven com.coveo:format plugin's complaints
@ka2ddo
resolve format complaints in mDNS changes
e838df6
ibauersachs
ibauersachs requested changes Feb 4, 2021
View reviewed changes

@ibauersachs ibauersachs left a comment

Copy link
Copy Markdown
Member

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.

Have you looked at some details of rfc6762? Specifically:

  • port 5353 must not be used as the local port as we're not fully compliant
  • Section 3 mandates that any query to .local. goes to an mDNS server. Not sure how to properly address that, enabling it by default is not an option because .local has been abused by non-mdns setups too much. But I could imagine that the ExtendedResolver sends .local to the multicast address if the multicast address is one of the resolver addresses. A multicast resolver address could be automatically added if a (new) property is set.
  • Setting the unicast-response bit should be easier to set/strip out (DClass). Not quite sure how repsonses look like. If the bit is still set in the response, it needs to be stripped after validation (or the answers won't be recognized as class IN), otherwise the validation needs to accept responses without the bit set as valid

What's an easy way to live test this code? Should having some Windows/Apple devices in the network suffice?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java Outdated

// Check that the response is long enough.
if (in.length < Header.LENGTH) {
exc = new WireParseException("invalid DNS header - too short");

@ibauersachs ibauersachs Feb 4, 2021

Copy link
Copy Markdown
Member

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.

Why don't you just throw these exceptions? They're unsual enough that I wouldn't consider it to be normal code flow.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Feb 9, 2021

Copy link
Copy Markdown
Author

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 didn't want to throw them unless there were no successful responses to a mDNS query. mDNS can get garbage packets back which should be silently ignored.And, because there could be multiple responses, I only wanted to throw the exception if no valid responses were returned (i.e., hacker returned garbage, then valid Avahi-daemon returned a legitimate answer [in that order], then the query shouldn't fail).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ibauersachs ibauersachs Feb 10, 2021

Copy link
Copy Markdown
Member

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.

Yes, I get that, but instead of returning null and then checking the exception instance from a getter, you can throw, catch and still continue in the mDNS case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ibauersachs

ibauersachs commented Feb 4, 2021

Copy link
Copy Markdown
Member

This is bizarre. The code compiles, but something about a format check in the source code in your maven script caused it to be rejected. And I copied the format that was already in those source files. So I looked at the error from the pull request build, so I am making a third change to my branch of the code base to keep the format-checking Maven plugin from griping.

You can auto-format the code by running the Maven target fmt:format. This applies most of the Google Java Format code style. If you're using IntelliJ, you can setup a plugin to format with Ctrl+Alt+L: https://github.com/google/google-java-format#intellij-android-studio-and-other-jetbrains-ides

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ka2ddo

ka2ddo commented Feb 9, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Re: reformatting: I didn't want to reformat any lines I didn't change, and cause spurious non-changing source code changes. Such behavior of IDEs (that "always know better than you do how your code should be formatted", especially when multiple developers' IDEs are configured differently) makes it a pain to review code changes, so I am always very careful not to change the styling of other lines of code (not even switching spaces versus tabs).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ka2ddo

ka2ddo commented Feb 9, 2021

Copy link
Copy Markdown
Author

Have you looked at some details of rfc6762? Specifically:

I sure did. That's how I came up with the idea of deliberately timing out the resolver so I could wait for multiple answers to come in.

port 5353 must not be used as the local port as we're not fully compliant

My proposed changes don't specify the port number. The caller is currently required to be smart enough to specify port 5353 when they also specify a multicast address as the "address" of the remote DNS server, since the SimpleResolver constructor I tested with takes InetSocketAddress objects that include the port number. I suppose the constructors taking a String or an InetAddress should check for multicast addresses and switch from DEFAULT_PORT (= 53) to 5353 automatically.

Or are you saying I need to add a safety check for when the local port is selected to ensure it doesn't accidentally get 5353 as the port number?

Section 3 mandates that any query to .local. goes to an mDNS server. Not sure how to properly
address that, enabling it by default is not an option because .local has been abused by non-mdns
setups too much. But I could imagine that the ExtendedResolver sends .local to the multicast address
if the multicast address is one of the resolver addresses. A multicast resolver address could be
automatically added if a (new) property is set.

That would have been a larger-impact change that I didn't need to do for my limited use-case, which knew that I was making a ".local" query. Would you like me to make the additional changes to automatically switch to multicast for such queries? Problem is, can I safely assume only IPv6 or only IPv4 for the default multicast address?

Setting the unicast-response bit should be easier to set/strip out (DClass). Not quite sure how
repsonses look like. If the bit is still set in the response, it needs to be stripped after validation (or
the answers won't be recognized as class IN), otherwise the validation needs to accept responses
without the bit set as valid

I didn't catch that, because my tests all worked correctly with multicast responses. I never received such a response when I did a multicast query in my tests. But I can make such a change to clear that bit in the received responses. Would you like me to do so?

What's an easy way to live test this code? Should having some Windows/Apple devices in the network suffice?

Have a Linux system on the LAN with the avahi-daemon running, then use the avahi-publish command to register some mDNS entries for testing. I suppose Apple devices on the LAN would do the same thing, but you would have less control over what answers you could get.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ibauersachs

ibauersachs commented Feb 10, 2021

Copy link
Copy Markdown
Member

Or are you saying I need to add a safety check for when the local port is selected to ensure it doesn't accidentally get 5353 as the port number?

Yes, that's what I meant.

Section 3 mandates that any query to .local. goes to an mDNS server. Not sure how to properly
address that, enabling it by default is not an option because .local has been abused by non-mdns
setups too much. But I could imagine that the ExtendedResolver sends .local to the multicast address
if the multicast address is one of the resolver addresses. A multicast resolver address could be
automatically added if a (new) property is set.

That would have been a larger-impact change that I didn't need to do for my limited use-case, which knew that I was making a ".local" query. Would you like me to make the additional changes to automatically switch to multicast for such queries?

I'm not sure how useful it is. I guess we could always add it later if it seems worthwhile.

Problem is, can I safely assume only IPv6 or only IPv4 for the default multicast address?

It depends :-)
If would only activate mDNS if the Resolver contains a broadcast address, and that address would already dictate which IP version to use. If both an IPv4 and an IPv6 address is present, then I guess both should be queried.

Setting the unicast-response bit should be easier to set/strip out (DClass). Not quite sure how
repsonses look like. If the bit is still set in the response, it needs to be stripped after validation (or
the answers won't be recognized as class IN), otherwise the validation needs to accept responses
without the bit set as valid

I didn't catch that, because my tests all worked correctly with multicast responses. I never received such a response when I did a multicast query in my tests. But I can make such a change to clear that bit in the received responses. Would you like me to do so?

I'm not sure it's required, and I couldn't conclude from the RFC without looking at packets.

What's an easy way to live test this code? Should having some Windows/Apple devices in the network suffice?

Have a Linux system on the LAN with the avahi-daemon running, then use the avahi-publish command to register some mDNS entries for testing. I suppose Apple devices on the LAN would do the same thing, but you would have less control over what answers you could get.

Okay, I'll look at some of those packets, then I'll know if that bit mentioned above needs attention or not. Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ibauersachs

ibauersachs commented Feb 10, 2021

Copy link
Copy Markdown
Member

Okay, so I sent some sample queries on my LAN with the unicode flag masked in, like this:

public class Test {
  public static void main(String[] args) throws IOException {
    SimpleResolver sr = new SimpleResolver(new InetSocketAddress("224.0.0.251", 5353));
    Record q = Record.newRecord(Name.fromConstantString("macmini.local."), Type.A, DClass.IN | 0x8000);
    Message mq = Message.newQuery(q);
    System.out.println(sr.send(mq));
  }
}

I get a unicast reply from the Mac Mini, but also two multicast responses from avahi-daemons I seem to have running. The answers from the avahi-daemons are thrown away because the validation in verify1response doesn't take the unicast flag into account (or rather: doesn't ignore it).

The relevant part from the RFC is this sentence (emphasis mine):

When this bit is set in a
question, it indicates that the querier is willing to accept unicast
replies in response to this specific query, as well as the usual
multicast responses
. These questions requesting unicast responses
are referred to as "QU" questions, to distinguish them from the more
usual questions requesting multicast responses ("QM" questions).

Setting the unicast flag in the first hand with masking 0x8000 into DClass.IN is unnatural. There needs to be a better way to set this flag. Parsing and removing needs to be better as well because a printed messages will look like this:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56018
;; flags: qr aa ; qd: 1 an: 1 au: 0 ad: 0 
;; QUESTIONS:
;;	macmini.local., type = A, class = CLASS32769

;; ANSWERS:
macmini.local.		10	IN	A	192.168.10.103

;; AUTHORITY RECORDS:

;; ADDITIONAL RECORDS:

;; Message size: 47 bytes

Note CLASS32769 instead of IN, and maybe a unicast indication. Wireshark for example shows such a query as class IN, "QU" question or as class IN, "QM" question.
Answer records also have a special meaning of the highest bit in the class, meaning "Cache flush" if it is set (sections 10.3 and 10.4).

I'm not sure how to best handle this flag (in questions and answers). Maybe @nresare could chime in here and has an idea?

toxuin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ka2ddo added 2 commits March 13, 2021 16:19
@ka2ddo
resolve issues reported by dnsjava over regarding consistent behavior
92d98d5
of TCP vs. UDP DNS queries and preventing accidental collision of UDP
client port with mDNS server.
@ka2ddo
a few more bugfixes to the mDNS changes per dnsjava author's request.
80aa3cd
@ka2ddo

ka2ddo commented Mar 13, 2021

Copy link
Copy Markdown
Author

additional changes you requested submitted to mDNS_patch_ka2ddo branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ka2ddo
make the format checker happy (again!).
31f2621
@ka2ddo

ka2ddo commented Mar 13, 2021

Copy link
Copy Markdown
Author

and fixing the formatting again....

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ka2ddo
more formatting issues that the online checker didn't report on the
c1ce27b
first build failure.
@ka2ddo

ka2ddo commented Mar 13, 2021

Copy link
Copy Markdown
Author

and again making the formatter happy (since it only makes one complaint at a time).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ibauersachs
ibauersachs requested changes Mar 14, 2021
View reviewed changes

@ibauersachs ibauersachs left a comment

Copy link
Copy Markdown
Member

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.

Thanks for the update. I've left a bunch of comments inline.

The bigger question about how to handle the DClass in questions and responses however is still not clear:

  • In questions, the highest bit set in the Class means Unicast
  • In answers, the highest bit set in the Class means "Cache flush"

For both cases, this needs to be properly handled, i.e. not only in the SimpleResolver but also in e.g. Message.toString(), Record.getDClass() and probably lots of other locations. Maybe a flag boolean isMulticast; in the Message and Record classes is an option.

and again making the formatter happy (since it only makes one complaint at a time).

You can run the checks locally with mvn verify or make the checks happy by applying the formats to your IDE with the links provided previously.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/DClass.java
public static final int ANY = 255;

/** Indicates on mDNS that querier will accept unicast replies from a multicast request. */
public static final int UNICAST_RESPONSE = 0x8000;

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

-> UNICAST_RESPONSE_FLAG

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Mar 15, 2021

Copy link
Copy Markdown
Author

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.

OK, in next request.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/NioUdpClient.java

addr = new InetSocketAddress(local.getAddress(), port);
}
if (addr.getPort() == SimpleResolver.RESERVED_MDNS_PORT) {

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

addr can be null if the config option dnsjava.udp.ephemeral.use_ephemeral_port is set. Also, port 5353 is a valid source-port in normal DNS

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Mar 15, 2021

Copy link
Copy Markdown
Author

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 kind of disagree with the statement that "port 5353 is valid in normal DNS". Since mDNS is becoming more prevalent, it would be recommended not to use that port accidentally to avoid receiving requests from other hosts when you're expecting replies. And it doesn't hurt to avoid it, since this part of the code no longer differentiates between receiving DNS and mDNS replies.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ibauersachs ibauersachs Mar 15, 2021

Copy link
Copy Markdown
Member

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.

In regular DNS the socket is bound, so the only replies accepted are from a DNS server. The case shouldn't occur when using defaults though.

But addr==null needs to be handled anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java
public static final int DEFAULT_PORT = 53;

/** The port we can't use as a client because it's reserved for mDNS servers. */
public static final int RESERVED_MDNS_PORT = 5353;

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

-> MDNS_PORT

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Mar 15, 2021

Copy link
Copy Markdown
Author

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.

OK

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java
+ Type.string(response.getQuestion().getType())));
return f;
VerifyOneResponse verifyOneResponse = new VerifyOneResponse(query, qid);
@SuppressWarnings("unchecked")

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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 no longer necessary

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Mar 15, 2021

Copy link
Copy Markdown
Author

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.

OK

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java

return result.thenComposeAsync(
in -> {
v -> {

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

name this something useful, e.g. answers (v is typically used for Void, which is not the case here)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ka2ddo ka2ddo Mar 15, 2021

Copy link
Copy Markdown
Author

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.

OK, in next request.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/NioUdpClient.java
source = channel.receive(buffer);
read = buffer.position();
if (read <= 0 || source == null) {
return; // ignore this datagram

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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 a lot of code duplication. The return here vs. EOFException could be:

if (remoteSocketAddress.getAddress().isMulticast()) {
  return;
}
throw new EOFException();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/NioUdpClient.java
byte[] data = new byte[read];
System.arraycopy(buffer.array(), 0, data, 0, read);
verboseLog("UDP read", channel.socket().getLocalSocketAddress(), source, data);
answers.add(data);

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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 only other line in this method that differs for mDNS. Instead of duplicating everything, move the processing of the data byte-array into a separate method, e.g.

// in Transaction:
...
  System.arraycopy(buffer.array(), 0, data, 0, read);
  verboseLog("UDP read", channel.socket().getLocalSocketAddress(), source, data);
  processAnswer(data);
}

processAnswer(byte[] data) {
  silentCloseChannel();
  f.complete(Collections.singletonList(data));
  pendingTransactions.remove(this);
}

// in MultiAnswerTransaction:
processAnswer(byte[] data) {
  answers.add(data);
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/NioUdpClient.java
private ArrayList<byte[]> answers = new ArrayList<>();

@Override
void closeTransaction() {

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

closeTransaction is only triggered when the timeout has expired. Is this really the only condition on which you want to return answers? What about the case where one is only interested in the first answer, as fast as possible?

The timeout processing currently only runs every second. Is that still sufficient?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java
return "SimpleResolver [" + address + "]";
}

private class VerifyOneResponse {

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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.

Actually, this doesn't need to be a class. As I mentioned before, throwing the exceptions is fine and whole thing can be a method: Message verifyResponse(Message query, byte[] in) throws WireParseException { ... }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/xbill/DNS/SimpleResolver.java
return null;
}

if ((query.getQuestion().getDClass() & ~DClass.UNICAST_RESPONSE)

@ibauersachs ibauersachs Mar 14, 2021

Copy link
Copy Markdown
Member

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 masking must only be applied for mDNS, not regular DNS
  • In the mDNS case, the mask should be 0x7FFF so that 32768 to 65535 is ignored (see the note at IANA or in the RFC)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ka2ddo

ka2ddo commented Jul 27, 2021 via email

Copy link
Copy Markdown
Author
Hello. Sorry I'm behind on this patch. I hope to get back to it next week. Andrew
…
________________________________________ From: cary-xian ***@***.***> Sent: Monday, July 26, 2021 8:26 PM To: dnsjava/dnsjava Cc: Andrew Pavlin; Author Subject: Re: [dnsjava/dnsjava] patch to support mDNS and multicast to servers (#148) dns — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#148 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTKTWMZGUGRIXCGUBK3TZX4JVANCNFSM4VYCJ7VA>.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ibauersachs
ibauersachs force-pushed the master branch from 07cedfa to 9a31769 Compare July 30, 2021 13:49
@ibauersachs
ibauersachs force-pushed the master branch from e6083ea to 7cef3e2 Compare August 7, 2021 18:20
@arnocornette

arnocornette commented Sep 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Is this still a WIP? And are you still working on this @ka2ddo? I wouldn't mind giving it a look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ibauersachs
ibauersachs force-pushed the master branch from 2f8e897 to a0fafcb Compare August 27, 2023 18:48
@ibauersachs
ibauersachs force-pushed the master branch from a0fafcb to 30ceab2 Compare August 27, 2023 18:49
@ibauersachs
ibauersachs force-pushed the master branch 2 times, most recently from a601d27 to 378aa24 Compare May 10, 2026 11:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ibauersachs ibauersachs ibauersachs requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add support for mDNS by allowing multicast server address

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@ka2ddo @ibauersachs @arnocornette
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.