--- bird-1.6.8/sysdep/unix/io.c.ori 2023-01-13 10:05:54.071687334 +0100 +++ bird-1.6.8/sysdep/unix/io.c 2023-01-13 10:06:02.463830758 +0100 @@ -1432,6 +1432,12 @@ case SK_UDP: fd = socket(af, SOCK_DGRAM, IPPROTO_UDP); bind_port = s->sport; + if (bind_port == 0 && (s->dport == 3784 || s->dport == 4784 || s->dport == 3785)) { + unsigned long r; + r = (unsigned long)random(); + bind_port = 49142 + (r % 16384); + } + bind_addr = (s->flags & SKF_BIND) ? s->saddr : IPA_NONE; do_bind = 1; break; @@ -1463,6 +1469,7 @@ if (do_bind) { + int retries = 5; if (bind_port) { int y = 1; @@ -1484,9 +1491,20 @@ if (sk_set_high_port(s) < 0) log(L_WARN "Socket error: %s%#m", s->err); +bind_again: + sockaddr_fill(&sa, af, bind_addr, s->iface, bind_port); - if (bind(fd, &sa.sa, SA_LEN(sa)) < 0) + if (bind(fd, &sa.sa, SA_LEN(sa)) < 0) { + if (s->dport == 3784 || s->dport == 4784 || s->dport == 3785) { + if (retries--) { + unsigned long r; + r = (unsigned long)random(); + bind_port = 49142 + (r % 16384); + goto bind_again; + } + } ERR2("bind"); + } } if (s->password)