Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71ffaea4 authored by Ken Chen's avatar Ken Chen Committed by Automerger Merge Worker
Browse files

Don't use 5353 source port for mDNS queries am: f3c42075

parents cfedf73d f3c42075
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ static struct timespec evNowTime(void) {
// END: Code copied from ISC eventlib

/* BIONIC-BEGIN: implement source port randomization */
static int random_bind(int s, int family) {
static int random_bind(int s, int family, bool isMdns) {
    sockaddr_union u;
    int j;
    socklen_t slen;
@@ -279,6 +279,10 @@ static int random_bind(int s, int family) {
    for (j = 0; j < 10; j++) {
        /* find a random port between 1025 .. 65534 */
        int port = 1025 + (arc4random_uniform(65535 - 1025));
        // RFC 6762 section 5.1: Don't use 5353 source port on one-shot Multicast DNS queries. DNS
        // resolver does not fully compliant mDNS.
        if (isMdns && port == 5353) continue;

        if (family == AF_INET)
            u.sin.sin_port = htons(port);
        else
@@ -775,7 +779,7 @@ same_ns:
            }
        }
        errno = 0;
        if (random_bind(statp->tcp_nssock, nsap->sa_family) < 0) {
        if (random_bind(statp->tcp_nssock, nsap->sa_family, false /* isMdns */) < 0) {
            *terrno = errno;
            dump_error("bind/vc", nsap);
            statp->closeSockets();
@@ -1078,7 +1082,9 @@ static int setupUdpSocket(ResState* statp, const sockaddr* sockap, unique_fd* fd
        }
    }

    if (random_bind(*fd_out, sockap->sa_family) < 0) {
    const auto addr = IPSockAddr::toIPSockAddr(*sockap);
    const bool isMdns = (addr == mdns_addrs[0] || addr == mdns_addrs[1]);
    if (random_bind(*fd_out, sockap->sa_family, isMdns) < 0) {
        *terrno = errno;
        dump_error("bind", sockap);
        return 0;