25RCSID(
"$Id: 71cdf304bfeecaf53b6ca8e14697c8808cbab71f $")
27#define LOG_PREFIX "unbound"
29#include <freeradius-devel/server/log.h>
30#include <freeradius-devel/util/debug.h>
31#include <freeradius-devel/util/event.h>
32#include <freeradius-devel/util/syserror.h>
36#ifdef HAVE_WDOCUMENTATION
39#include <unbound-event.h>
40#ifdef HAVE_WDOCUMENTATION
93 short new = ev->
events | flags;
95 DEBUG4(
"unbound event %p - Adding flags %i (current %i, new %i)", ev, flags, ev->
events,
new);
109 short new = ev->
events & ~flags;
113 DEBUG4(
"unbound event %p - Removing flags %i (current %i, new %i)", ev, flags, ev->
events,
new);
128 if (fd == ev->
fd)
return;
130 DEBUG4(
"unbound event %p - Changed FD from %i to %i", ev, ev->
fd, fd);
142 DEBUG4(
"unbound event %p - Freed", ev);
158 DEBUG4(
"unbound event %p - Timeout", ev);
160 ev->
cb(-1, UB_EV_TIMEOUT, ev->
uctx);
175 DEBUG4(
"unbound event %p - FD %i now readable", ev, fd);
177 ev->
cb(fd, UB_EV_READ, ev->
uctx);
182 if (!(ev->
events & UB_EV_PERSIST)) {
183 DEBUG4(
"unbound event %p - UB_EV_PERSIST not set - Removing events for FD %i", ev, ev->
fd);
185 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
199 DEBUG4(
"unbound event %p - FD %i now writable", ev, fd);
201 ev->
cb(fd, UB_EV_WRITE, ev->
uctx);
206 if (!(ev->
events & UB_EV_PERSIST)) {
207 DEBUG4(
"unbound event %p - UB_EV_PERSIST not set - Removing events for FD %i", ev, ev->
fd);
209 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
223 int fd,
UNUSED int flags,
int fd_errno,
void *uctx)
238 ev->
cb(-1, UB_EV_TIMEOUT, ev->
uctx);
254 if ((ev->
events & UB_EV_READ) && (ev->
events & UB_EV_WRITE)) {
257 DEBUG4(
"unbound event %p - Registered for read+write events on FD %i", ev, ev->
fd);
264 PERROR(
"unbound event %p - Registration failed for read+write+error events on FD %i",
269 }
else if (ev->
events & UB_EV_READ) {
272 DEBUG4(
"unbound event %p - Registered for read+error events on FD %i", ev, ev->
fd);
279 PERROR(
"unbound event %p - Registration failed for read+error events on FD %i",
284 }
else if (ev->
events & UB_EV_WRITE) {
287 DEBUG4(
"unbound event %p - Registered for write+error events on FD %i", ev, ev->
fd);
294 PERROR(
"unbound event %p - Registration failed for write+error events on FD %i",
304 if (ev->
events & UB_EV_TIMEOUT) {
311 PERROR(
"unbound event %p - Failed adding timeout", ev);
313 if (ev->
events & (UB_EV_READ | UB_EV_WRITE)) {
334 if (!ev->
active)
return 0;
336 if (ev->
events & (UB_EV_READ | UB_EV_WRITE)) {
337 DEBUG4(
"unbound event %p - De-registering FD %i", ev, ev->
fd);
340 PERROR(
"unbound event %p - De-registration failed for FD %i", ev, ev->
fd);
346 if (ev->
events & UB_EV_TIMEOUT) {
347 DEBUG4(
"unbound event %p - Disarming timeout", ev);
361 void (*cb)(
int,
short,
void*),
362 void *uctx,
struct timeval *tv)
371 DEBUG4(
"unbound event %p - New callback %p (old callback was %p)",
375 if (ev->
uctx != uctx) {
376 DEBUG4(
"unbound event %p - New uctx %p (old uctx was %p)",
389 PERROR(
"unbound event %p - Failed adding timeout", ev);
406 DEBUG4(
"unbound event %p - Disarming timeout", ev);
418 void (*cb)(
int,
short,
void*),
void *uctx)
423 static struct ub_event_vmt vmt = {
435 ev->
base.magic = UB_EVENT_MAGIC;
444 DEBUG4(
"unbound event %p - Allocated - Events %i, FD %i, callback %p, uctx %p", ev, flags, fd, cb, uctx);
446 return (
struct ub_event *)ev;
451 if (ev_b->
ub) ub_ctx_delete(ev_b->
ub);
474 static struct ub_event_base_vmt vmt = {
484 ev_b->
base.magic = UB_EVENT_MAGIC;
485 ev_b->
base.vmt = &vmt;
493 ev_b->
ub = ub_ctx_create_ub_event((
struct ub_event_base *)ev_b);
495 ERROR(
"Failed creating ub_ctx");
#define fr_event_fd_insert(...)
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
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 void _unbound_io_service_timer_expired(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Timeout fired.
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.
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.
fr_timer_t * timer_ev
Stores the pointer to the enabled timer for this event handled.
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.
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.
#define FR_TIMER_DISARM_RETURN(_ev)
#define FR_TIMER_DISARM(_ev)
static fr_event_list_t * el
#define fr_box_time_delta(_val)