Comments (21)
buf.set_len(sz) is unsafe
buf.truncate(sz) is ok
from mdns-sd.
Two panic!
for _ in 0..n {
let name = self.read_name()?;
let slice = &self.data[self.offset..];
// ***************** slice.len() < 10
let ty = u16_from_be_slice(&slice[..2]);
let class = u16_from_be_slice(&slice[2..4]);
let ttl = u32_from_be_slice(&slice[4..8]);
let length = u16_from_be_slice(&slice[8..10]) as usize;
self.offset += 10;
let next_offset = self.offset + length;
// Check the first 2 bits for possible "Message compression".
match length & 0xC0 {
0x00 => {
// regular utf8 string with length
offset += 1;
// **************** (offset + length as usize) > data.len()
name += str::from_utf8(&data[offset..(offset + length as usize)])
.map_err(|e| Error::Msg(format!("read_name: from_utf8: {}", e)))?;
name += ".";
offset += length as usize;
}
from mdns-sd.
In my environment, MDNS has a relatively large amount of data, and the problem of data loss is often caused by the read cache being full. So it also causes the above problems.
from mdns-sd.
buf.set_len(sz) is unsafe buf.truncate(sz) is ok
I couldn't remember why we didn't truncate the buffer after the read
. One possible reason is DnsIncoming
decoding the buffer does not require the truncate (The decoding relies on the message format). But anyhow we can add buf.truncate(sz)
.
from mdns-sd.
// ***************** slice.len() < 10
I think it's a good idea to add a check for the slice length and return Err
if fails.
from mdns-sd.
// **************** (offset + length as usize) > data.len()
Same here, I agree it's good to check the length here.
from mdns-sd.
In my environment, MDNS has a relatively large amount of data, and the problem of data loss is often caused by the read cache being full. So it also causes the above problems.
What the typical and max size of your mDNS message? Did you mean the mDNS message in your env. is larger than MAX_MSG_ABSOLUTE i.e. 8966 bytes? The RFC says a Multicast DNS packet, including IP and UDP headers, MUST NOT exceed 9000 bytes
(here).
from mdns-sd.
For the sanity checks, I've opened a PR to add them. Let me know if you have any questions or comments.
from mdns-sd.
PR merged. Let me know if you have any questions.
from mdns-sd.
In my environment, MDNS has a relatively large amount of data, and the problem of data loss is often caused by the read cache being full. So it also causes the above problems.
What the typical and max size of your mDNS message? Did you mean the mDNS message in your env. is larger than MAX_MSG_ABSOLUTE i.e. 8966 bytes? The RFC says
a Multicast DNS packet, including IP and UDP headers, MUST NOT exceed 9000 bytes
(here).
I did receive an oversized package, if it's illegal, then ignore it.
from mdns-sd.
PR merged. Let me know if you have any questions.
Good!
from mdns-sd.
In my environment, MDNS has a relatively large amount of data, and the problem of data loss is often caused by the read cache being full. So it also causes the above problems.
What the typical and max size of your mDNS message? Did you mean the mDNS message in your env. is larger than MAX_MSG_ABSOLUTE i.e. 8966 bytes? The RFC says
a Multicast DNS packet, including IP and UDP headers, MUST NOT exceed 9000 bytes
(here).I did receive an oversized package, if it's illegal, then ignore it.
According to WireShark, the packet size is 1030 bytes, far from the max size (8966 bytes). I didn't see obvious problems here. Let me know if you encountered any particular issues.
![mdns-sd-wireshark-2024-02-04](https://private-user-images.githubusercontent.com/7699244/302122524-766f7986-4b58-4c7d-8c79-08419422046e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg2NTk4NzMsIm5iZiI6MTcxODY1OTU3MywicGF0aCI6Ii83Njk5MjQ0LzMwMjEyMjUyNC03NjZmNzk4Ni00YjU4LTRjN2QtOGM3OS0wODQxOTQyMjA0NmUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTdUMjEyNjEzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjE3YjM3NDgwODRlZDg3OWRjYzUzOGJkYWFhNjZiMDRhZjlhMmQzY2Y1ZDYyNzNkNWRiZDc5MjMwNGI0NjEwMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.O8FepDzJxjn575yeK0SW5mci5LVMm1j4BFZDnwvJoKc)
from mdns-sd.
All 11 frames form one package.
from mdns-sd.
Oh I missed that, sorry. It is a fragmented IP packet. We don't support fragmented IP packets yet. This would be a new feature and it will take some time to implement if I would do it. Would you be interested in creating a PR to add this new feature to support IP fragments?
from mdns-sd.
from mdns-sd.
Regarding IP fragmentation, it seems that UDP packet received by the socket should already be reassembled, if no dropped packets. From ChatGPT:
In summary, IP handles fragmentation and reassembly, and this applies to both TCP and UDP traffic. UDP itself, being a simple and connectionless protocol, doesn't have built-in mechanisms for handling fragmentation or reassembly.
That means we need not (and should not) have special logic to handle IP fragments.
And as what Dale mentioned :
Basically, an mdns datagram can not be larger than 9000 even when
fragmented into multiple UDP packets. And also can not contain more
than one resource record.
We should be good with the current max size (around 9000). For any large RR (resource record), it should be sent in a separate mDNS datagram.
Looking back at your capture, it seems that all 377 RRs are sent in a single datagram of 15794 bytes, which conflicts the RFC recommendation.
![mdns-wireshark-large](https://private-user-images.githubusercontent.com/7699244/302451289-cdd2e5d1-ed7e-4d84-8654-68581b5c6ac5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg2NTk4NzMsIm5iZiI6MTcxODY1OTU3MywicGF0aCI6Ii83Njk5MjQ0LzMwMjQ1MTI4OS1jZGQyZTVkMS1lZDdlLTRkODQtODY1NC02ODU4MWI1YzZhYzUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTdUMjEyNjEzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Mzc3NmZlZTg0MTA4MWIyZjY1NmYzZWYxYjgwM2ZiZmQ1ZmZiYzFlYmRhOTVmZDc4NDI4ZTJkZmIxY2Y2Zjc1NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Y3MqTyQivlTISKRqRrH4iFFlWLZEz_ynK9MzH6rl5oM)
from mdns-sd.
from mdns-sd.
I'm curious what is generating that huge datagram! Is that Bonjour or Avahi? Some other library? Something homebrewed? What kind of device is sending that? Thanks! -Dale
I guess it comes from the jmdns package used by my colleague, but I haven't personally verified it yet.
from mdns-sd.
I don't think we need to support such datagram that is clearly outside of the RFC. On the other hand, I will think of how we can handle such cases more gracefully.
from mdns-sd.
I had to re-learn some details about UDP socket API. Here is a related info about the recv/recv_from
API on Linux:
If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from.
and in the classic book "TCP/IP Illustrated, volume 1", chapter 11, section 11.10 Maximum UDP Datagram Size, it says this about "Datagram Truncation":
What happens if the received datagram exceeds the size the application is prepared to deal with? Unfortunately the answer depends on the programming interface and the implementation.
It then says the sockets API under SVR4 Unix does not truncate the datagram.
Based on the above, I think there is no much more we can do (or should do) besides the sanity checks in the current code.
If a mDNS datagram happens to exceed the max buffer size, it will not be decoded correctly / fully. And if there is no truncation, the follow-up read will have invalid headers, etc, and will fail the decode process with an Err return. As long as there is no crash, I think we are good.
from mdns-sd.
I've merged in the minor change of MAX_MSG_ABSOLUTE and added comments. Will close this issue. If you have any additional questions, please re-open this issue or open a new issue. Cheers!
from mdns-sd.
Related Issues (20)
- Trouble with query_missing_srv() HOT 5
- check_service_name_length() attempt to subtract with overflow HOT 5
- Updating service info when service is registered HOT 2
- A and AAAA mDNS records HOT 13
- Use `serde` for de/ser Txt Records HOT 4
- Failed to send to ... Resource temporarily unavailable (os error 11) HOT 2
- When a receiver is dropped, the error produced by sender should not be Error HOT 5
- Issues with using a multicast IP for a service HOT 7
- Services published using python-zerconf or systemd-resolved are not resolved HOT 17
- Utility function to resolve mDNS hostnames HOT 7
- Add support for traffic reduction techniques from RFC6762, sec. 7 HOT 1
- Too verbose logging, even when logging is not enabled HOT 6
- question about interaction between record refresh and cache flush bit HOT 5
- Refactor functions warned by clippy::cognitive_complexity lint HOT 2
- Some weird caching behavior HOT 8
- Having a browse running for a longer time, services with a ttl of 60 are sort of flapping HOT 13
- Test `integration_success` fails on Windows HOT 5
- submit by mistake
- Reverse DNS lookup query HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdns-sd.