2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

13 Commits

Author SHA1 Message Date
Ondřej Surý
552cf64a70
Replace isc_mem_destroy() with isc_mem_detach()
Remove legacy isc_mem_destroy() and just use isc_mem_detach() as
isc_mem_destroy() doesn't play well with call_rcu API.
2025-03-05 11:17:17 +01:00
Ondřej Surý
0258850f20
Remove redundant parentheses from the return statement 2024-11-19 12:27:22 +01:00
Mark Andrews
d8a6ff5c3e Extend ISC_TEST_MAIN for debugging
ISC_TEST_MAIN now supports turning on/off debugging and
running individual tests.
2024-08-22 09:54:39 +10:00
Ondřej Surý
8506102216 Remove logging context (isc_log_t) from the public namespace
Now that the logging uses single global context, remove the isc_log_t
from the public namespace.
2024-08-20 12:50:39 +00:00
Ondřej Surý
32a8773ab3
Always initialize the workers in the libtest
The workers variable might be needed even to tests not using
loopmgr. Split the workers initialization into setup_workers() function
and always call it from the default main loop.
2023-04-21 09:04:24 +02:00
Ondřej Surý
3b10814569
Fix the streaming read callback shutdown logic
When shutting down TCP sockets, the read callback calling logic was
flawed, it would call either one less callback or one extra.  Fix the
logic in the way:

1. When isc_nm_read() has been called but isc_nm_read_stop() hasn't on
   the handle, the read callback will be called with ISC_R_CANCELED to
   cancel active reading from the socket/handle.

2. When isc_nm_read() has been called and isc_nm_read_stop() has been
   called on the on the handle, the read callback will be called with
   ISC_R_SHUTTINGDOWN to signal that the dormant (not-reading) socket
   is being shut down.

3. The .reading and .recv_read flags are little bit tricky.  The
   .reading flag indicates if the outer layer is reading the data (that
   would be uv_tcp_t for TCP and isc_nmsocket_t (TCP) for TLSStream),
   the .recv_read flag indicates whether somebody is interested in the
   data read from the socket.

   Usually, you would expect that the .reading should be false when
   .recv_read is false, but it gets even more tricky with TLSStream as
   the TLS protocol might need to read from the socket even when sending
   data.

   Fix the usage of the .recv_read and .reading flags in the TLSStream
   to their true meaning - which mostly consist of using .recv_read
   everywhere and then wrapping isc_nm_read() and isc_nm_read_stop()
   with the .reading flag.

4. The TLS failed read helper has been modified to resemble the TCP code
   as much as possible, clearing and re-setting the .recv_read flag in
   the TCP timeout code has been fixed and .recv_read is now cleared
   when isc_nm_read_stop() has been called on the streaming socket.

5. The use of Network Manager in the named_controlconf, isccc_ccmsg, and
   isc_httpd units have been greatly simplified due to the improved design.

6. More unit tests for TCP and TLS testing the shutdown conditions have
   been added.

Co-authored-by: Ondřej Surý <ondrej@isc.org>
Co-authored-by: Artem Boldariev <artem@isc.org>
2023-04-20 12:58:32 +02:00
Tony Finch
906d434aea Fix Coverity complaints in the qp-trie tests
The main problem was `qp_test_keytoname()` not using `qpkey_bit()`
to do bounds checking.
2023-04-03 15:10:47 +00:00
Ondřej Surý
2c0a9575d7
Replace __attribute__((unused)) with ISC_ATTR_UNUSED attribute macro
Instead of marking the unused entities with UNUSED(x) macro in the
function body, use a `ISC_ATTR_UNUSED` attribute macro that expans to
C23 [[maybe_unused]] or __attribute__((__unused__)) as fallback.
2023-03-30 23:29:25 +02:00
Evan Hunt
a52b17d39b
remove isc_task completely
as there is no further use of isc_task in BIND, this commit removes
it, along with isc_taskmgr, isc_event, and all other related types.

functions that accepted taskmgr as a parameter have been cleaned up.
as a result of this change, some functions can no longer fail, so
they've been changed to type void, and their callers have been
updated accordingly.

