-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Compressed dns #3769
Compressed dns #3769
Conversation
7ea02cf
to
c10892a
Compare
c10892a
to
3f03ef0
Compare
@@ -539,15 +539,24 @@ void MDNSResponder::_parsePacket(){ | |||
while (numAnswers--) { | |||
// Read name | |||
stringsRead = 0; | |||
size_t here = 0; |
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.
Please rename this into something more meaningful
@@ -632,31 +649,36 @@ void MDNSResponder::_parsePacket(){ | |||
uint16_t answerPrio = _conn_read16(); // Read priority | |||
uint16_t answerWeight = _conn_read16(); // Read weight | |||
answerPort = _conn_read16(); // Read port | |||
size_t here = 0; |
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.
Doesn't this declaration of here shadow the declaration on line 542?
e3a3a00
to
873a173
Compare
Thank you for the feedback, I updated the code accordingly. |
873a173
to
bd6c859
Compare
bd6c859
to
7065571
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.
I don't know the changes of compressed dns, but the code changes look ok.
Help needed with testing this! |
The way I discovered this was missing was that I got errors with mDNS when connecting to a mac (which is compressing its data). Thus, to test this, set up a local domain with dns-sd with and without this patch and monitor the esp8266 errors on the serial port as it tries to connect (compile with DEBUG_ESP_MDNS_RX) |
@jonatanolofsson my wife has a mac. I hate the thing, but I could use it to test this, if you provide detailed instructions for the setup on it. |
if (tmp8 == 0x00) { // End of name | ||
break; | ||
} | ||
if (tmp8 & 0xC0) { // Compressed pointer | ||
uint16_t offset = ((((uint16_t)tmp8) & 0xC0) << 8) | _conn_read8(); |
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.
-
Would the resulting offset's boundaries be checked here ?
-
If the first byte is 0xca and the second 0xaa, then the offset would be 0xcaaa.
Would it not be 0xaaa like with (((uint16_t)(tmp8 & ~0xC0)) << 8) | _conn_read8() ?
d8d1467
to
7f645e0
Compare
|
||
(void) answerPrio; | ||
(void) answerWeight; | ||
|
||
// Read hostname | ||
tmp8 = _conn_read8(); | ||
if (tmp8 & 0xC0) { // Compressed pointer (not supported) | ||
if (tmp8 & 0xC0) { // Compressed pointer | ||
uint16_t offset = ((((uint16_t)tmp8) & 0xC0) << 8) | _conn_read8(); |
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.
Is it &~0xc0 too here ?
|
||
(void) answerPrio; | ||
(void) answerWeight; | ||
|
||
// Read hostname | ||
tmp8 = _conn_read8(); | ||
if (tmp8 & 0xC0) { // Compressed pointer (not supported) | ||
if (tmp8 & 0xC0) { // Compressed pointer | ||
uint16_t offset = ((((uint16_t)tmp8) & 0xC0) << 8) | _conn_read8(); |
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.
Do you think the calculated offset can be checked beeing out of bound to prevent crashing with malformed or crafted dns replies ?
dcd569f
to
1adb42f
Compare
} | ||
|
||
bool isValidOffset(const size_t pos) const { | ||
return (pos <= _rx_buf->len); |
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.
Since you are going to use this offset, would'nt it be pos < _rx_buf->len
?
Sorry I don't mean to be pushy :]
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.
Not at all, I appreciate your comments, I just havn't had much time to do more than fix them during breaks at work today =D
The check on line 222 in the 'read' function checks if the offset is at least equal to the limit, which should give that to set the buffer as "fully read", the offset should be set just past the limit, i.e. equal to the length. I figured "finished reading" was a valid use-case and thus a valid offset.
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 explanation
DEBUG_ESP_PORT.println(offset); | ||
#endif | ||
_conn->seek(offset); | ||
tmp8 = _conn_read8(); |
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.
Are you reading tmp8 twice (here and in L568) ?
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.
Indeed, I forgot to remove the second one. Fixed.
@jonatanolofsson can you tell us more about the steps to test your PR ? |
1adb42f
to
f81af25
Compare
I'll try to find time to make a test description. Not going to happen this week unfortunately. My computer is a mac, but I'm only ever booting into linux anymore :) |
Linux is no problem if you know how to update avahi's conffile so. |
Right, I wasn't sure if avahi compressed the payload |
f81af25
to
2570bdc
Compare
2570bdc
to
1d702d5
Compare
@jonatanolofsson I now understand your code changes, and I think they are correct. I am currently rewriting the mdns code based on the idf functionality, and was struggling a bit with compression (it's very different in idf due to fundamental differences in how things work at low level). This helps quite a bit. I'll merge this, and integrate it into my current work. |
* Add UdpContext seek and tell * Add support for DNS compressed messages * mDNS compressed pointer: Validate offset before jumping (cherry picked from commit 461c922)
According to (RFC 1035), clients must understand compressed dns messages. These commits aim to add the support of this to the ESP8266mDNS library.