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

limit read buffer size to 9000B #172

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const (
destinationAddress = "224.0.0.251:5353"
maxMessageRecords = 3
responseTTL = 120
// maxPacketSize is the maximum size of a mdns packet.
// From RFC 6762:
// Even when fragmentation is used, a Multicast DNS packet, including IP
// and UDP headers, MUST NOT exceed 9000 bytes.
// https://datatracker.ietf.org/doc/html/rfc6762#section-17
maxPacketSize = 9000
)

var errNoPositiveMTUFound = errors.New("no positive MTU found")
Expand Down Expand Up @@ -81,6 +87,9 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
if inboundBufferSize == 0 {
return nil, errNoPositiveMTUFound
}
if inboundBufferSize > maxPacketSize {
inboundBufferSize = maxPacketSize
}
if joinErrCount >= len(ifaces) {
return nil, errJoiningMulticastGroup
}
Expand Down
Loading