25RCSID(
"$Id: 6467943ea8a676f2023f6d4d82a7ec39647294bd $")
27#define LOG_PREFIX "unbound"
29#include <freeradius-devel/server/log.h>
30#include <freeradius-devel/util/event.h>
31#include <freeradius-devel/util/syserror.h>
35#ifdef HAVE_WDOCUMENTATION
38#include <unbound-event.h>
39#ifdef HAVE_WDOCUMENTATION
92 short new = ev->
events | flags;
94 DEBUG4(
"unbound event %p - Adding flags %i (current %i, new %i)", ev, flags, ev->
events,
new);
108 short new = ev->
events & ~flags;
112 DEBUG4(
"unbound event %p - Removing flags %i (current %i, new %i)", ev, flags, ev->
events,
new);
127 if (fd == ev->
fd)
return;
129 DEBUG4(
"unbound event %p - Changed FD from %i to %i", ev, ev->
fd, fd);
141 DEBUG4(
"unbound event %p - Freed", ev);
157 DEBUG4(
"unbound event %p - Timeout", ev);
159 ev->
cb(-1, UB_EV_TIMEOUT, ev->
uctx);
174 DEBUG4(
"unbound event %p - FD %i now readable", ev, fd);
176 ev->
cb(fd, UB_EV_READ, ev->
uctx);
181 if (!(ev->
events & UB_EV_PERSIST)) {
182 DEBUG4(
"unbound event %p - UB_EV_PERSIST not set - Removing events for FD %i", ev, ev->
fd);
184 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
198 DEBUG4(
"unbound event %p - FD %i now writable", ev, fd);
200 ev->
cb(fd, UB_EV_WRITE, ev->
uctx);
205 if (!(ev->
events & UB_EV_PERSIST)) {
206 DEBUG4(
"unbound event %p - UB_EV_PERSIST not set - Removing events for FD %i", ev, ev->
fd);
208 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
222 int fd,
UNUSED int flags,
int fd_errno,
void *uctx)
236 PERROR(
"ubound event %p - Failed disarming timeout", ev);
239 ev->
cb(-1, UB_EV_TIMEOUT, ev->
uctx);
255 if ((ev->
events & UB_EV_READ) && (ev->
events & UB_EV_WRITE)) {
258 DEBUG4(
"unbound event %p - Registered for read+write events on FD %i", ev, ev->
fd);
265 PERROR(
"unbound event %p - Registration failed for read+write+error events on FD %i",
270 }
else if (ev->
events & UB_EV_READ) {
273 DEBUG4(
"unbound event %p - Registered for read+error events on FD %i", ev, ev->
fd);
280 PERROR(
"unbound event %p - Registration failed for read+error events on FD %i",
285 }
else if (ev->
events & UB_EV_WRITE) {
288 DEBUG4(
"unbound event %p - Registered for write+error events on FD %i", ev, ev->
fd);
295 PERROR(
"unbound event %p - Registration failed for write+error events on FD %i",
305 if (ev->
events & UB_EV_TIMEOUT) {
312 PERROR(
"unbound event %p - Failed adding timeout", ev);
314 if (ev->
events & (UB_EV_READ | UB_EV_WRITE)) {
335 if (!ev->
active)
return 0;
337 if (ev->
events & (UB_EV_READ | UB_EV_WRITE)) {
338 DEBUG4(
"unbound event %p - De-registering FD %i", ev, ev->
fd);
341 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
347 if (ev->
events & UB_EV_TIMEOUT) {
348 DEBUG4(
"unbound event %p - Disarming timeout", ev);
351 PERROR(
"ubound event %p - Failed disarming timeout", ev);
366 void (*cb)(
int,
short,
void*),
367 void *uctx,
struct timeval *tv)
376 DEBUG4(
"unbound event %p - New callback %p (old callback was %p)",
380 if (ev->
uctx != uctx) {
381 DEBUG4(
"unbound event %p - New uctx %p (old uctx was %p)",
386 PERROR(
"ubound event %p - Failed disarming timeout", ev);
397 PERROR(
"unbound event %p - Failed adding timeout", ev);
414 DEBUG4(
"unbound event %p - Disarming timeout", ev);
417 PERROR(
"unbound event %p - Failed disarming timeout", ev);
430 void (*cb)(
int,
short,
void*),
void *uctx)
435 static struct ub_event_vmt vmt = {
447 ev->
base.magic = UB_EVENT_MAGIC;
456 DEBUG4(
"unbound event %p - Allocated - Events %i, FD %i, callback %p, uctx %p", ev, flags, fd, cb, uctx);
458 return (
struct ub_event *)ev;
463 if (ev_b->
ub) ub_ctx_delete(ev_b->
ub);
486 static struct ub_event_base_vmt vmt = {
496 ev_b->
base.magic = UB_EVENT_MAGIC;
497 ev_b->
base.vmt = &vmt;
505 ev_b->
ub = ub_ctx_create_ub_event((
struct ub_event_base *)ev_b);
507 ERROR(
"Failed creating ub_ctx");
#define fr_event_fd_insert(...)
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
#define fr_event_timer_in(...)
int fr_event_timer_delete(fr_event_timer_t const **ev_p)
Delete a timer event from the event list.
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter)
Remove a file descriptor from the event loop.
Stores all information relating to an event list.
static void _unbound_io_service_errored(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, int fd_errno, void *uctx)
Unbound FD errored.
static void _unbound_io_event_flags_del(struct ub_event *ub_ev, short flags)
Alter the enabled flags associated with the event.
int fd
File descriptor this event handle relates to.
static int _unbound_io_timer_deactivate(struct ub_event *ub_ev)
Deactivate a timeout.
short events
The events this event handle should receive when activated.
struct ub_event base
Unbound event base, which we populate with callback functions for adding events for FDs setting timer...
static void _unbound_io_service_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
Unbound FD became writable.
int unbound_io_init(TALLOC_CTX *ctx, unbound_io_event_base_t **ev_b_out, fr_event_list_t *el)
Alloc a new event base, and unbound ctx initialised from that event base.
void(* unbound_cb_t)(int, short flags, void *uctx)
Definition for libunbound's event callback.
unbound_cb_t cb
The callback we need to call when a specified event happens.
void * uctx
This is the argument libunbound wants passed to the callback when it's called.
static void _unbound_io_service_readable(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
Unbound FD became readable.
static void _unbound_io_event_free(struct ub_event *ub_ev)
Free an event, and, by the magic of talloc, any timers or fd events.
static void _unbound_io_service_timer_expired(UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx)
Timeout fired.
unbound_io_event_base_t * ev_b
Event base this handle was created for.
static int _unbound_io_timer_modify(struct ub_event *ub_ev, UNUSED struct ub_event_base *ev_b, void(*cb)(int, short, void *), void *uctx, struct timeval *tv)
Modify an existing timeout.
static int _unbound_io_event_deactivate(struct ub_event *ub_ev)
static int _unbound_io_event_activate(struct ub_event *ub_ev, struct timeval *tv)
Activate FD events and set a timer for a timeout.
static void _unbound_io_event_flags_add(struct ub_event *ub_ev, short flags)
Alter the enabled flags associated with the event.
static int _event_base_free(unbound_io_event_base_t *ev_b)
static struct ub_event * _unbound_io_event_new(struct ub_event_base *base, int fd, short flags, void(*cb)(int, short, void *), void *uctx)
Returns a new libunbound event handle.
fr_event_timer_t const * timer
Stores the pointer to the enabled timer for this event handled.
static void _unbound_io_event_fd_set(struct ub_event *ub_ev, int fd)
Change the file descriptor associated with an event.
bool active
Whether this event is considered active.
Wrapper around event handle for our event loop.
Function prototypes and datatypes for the REST (HTTP) transport.
struct ub_ctx * ub
Unbound ctx instantiated from this event base.
struct ub_event_base base
Interface structure for libunbound.
fr_event_list_t * el
Event loop events should be inserted into.
Wrapper around our event loop specifying callbacks for creating new event handles.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
static fr_time_delta_t fr_time_delta_from_timeval(struct timeval const *tv)
A time delta, a difference in time measured in nanoseconds.
static fr_event_list_t * el
#define fr_box_time_delta(_val)