On Sat, Aug 29 2020, Stuart Henderson <s...@spacehopper.org> wrote:
> On 2020/08/27 15:28, Florian Obser wrote:
>> all heavy lifting done by sthen in unbound
>> 
>> tests?
>
> ok with me. only tested lightly (the machine I normally use does DNS for
> other machines too so runs unbound).
>
> related, any idea what's happening here?
>
> unwind[51500]: fatal in main: could not bind to 127.0.0.1 or ::1 on port 53: 
> Address already in use
>
> unbound is listening to *:53, but shouldn't other software be able to
> listen if bound to a specific address like 127.0.0.1:53? is this a bug
> somewhere or am I just missing something about UDP?

Once *:53 is bound you need SO_REUSEADDR to loosen the checks.  ktrace
says unbound(8) uses this unconditionally.  ChangeLog entry:

        - Fix #531: Set SO_REUSEADDR so that the wildcard interface and a 
          more specific interface port 53 can be used at the same time, and
          one of the daemons is unbound.

I think unwind could use the same treatment.

Note that using SO_REUSEADDR still prevents two unwind copies from
binding to 127.0.0.1:53 / [::1]:53 (for that to work you'd need
SO_REUSEPORT instead).

Thoughts?  oks?


Index: unwind.c
===================================================================
RCS file: /d/cvs/src/sbin/unwind/unwind.c,v
retrieving revision 1.47
diff -u -p -p -u -r1.47 unwind.c
--- unwind.c    25 May 2020 16:52:15 -0000      1.47
+++ unwind.c    29 Aug 2020 17:07:49 -0000
@@ -726,6 +726,7 @@ open_ports(void)
 {
        struct addrinfo  hints, *res0;
        int              udp4sock = -1, udp6sock = -1, error;
+       int              opt = 1;
 
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_INET;
@@ -736,6 +737,9 @@ open_ports(void)
        if (!error && res0) {
                if ((udp4sock = socket(res0->ai_family, res0->ai_socktype,
                    res0->ai_protocol)) != -1) {
+                       if (setsockopt(udp4sock, SOL_SOCKET, SO_REUSEADDR,
+                           &opt, sizeof(opt)) == -1)
+                               log_warn("setting SO_REUSEADDR on socket");
                        if (bind(udp4sock, res0->ai_addr, res0->ai_addrlen)
                            == -1) {
                                close(udp4sock);
@@ -751,6 +755,9 @@ open_ports(void)
        if (!error && res0) {
                if ((udp6sock = socket(res0->ai_family, res0->ai_socktype,
                    res0->ai_protocol)) != -1) {
+                       if (setsockopt(udp6sock, SOL_SOCKET, SO_REUSEADDR,
+                           &opt, sizeof(opt)) == -1)
+                               log_warn("setting SO_REUSEADDR on socket");
                        if (bind(udp6sock, res0->ai_addr, res0->ai_addrlen)
                            == -1) {
                                close(udp6sock);


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to