wireguard: fix sending peer events from worker threads 02/38502/3
authorAlexander Chernavin <[email protected]>
Thu, 16 Mar 2023 09:48:45 +0000 (09:48 +0000)
committerFan Zhang <[email protected]>
Mon, 20 Mar 2023 16:41:14 +0000 (16:41 +0000)
commitd76c029a85f0b5a4bb72c84fb4cd012cbd5465cd
tree6570d9a299f31487d179dc84406ca1c669c8bee7
parent645a588ee3a136bd68b1e89414c6b0a192df3c31
wireguard: fix sending peer events from worker threads

Type: fix

API clients can register for peer events (e.g. to be notified when
connection is established). In a multi-worker setup, peer events might
be triggered from a worker thread. In order to send a peer event to the
clients, an API message needs to be allocated and populated.

API messages allocation is only allowed from the main thread. Currently,
the code does not handle the case when a peer event is trying to be sent
from a worker thread. In debug builds, when this happens, it causes
SIGABRT in vl_msg_api_alloc_internal() because assertion "pool == 0 ||
vlib_get_thread_index () == 0" fails. In production builds, when this
happens, it might cause unexplained behavior.

There is a test that is supposed to catch this but all multi-worker
Wireguard tests are currently disabled. This problem is likely to be one
of the reasons they were disabled.

With this fix, when a peer event is triggered from a worker thread,
allocate and send corresponding API message from the main thread using
RPC.

Signed-off-by: Alexander Chernavin <[email protected]>
Change-Id: Ib3fe19f8070563b35732afd16c017411c089437e
src/plugins/wireguard/wireguard_api.c