"""Bounded packet-only mDNS transport for the appointed host LAN and manager. No DNS records are generated or rewritten. Private injection uses multicast hop-limit zero: local DNS-SD consumers receive the real packet, but pasta cannot send the injected copy back out. Host loopback copies are bounded/deduplicated. """ import hashlib import ipaddress import socket import struct import time PORT=5353 GROUP4='224.0.0.251' GROUP6='ff02::fb' MAX_PACKET=9000 def validate(value,uplink): if type(value) is not dict or set(value)!={'interface','ifindex','ipv4'}:raise ValueError('mDNS scope fields') if value['interface']!=uplink['wan'][0] or value['ipv4']!=uplink['wan'][2] or uplink.get('routing')!='host-dual-stack':raise ValueError('mDNS must use the appointed physical uplink') if type(value['ifindex']) is not int or not 0now} key=hashlib.sha256(packet).digest() if realm=='host' and key in self.recent:return if realm=='managed': if len(self.recent)>=256:return self.recent[key]=now+1 target.sendto(packet,destination(target)) if realm not in self.observed: self.observed.add(realm) print('C01_MDNS_FORWARD family='+('4' if source.family==socket.AF_INET else '6')+' source='+realm,flush=True) def close(self): self.managed.close() # host socket belongs to the ordinary listener lease