Skip to content

Ignore queries from sources that are not on the link - #532

Closed
aazf wants to merge 1 commit into
keepsimple1:mainfrom
micaoss:upstream/on-link-source
Closed

aazf wants to merge 1 commit into
keepsimple1:mainfrom
micaoss:upstream/on-link-source

Conversation

@aazf

@aazf aazf commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

RFC 6762 section 11 (Source Address Check): a responder should not answer a query whose source is not on the local link.

Multicast queries cannot cross a router, so a query from an off-link source reached the host through its unicast address on port 5353. Today handle_query answers it, and a legacy unicast query (source port other than 5353) is answered by unicast to that source address and port, whatever it is. A host with a routed address and no firewall then answers spoofed queries from anywhere, which makes it a small reflector.

This change drops a query in handle_query unless one of these holds:

  • its source lies in a subnet of one of the receiving interface's addresses (valid_ip_on_intf);
  • its source is link-local (169.254.0.0/16, fe80::/10), which is on-link by definition.

Tests:

  • test_query_from_off_link_source_is_not_answered narrows the loopback interface to 127.0.0.1/32, then checks that a querier at 127.0.0.1 is answered and one at 127.0.0.2 is not. It fails without the check.
  • test_link_local_sources_are_on_link covers the link-local cases.

cargo test --lib passes.

Happy to put this behind an option if you prefer a default that keeps today's behaviour.

RFC 6762 section 11 (Source Address Check) says a responder should not
answer a query whose source is not on the local link. Multicast queries
cannot cross a router, so such a query was sent to this host's unicast
address from elsewhere; answering it, in particular with a legacy
unicast response to an arbitrary address and port, makes the host a
reflector for spoofed queries when it has a routed address.

handle_query now drops a query unless its source lies in a subnet of
one of the receiving interface's addresses, or is a link-local address
(169.254.0.0/16, fe80::/10), which is on-link by definition.
aazf added a commit to micaoss/mica-core that referenced this pull request Oct 25, 2026
A responder on mdns-sd, on both inits, answers <hostname>.local on every
interface but loopback, the container links, WireGuard and CAN, and
publishes _mica._tcp (TXT txtvers, product, hostname), the console
while apid serves the network, and SSH while it is on. A query from off
the link is not answered: mdns-sd is pinned to the micaoss fork carrying
the on-link source check and a cap on legacy-unicast answers
(keepsimple1/mdns-sd#532) until upstream releases it.

access.mdns.enabled switches it, else the product's MDNS= line; off is
no socket. The resolved drop-in now says MulticastDNS=no, so resolved
never becomes a second responder on 5353.

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! The intention is valid. Comments inline.

Comment thread src/service_daemon.rs
fn is_on_link(addr: &IpAddr, intf: &MyIntf) -> bool {
let link_local = match addr {
IpAddr::V4(v4) => v4.is_link_local(),
IpAddr::V6(v6) => (v6.segments()[0] & 0xffc0) == 0xfe80,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: add a comment:

// Same as Ipv6Addr::is_unicast_link_local(), which needs Rust 1.84 (MSRV is 1.71).

Comment thread src/service_daemon.rs
/// addresses, or a link-local address, which is on-link by definition.
fn is_on_link(addr: &IpAddr, intf: &MyIntf) -> bool {
let link_local = match addr {
IpAddr::V4(v4) => v4.is_link_local(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note: the RFC 6762 section 11 checks IPv4 local addresses in the same way as valid_ip_on_intf , not blindly accepts source address 169.254/16 if the local interface does not have 169.254/16 address:

 An IPv4 source address 
        is determined to be on a local subnet if, for (one of) the
        address(es) configured on the interface receiving the packet, (I
        & M) == (P & M), where I and M are the interface address and
        subnet mask respectively, P is the source IP address from the
        packet, '&' represents the bitwise logical 'and' operation, and
        '==' represents a bitwise equality test. 

i.e. but I think either way is fine, i.e. keeping the 169.254/16 exemption is defensible, so we can keep it .

Comment thread src/service_daemon.rs
// cannot cross a router, so such a query was sent to this host's
// unicast address from elsewhere, possibly with a spoofed source, and
// a reply would make this host a reflector.
if !is_on_link(&querier_ip, intf) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only check the source address when the incoming packet destination address is not multicast address. In RFC 6762 section 11:

All responses received with a destination address in the IP
        header that is the mDNS IPv4 link-local multicast address
        224.0.0.251 or the mDNS IPv6 link-local multicast address
        FF02::FB are necessarily deemed to have originated on the local
        link, regardless of source IP address. 

Also it's mentioned in RFC 6762 section 5.5

sock.pktinfo.recv() returns a PktInfo with addr_dst so we could pass the destination into handle_query.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants