1. 05 Oct, 2020 3 commits
  2. 28 Sep, 2020 1 commit
    • Ondřej Surý's avatar
      Refactor the pausing/unpausing and finishing the nm_thread · e5ab137b
      Ondřej Surý authored
      The isc_nm_pause(), isc_nm_resume() and finishing the nm_thread() from
      nm_destroy() has been refactored, so all use the netievents instead of
      directly touching the worker structure members.  This allows us to
      remove most of the locking as the .paused and .finished members are
      always accessed from the matching nm_thread.
      
      When shutting down the nm_thread(), instead of issuing uv_stop(), we
      just shutdown the .async handler, so all uv_loop_t events are properly
      finished first and uv_run() ends gracefully with no outstanding active
      handles in the loop.
      e5ab137b
  3. 14 Sep, 2020 1 commit
  4. 11 Sep, 2020 5 commits
    • Witold Krecicki's avatar
      tracing of active sockets and handles · 00e04a86
      Witold Krecicki authored
      If NETMGR_TRACE is defined, we now maintain a list of active sockets
      in the netmgr object and a list of active handles in each socket
      object; by walking the list and printing `backtrace` in a debugger
      we can see where they were created, to assist in in debugging of
      reference counting errors.
      
      On shutdown, if netmgr finds there are still active sockets after
      waiting, isc__nm_dump_active() will be called to log the list of
      active sockets and their underlying handles, along with some details
      about them.
      00e04a86
    • Evan Hunt's avatar
      limit the time we wait for netmgr to be destroyed · 2f2d60a9
      Evan Hunt authored
      if more than 10 seconds pass while we wait for netmgr events to
      finish running on shutdown, something is almost certainly wrong
      and we should assert and crash.
      2f2d60a9
    • Ondřej Surý's avatar
      properly lock the setting/unsetting of callbacks in isc_nmsocket_t · 89c534d3
      Ondřej Surý authored
      changes to socket callback functions were not thread safe.
      89c534d3
    • Evan Hunt's avatar
      change from isc_nmhandle_ref/unref to isc_nmhandle attach/detach · 57b4dde9
      Evan Hunt authored
      Attaching and detaching handle pointers will make it easier to
      determine where and why reference counting errors have occurred.
      
      A handle needs to be referenced more than once when multiple
      asynchronous operations are in flight, so callers must now maintain
      multiple handle pointers for each pending operation. For example,
      ns_client objects now contain:
      
              - reqhandle:    held while waiting for a request callback (query,
                              notify, update)
              - sendhandle:   held while waiting for a send callback
              - fetchhandle:  held while waiting for a recursive fetch to
                              complete
              - updatehandle: held while waiting for an update-forwarding
                              task to complete
      
      control channel connection objects now contain:
      
              - readhandle: held while waiting for a read callback
              - sendhandle: held while waiting for a send callback
              - cmdhandle:  held while an rndc command is running
      
      httpd connections contain:
      
              - readhandle: held while waiting for a read callback
              - sendhandle: held while waiting for a send callback
      57b4dde9
    • Witold Krecicki's avatar
      assorted small netmgr-related changes · 7eb45648
      Witold Krecicki authored
      - rename isc_nmsocket_t->tcphandle to statichandle
      - cancelread functions now take handles instead of sockets
      - add a 'client' flag in socket objects, currently unused, to
        indicate whether it is to be used as a client or server socket
      7eb45648
  5. 05 Aug, 2020 1 commit
    • Evan Hunt's avatar
      Use different allocators for UDP and TCP · 38264b6a
      Evan Hunt authored
      Each worker has a receive buffer with space for 20 DNS messages of up
      to 2^16 bytes each, and the allocator function passed to uv_read_start()
      or uv_udp_recv_start() will reserve a portion of it for use by sockets.
      UDP can use recvmmsg() and so it needs that entire space, but TCP reads
      one message at a time.
      
      This commit introduces separate allocator functions for TCP and UDP
      setting different buffer size limits, so that libuv will provide the
      correct buffer sizes to each of them.
      38264b6a
  6. 31 Jul, 2020 1 commit
    • Witold Krecicki's avatar
      netmgr: retry binding with IP_FREEBIND when EADDRNOTAVAIL is returned. · a0f7d289
      Witold Krecicki authored
      When a new IPv6 interface/address appears it's first in a tentative
      state - in which we cannot bind to it, yet it's already being reported
      by the route socket. Because of that BIND9 is unable to listen on any
      newly detected IPv6 addresses. Fix it by setting IP_FREEBIND option (or
      equivalent option on other OSes) and then retrying bind() call.
      a0f7d289
  7. 13 Jul, 2020 1 commit
  8. 01 Jul, 2020 1 commit
  9. 26 Jun, 2020 3 commits
    • Evan Hunt's avatar
      Make netmgr tcpdns send calls asynchronous · 591b79b5
      Evan Hunt authored
      isc__nm_tcpdns_send() was not asynchronous and accessed socket
      internal fields in an unsafe manner, which could lead to a race
      condition and subsequent crash. Fix it by moving tcpdns processing
      to a proper netmgr thread.
      591b79b5
    • Witold Krecicki's avatar
      Fix a shutdown race in netmgr udp · 1cf65cd8
      Witold Krecicki authored
      We need to mark the socket as inactive early (and synchronously)
      in the stoplistening process; otherwise we might destroy the
      callback argument before we actually stop listening, and call
      the callback on bad memory.
      1cf65cd8
    • Evan Hunt's avatar
      clean up outerhandle when a tcpdns socket is disconnected · 3704c4ff
      Evan Hunt authored
      this prevents a crash when some non-netmgr thread, such as a
      recursive lookup, times out after the TCP socket is already
      disconnected.
      3704c4ff
  10. 19 Jun, 2020 6 commits
    • Evan Hunt's avatar
      implement isc_nm_cancelread() · 5191ec8f
      Evan Hunt authored
      The isc_nm_cancelread() function cancels reading on a connected
      socket and calls its read callback function with a 'result'
      parameter of ISC_R_CANCELED.
      5191ec8f
    • Evan Hunt's avatar
      shorten the sleep in isc_nm_destroy() · 870204fe
      Evan Hunt authored
      when isc_nm_destroy() is called, there's a loop that waits for
      other references to be detached, pausing and unpausing the netmgr
      to ensure that all the workers' events are run, followed by a
      1-second sleep. this caused a delay on shutdown which will be
      noticeable when netmgr is used in tools other than named itself,
      so the delay has now been reduced to a hundredth of a second.
      870204fe
    • Evan Hunt's avatar
      implement isc_nm_tcpconnect() · abbb79f9
      Evan Hunt authored
      the isc_nm_tcpconnect() function establishes a client connection via
      TCP.  once the connection is esablished, a callback function will be
      called with a newly created network manager handle.
      abbb79f9
    • Witold Krecicki's avatar
      allow tcpdns sockets to self-reference while connected · cd79b495
      Witold Krecicki authored
      A TCPDNS socket creates a handle for each complete DNS message.
      
      Previously, when all the handles were disconnected, the socket
      would be closed, but the wrapped TCP socket might still have
      more to read.
      
      Now, when a connection is established, the TCPDNS socket creates
      a reference to itself by attaching itself to sock->self. This
      reference isn't cleared until the connection is closed via
      EOF, timeout, or server shutdown. This allows the socket to remain
      open even when there are no active handles for it.
      cd79b495
    • Evan Hunt's avatar
      modify reference counting within netmgr · 5ea26ee1
      Evan Hunt authored
      - isc__nmhandle_get() now attaches to the sock in the nmhandle object.
        the caller is responsible for dereferencing the original socket
        pointer when necessary.
      - tcpdns listener sockets attach sock->outer to the outer tcp listener
        socket. tcpdns connected sockets attach sock->outerhandle to the handle
        for the tcp connected socket.
      - only listener sockets need to be attached/detached directly. connected
        sockets should only be accessed and reference-counted via their
        associated handles.
      5ea26ee1
    • Evan Hunt's avatar
      make isc_nmsocket_{attach,detach}{} functions private · 9e740cad
      Evan Hunt authored
      there is no need for a caller to reference-count socket objects.
      they need tto be able tto close listener sockets (i.e., those
      returned by isc_nm_listen{udp,tcp,tcpdns}), and an isc_nmsocket_close()
      function has been added for that. other sockets are only accessed via
      handles.
      9e740cad
  11. 11 Jun, 2020 1 commit
  12. 29 May, 2020 2 commits
  13. 25 May, 2020 1 commit
  14. 13 May, 2020 1 commit
    • Witold Krecicki's avatar
      Redesigned TCP accepting: one listen/accept loop, passing the connected socket. · 60629e5b
      Witold Krecicki authored
      Instead of using bind() and passing the listening socket to the children
      threads using uv_export/uv_import use one thread that does the accepting,
      and then passes the connected socket using uv_export/uv_import to a random
      worker. The previous solution had thundering herd problems (all workers
      waking up on one connection and trying to accept()), this one avoids this
      and is simpler.
      The tcp clients quota is simplified with isc_quota_attach_cb - a callback
      is issued when the quota is available.
      60629e5b
  15. 30 Apr, 2020 1 commit
  16. 21 Apr, 2020 1 commit
    • Ondřej Surý's avatar
      Complete rewrite the BIND 9 build system · 978c7b2e
      Ondřej Surý authored
      The rewrite of BIND 9 build system is a large work and cannot be reasonable
      split into separate merge requests.  Addition of the automake has a positive
      effect on the readability and maintainability of the build system as it is more
      declarative, it allows conditional and we are able to drop all of the custom
      make code that BIND 9 developed over the years to overcome the deficiencies of
      autoconf + custom Makefile.in files.
      
      This squashed commit contains following changes:
      
      - conversion (or rather fresh rewrite) of all Makefile.in files to Makefile.am
        by using automake
      
      - the libtool is now properly integrated with automake (the way we used it
        was rather hackish as the only official way how to use libtool is via
        automake
      
      - the dynamic module loading was rewritten from a custom patchwork to libtool's
        libltdl (which includes the patchwork to support module loading on different
        systems internally)
      
      - conversion of the unit test executor from kyua to automake ...
      978c7b2e
  17. 03 Apr, 2020 1 commit
  18. 30 Mar, 2020 1 commit
  19. 24 Mar, 2020 1 commit
    • Witold Krecicki's avatar
      netmgr refactoring: use generic functions when operating on sockets. · 5fedd21e
      Witold Krecicki authored
      tcpdns used transport-specific functions to operate on the outer socket.
      Use generic ones instead, and select the proper call in netmgr.c.
      Make the missing functions (e.g. isc_nm_read) generic and add type-specific
      calls (isc__nm_tcp_read). This is the preparation for netmgr TLS layer.
      5fedd21e
  20. 05 Mar, 2020 2 commits
  21. 28 Feb, 2020 1 commit
  22. 18 Feb, 2020 1 commit
  23. 14 Feb, 2020 1 commit
  24. 13 Feb, 2020 2 commits
    • Evan Hunt's avatar
      apply the modified style · e851ed0b
      Evan Hunt authored
      e851ed0b
    • Ondřej Surý's avatar
      Use clang-tidy to add curly braces around one-line statements · 056e133c
      Ondřej Surý authored
      The command used to reformat the files in this commit was:
      
      ./util/run-clang-tidy \
      	-clang-tidy-binary clang-tidy-11
      	-clang-apply-replacements-binary clang-apply-replacements-11 \
      	-checks=-*,readability-braces-around-statements \
      	-j 9 \
      	-fix \
      	-format \
      	-style=file \
      	-quiet
      clang-format -i --style=format $(git ls-files '*.c' '*.h')
      uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h')
      clang-format -i --style=format $(git ls-files '*.c' '*.h')
      056e133c