the tasks table has been removed from the statistics channel and
the stats version has been updated. dns_dyndbctx has been changed
to reference the loopmgr instead of taskmgr, and DNS_DYNDB_VERSION
has been udpated as well.
2023-02-16 18:35:32 +01:00
Mark Andrews
cdcd605ede Increase the number of available file descriptors
notify_test and query_test run out of descriptors on some platforms.

    % ./notify_test
    [==========] Running 1 test(s).
    [ RUN      ] notify_start
    netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace
    0   libisc-9.19.9-dev.dylib             0x00000001045c5080 default_callback + 72
    1   libisc-9.19.9-dev.dylib             0x00000001045c4ffc isc_assertion_failed + 56
    2   libisc-9.19.9-dev.dylib             0x00000001045b8bcc start_tcp_child + 304
    3   libisc-9.19.9-dev.dylib             0x00000001045b8710 isc_nm_listentcp + 636
    4   libisc-9.19.9-dev.dylib             0x00000001045b3e0c isc_nm_listenstreamdns + 344
    5   libns-9.19.9-dev.dylib              0x0000000104b90630 ns_interface_listentcp + 152
    6   libns-9.19.9-dev.dylib              0x0000000104b8f65c interface_setup + 488
    7   libns-9.19.9-dev.dylib              0x0000000104b8de98 do_scan + 2028
    8   libns-9.19.9-dev.dylib              0x0000000104b8d640 ns_interfacemgr_scan + 212
    9   notify_test                         0x000000010418ddd0 scan_interfaces + 44
    10  libisc-9.19.9-dev.dylib             0x00000001045d5fd8 isc__job_cb + 116
    11  libuv.1.dylib                       0x000000010545afe4 uv__run_idle + 152
    12  libuv.1.dylib                       0x0000000105455cd0 uv_run + 204
    13  libisc-9.19.9-dev.dylib             0x00000001045e1120 loop_run + 460
    14  libisc-9.19.9-dev.dylib             0x00000001045df824 loop_thread + 44
    15  libisc-9.19.9-dev.dylib             0x00000001045df6dc isc_loopmgr_run + 456
    16  notify_test                         0x000000010418b900 run_test_notify_start + 88
    17  libcmocka.0.dylib                   0x00000001054968c0 cmocka_run_one_test_or_fixture + 448
    18  libcmocka.0.dylib                   0x0000000105494ca4 _cmocka_run_group_tests + 848
    19  notify_test                         0x000000010418be60 main + 120
    20  libdyld.dylib                       0x0000000181509430 start + 4
    Abort
    % ./query_test
    [==========] Running 4 test(s).
    [ RUN      ] ns__query_sfcache
    netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace
    0   libisc-9.19.9-dev.dylib             0x000000010294d080 default_callback + 72
    1   libisc-9.19.9-dev.dylib             0x000000010294cffc isc_assertion_failed + 56
    2   libisc-9.19.9-dev.dylib             0x0000000102940bcc start_tcp_child + 304
    3   libisc-9.19.9-dev.dylib             0x0000000102940710 isc_nm_listentcp + 636
    4   libisc-9.19.9-dev.dylib             0x000000010293be0c isc_nm_listenstreamdns + 344
    5   libns-9.19.9-dev.dylib              0x00000001026cc630 ns_interface_listentcp + 152
    6   libns-9.19.9-dev.dylib              0x00000001026cb65c interface_setup + 488
    7   libns-9.19.9-dev.dylib              0x00000001026c9e98 do_scan + 2028
    8   libns-9.19.9-dev.dylib              0x00000001026c9640 ns_interfacemgr_scan + 212
    9   query_test                          0x00000001026a1018 scan_interfaces + 44
    10  libisc-9.19.9-dev.dylib             0x000000010295dfd8 isc__job_cb + 116
    11  libuv.1.dylib                       0x0000000103996fe4 uv__run_idle + 152
    12  libuv.1.dylib                       0x0000000103991cd0 uv_run + 204
    13  libisc-9.19.9-dev.dylib             0x0000000102969120 loop_run + 460
    14  libisc-9.19.9-dev.dylib             0x0000000102967824 loop_thread + 44
    15  libisc-9.19.9-dev.dylib             0x00000001029676dc isc_loopmgr_run + 456
    16  query_test                          0x000000010269cf34 run_test_ns__query_sfcache + 88
    17  libcmocka.0.dylib                   0x00000001028068c0 cmocka_run_one_test_or_fixture + 448
    18  libcmocka.0.dylib                   0x0000000102804ca4 _cmocka_run_group_tests + 848
    19  query_test                          0x000000010269eab8 main + 116
    20  libdyld.dylib                       0x0000000181509430 start + 4
    Abort
    %

expected_creads can exceed the number of file descriptors on some
platforms.

    % ./udp_test
    [==========] Running 18 test(s).
    [ RUN      ] mock_listenudp_uv_udp_open
    [       OK ] mock_listenudp_uv_udp_open
    [ RUN      ] mock_listenudp_uv_udp_bind
    [       OK ] mock_listenudp_uv_udp_bind
    [ RUN      ] mock_listenudp_uv_udp_recv_start
    [       OK ] mock_listenudp_uv_udp_recv_start
    [ RUN      ] mock_udpconnect_uv_udp_open
    [       OK ] mock_udpconnect_uv_udp_open
    [ RUN      ] mock_udpconnect_uv_udp_bind
    [       OK ] mock_udpconnect_uv_udp_bind
    [ RUN      ] mock_udpconnect_uv_udp_connect
    [       OK ] mock_udpconnect_uv_udp_connect
    [ RUN      ] mock_udpconnect_uv_recv_buffer_size
    [       OK ] mock_udpconnect_uv_recv_buffer_size
    [ RUN      ] mock_udpconnect_uv_send_buffer_size
    [       OK ] mock_udpconnect_uv_send_buffer_size
    [ RUN      ] udp_noop
    [       OK ] udp_noop
    [ RUN      ] udp_noresponse
    [       OK ] udp_noresponse
    [ RUN      ] udp_shutdown_connect
    [       OK ] udp_shutdown_connect
    [ RUN      ] udp_shutdown_read
    [       OK ] udp_shutdown_read
    [ RUN      ] udp_cancel_read
    [       OK ] udp_cancel_read
    [ RUN      ] udp_timeout_recovery
    [       OK ] udp_timeout_recovery
    [ RUN      ] udp_double_read
    [       OK ] udp_double_read
    [ RUN      ] udp_recv_one
    [       OK ] udp_recv_one
    [ RUN      ] udp_recv_two
    [       OK ] udp_recv_two
    [ RUN      ] udp_recv_send
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    %
2023-01-11 10:44:07 +00:00
Ondřej Surý
b69e783164
Update netmgr, tasks, and applications to use isc_loopmgr
Previously:

* applications were using isc_app as the base unit for running the
  application and signal handling.

* networking was handled in the netmgr layer, which would start a
  number of threads, each with a uv_loop event loop.

* task/event handling was done in the isc_task unit, which used
  netmgr event loops to run the isc_event calls.

In this refactoring:

* the network manager now uses isc_loop instead of maintaining its
  own worker threads and event loops.

* the taskmgr that manages isc_task instances now also uses isc_loopmgr,
  and every isc_task runs on a specific isc_loop bound to the specific
  thread.

* applications have been updated as necessary to use the new API.

* new ISC_LOOP_TEST macros have been added to enable unit tests to
  run isc_loop event loops. unit tests have been updated to use this
  where needed.
2022-08-26 09:09:24 +02:00
Ondřej Surý
84c90e223f
New event loop handling API
This commit introduces new APIs for applications and signal handling,
intended to replace isc_app for applications built on top of libisc.

* isc_app will be replaced with isc_loopmgr, which handles the
  starting and stopping of applications. In isc_loopmgr, the main
  thread is not blocked, but is part of the working thread set.
  The loop manager will start a number of threads, each with a
  uv_loop event loop running. Setup and teardown functions can be
  assigned which will run when the loop starts and stops, and
  jobs can be scheduled to run in the meantime. When
  isc_loopmgr_shutdown() is run from any the loops, all loops
  will shut down and the application can terminate.

* signal handling will now be handled with a separate isc_signal unit.
  isc_loopmgr only handles SIGTERM and SIGINT for application
  termination, but the application may install additional signal
  handlers, such as SIGHUP as a signal to reload configuration.

* new job running primitives, isc_job and isc_async, have been added.
  Both units schedule callbacks (specifying a callback function and
  argument) on an event loop. The difference is that isc_job unit is
  unlocked and not thread-safe, so it can be used to efficiently
  run jobs in the same thread, while isc_async is thread-safe and
  uses locking, so it can be used to pass jobs from one thread to
  another.

* isc_tid will be used to track the thread ID in isc_loop worker
  threads.

* unit tests have been added for the new APIs.
2022-08-25 12:24:29 +02:00
Evan Hunt
568f65cc56 Stop the unit tests from running twice
Move the libtest code into a 'libtest' subdirectory and make it
one of the SUBDIRS in the tests Makefile. having it at the top level
required having "." as one of the subdirs, and that caused the
unit tests to be executed twice.
2022-05-28 14:53:02 -07:00