The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions
io.c File Reference

Provides interface between libunbound and the FreeRADIUS event loop. More...

#include <freeradius-devel/server/log.h>
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/syserror.h>
#include "io.h"
#include <unbound-event.h>
+ Include dependency graph for io.c:

Go to the source code of this file.

Data Structures

struct  unbound_io_event_t
 Wrapper around event handle for our event loop. More...
 

Macros

#define LOG_PREFIX   "unbound"
 

Typedefs

typedef void(* unbound_cb_t) (int, short flags, void *uctx)
 Definition for libunbound's event callback. More...
 

Functions

static int _event_base_free (unbound_io_event_base_t *ev_b)
 
static int _unbound_io_event_activate (struct ub_event *ub_ev, struct timeval *tv)
 Activate FD events and set a timer for a timeout. More...
 
static int _unbound_io_event_deactivate (struct ub_event *ub_ev)
 
static void _unbound_io_event_fd_set (struct ub_event *ub_ev, int fd)
 Change the file descriptor associated with an event. More...
 
static void _unbound_io_event_flags_add (struct ub_event *ub_ev, short flags)
 Alter the enabled flags associated with the event. More...
 
static void _unbound_io_event_flags_del (struct ub_event *ub_ev, short flags)
 Alter the enabled flags associated with the event. More...
 
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. More...
 
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. More...
 
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. More...
 
static void _unbound_io_service_readable (fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Unbound FD became readable. More...
 
static void _unbound_io_service_timer_expired (UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx)
 Timeout fired. More...
 
static void _unbound_io_service_writable (fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Unbound FD became writable. More...
 
static int _unbound_io_timer_deactivate (struct ub_event *ub_ev)
 Deactivate a timeout. More...
 
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. More...
 
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. More...
 

Detailed Description

Provides interface between libunbound and the FreeRADIUS event loop.

Id
6467943ea8a676f2023f6d4d82a7ec39647294bd

Definition in file io.c.


Data Structure Documentation

◆ unbound_io_event_t

struct unbound_io_event_t

Wrapper around event handle for our event loop.

This stores libunbound specific information for an event in our event loop.

Lifetime should be bound to the event base.

Definition at line 55 of file io.c.

+ Collaboration diagram for unbound_io_event_t:
Data Fields
bool active Whether this event is considered active.
struct ub_event base Unbound event base, which we populate with callback functions for adding events for FDs setting timers etc...

MUST BE LISTED FIRST.

unbound_cb_t cb The callback we need to call when a specified event happens.
unbound_io_event_base_t * ev_b Event base this handle was created for.
short events The events this event handle should receive when activated.
int fd File descriptor this event handle relates to.
fr_event_timer_t const * timer Stores the pointer to the enabled timer for this event handled.

libunbound uses a single handle for managing related FD events and timers, which is weird, but ok...

void * uctx This is the argument libunbound wants passed to the callback when it's called.

It usually contains libunbound's internal connection handled. We don't have any visibility, it just remains an opaque blob to us.

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "unbound"

Definition at line 27 of file io.c.

Typedef Documentation

◆ unbound_cb_t

typedef void(* unbound_cb_t) (int, short flags, void *uctx)

Definition for libunbound's event callback.

Here because they don't provide one.

Definition at line 47 of file io.c.

Function Documentation

◆ _event_base_free()

static int _event_base_free ( unbound_io_event_base_t ev_b)
static

Definition at line 461 of file io.c.

◆ _unbound_io_event_activate()

static int _unbound_io_event_activate ( struct ub_event *  ub_ev,
struct timeval *  tv 
)
static

Activate FD events and set a timer for a timeout.

Definition at line 246 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_deactivate()

static int _unbound_io_event_deactivate ( struct ub_event *  ub_ev)
static

Definition at line 330 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_fd_set()

static void _unbound_io_event_fd_set ( struct ub_event *  ub_ev,
int  fd 
)
static

Change the file descriptor associated with an event.

Event MUST be disabled before changing the fd.

Definition at line 121 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_flags_add()

static void _unbound_io_event_flags_add ( struct ub_event *  ub_ev,
short  flags 
)
static

Alter the enabled flags associated with the event.

Event MUST be disabled before these flags are changed.

Definition at line 89 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_flags_del()

static void _unbound_io_event_flags_del ( struct ub_event *  ub_ev,
short  flags 
)
static

Alter the enabled flags associated with the event.

Event MUST be disabled before these flags are changed.

Definition at line 105 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_free()

static void _unbound_io_event_free ( struct ub_event *  ub_ev)
static

Free an event, and, by the magic of talloc, any timers or fd events.

Definition at line 137 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_event_new()

static struct ub_event* _unbound_io_event_new ( struct ub_event_base *  base,
int  fd,
short  flags,
void(*)(int, short, void *)  cb,
void *  uctx 
)
static

Returns a new libunbound event handle.

This handle is used by libunbound to interface with the worker's event loop

Definition at line 429 of file io.c.

+ Here is the call graph for this function:

◆ _unbound_io_service_errored()

static void _unbound_io_service_errored ( UNUSED fr_event_list_t el,
int  fd,
UNUSED int  flags,
int  fd_errno,
void *  uctx 
)
static

Unbound FD errored.

libunbound doesn't request errors, so tell it a timeout occurred

Because we don't have the separation between the IO event loop and the event loop processing results, we call ub_process immediately after calling the IO callback.

Definition at line 221 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_service_readable()

static void _unbound_io_service_readable ( fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Unbound FD became readable.

Because we don't have the separation between the IO event loop and the event loop processing results, we call ub_process immediately after calling the IO callback.

Definition at line 168 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_service_timer_expired()

static void _unbound_io_service_timer_expired ( UNUSED fr_event_list_t el,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Timeout fired.

Unbound uses these timeouts as part of its mechanism to measure rtt from candidate DNS servers, working out which is the fastest to use for any given query. The timeout happening causes the timeout against the server to be increased for any subsequent queries sent to it.

Definition at line 153 of file io.c.

+ Here is the caller graph for this function:

◆ _unbound_io_service_writable()

static void _unbound_io_service_writable ( fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Unbound FD became writable.

Definition at line 192 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_timer_deactivate()

static int _unbound_io_timer_deactivate ( struct ub_event *  ub_ev)
static

Deactivate a timeout.

Definition at line 408 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _unbound_io_timer_modify()

static int _unbound_io_timer_modify ( struct ub_event *  ub_ev,
UNUSED struct ub_event_base *  ev_b,
void(*)(int, short, void *)  cb,
void *  uctx,
struct timeval *  tv 
)
static

Modify an existing timeout.

Definition at line 365 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unbound_io_init()

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.

The ub_ctx is configured to use the el specified.

When the thread ctx is freed, unbound_io_free should be called to gracefully free the ub_ctx, and then the event base structure it depends on.

Parameters
[in]ctxTalloc ctx to allocate even base in.
[out]ev_b_outEvent base. Free with talloc_free.
[in]elTo use to run the unbound event loop.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 482 of file io.c.

+ Here is the caller graph for this function: