The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Typedefs | Functions | Variables
event.c File Reference

separate eventing thread to run libosmocore's event loop More...

#include <osmocom/core/talloc.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/io/schedule.h>
#include <unistd.h>
#include <semaphore.h>
#include <signal.h>
#include <osmocom/core/logging.h>
#include <osmocom/sccp/sccp_types.h>
#include <osmocom/mtp/mtp_level3.h>
#include "libosmo-m3ua/include/bsc_data.h"
#include "libosmo-m3ua/include/sctp_m3ua.h"
#include "sigtran.h"
+ Include dependency graph for event.c:

Go to the source code of this file.

Macros

#define LOG_PREFIX   "sigtran"
 

Typedefs

typedef int(* osmo_cb_func) (struct osmo_fd *fd, unsigned int what)
 

Functions

static int _mtp3_link_free (struct mtp_link *mtp3_link)
 Shutdown the MTP3 link gracefully if it's being freed. More...
 
static int _ofd_free (struct osmo_fd *ofd)
 Unregister a osmocom_fd from the event loop, and close it. More...
 
static int event_link_down (sigtran_conn_t *conn)
 Take down a sigtran link. More...
 
static int event_link_up (TALLOC_CTX *ctx, sigtran_conn_t **out, sigtran_conn_conf_t *conf)
 Bring up SCTP/M3UA/MTP3/SCCP. More...
 
static int event_process_request (struct osmo_fd *ofd, unsigned int what)
 Processes a request for a new pipe from a worker thread. More...
 
static struct osmo_fd * ofd_create (TALLOC_CTX *ctx, int fd, osmo_cb_func func, void *data)
 Register a new osmocom file descriptor callback. More...
 
int sigtran_event_exit (void)
 Signal that libosmo should exit. More...
 
static void * sigtran_event_loop (UNUSED void *instance)
 Enter the libosmo event loop. More...
 
int sigtran_event_start (void)
 Start the libosmo event loop. More...
 
int sigtran_event_submit (struct osmo_fd *ofd, sigtran_transaction_t *txn)
 Send response. More...
 
static int sigtran_m3ua_route_from_conf (UNUSED TALLOC_CTX *ctx, struct mtp_m3ua_client_link *client, sigtran_m3ua_route_t *conf)
 Add a route to an m3ua_association. More...
 

Variables

int ctrl_pipe [2] = { -1, -1 }
 
static bool do_exit = false
 
static pthread_t event_thread
 
static sem_t event_thread_running
 

Detailed Description

separate eventing thread to run libosmocore's event loop

Id
6278db1a8aa116790bf03a75bdd213862a640cfb

libosmocore is not thread safe, none of the event loop access functions support synchronised access by multiple threads.

Writing a shim layer and overloading the libosmo functions would work but is likely to be fragile.

Instead, we run a special thread to handle all requests to SS7 entities.

This thread runs the libosmocore event loop, and select()s over the SCTP FDs libosmo* creates, and a pipe we create (to allow communication with worker threads).

You might except performance using this model to be terrible. But the fact that libosmo is entirely async, and there's no heavy crypto being performed, I suspect that this thread is unlikely to become a bottleneck.

In future when we have our own async event loop, we can look at submitting patches to libosmocore to allow integration with external event loops.

Note
We rely on the fact that writes to a pipe of less than PIPE_BUF, are atomic and not interleaved.
Author
Arran Cudbard-Bell

Definition in file event.c.

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "sigtran"

Definition at line 59 of file event.c.

Typedef Documentation

◆ osmo_cb_func

typedef int(* osmo_cb_func) (struct osmo_fd *fd, unsigned int what)

Definition at line 83 of file event.c.

Function Documentation

◆ _mtp3_link_free()

static int _mtp3_link_free ( struct mtp_link *  mtp3_link)
static

Shutdown the MTP3 link gracefully if it's being freed.

Definition at line 130 of file event.c.

+ Here is the caller graph for this function:

◆ _ofd_free()

static int _ofd_free ( struct osmo_fd *  ofd)
static

Unregister a osmocom_fd from the event loop, and close it.

Parameters
ofdto unregister.
Returns
0.

Definition at line 90 of file event.c.

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

◆ event_link_down()

static int event_link_down ( sigtran_conn_t conn)
static

Take down a sigtran link.

Note
Probably need to do more than just freeing the memory

Definition at line 270 of file event.c.

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

◆ event_link_up()

static int event_link_up ( TALLOC_CTX *  ctx,
sigtran_conn_t **  out,
sigtran_conn_conf_t conf 
)
static

Bring up SCTP/M3UA/MTP3/SCCP.

Note
The final version needs to be much more complex. We can only have one event loop per instance of rlm_sigtran, so we need to record link references and reuse existing SCTP/MTP3 connections where appropriate.
Parameters
[in]ctxto allocate connection data in.
[out]outwhere to write the new sigtran connection.
[in]conffor the connection. Specifies SCTP/M3UA/MTP3/SCCP parameters.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 188 of file event.c.

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

◆ event_process_request()

static int event_process_request ( struct osmo_fd *  ofd,
unsigned int  what 
)
static

Processes a request for a new pipe from a worker thread.

Parameters
ofdfor the main ctrl_pipe.
whathappened.
Returns
  • 0 on success, with pointer written to registration pipe for new osmo_fd.
  • -1 on error, with NULL pointer written to registration pipe.

Definition at line 340 of file event.c.

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

◆ ofd_create()

static struct osmo_fd* ofd_create ( TALLOC_CTX *  ctx,
int  fd,
osmo_cb_func  func,
void *  data 
)
static

Register a new osmocom file descriptor callback.

Parameters
ctxto allocate osmocom_fd in.
fdto associate with osmocom_fd .
functo call when fd becomes readable.
dataprivate contextual data.
Returns
  • NULL on error.
    • New osmocom_fd on success. Freeing unregisters osmocom_fd from event loop, and closes file descriptor.

Definition at line 109 of file event.c.

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

◆ sigtran_event_exit()

int sigtran_event_exit ( void  )

Signal that libosmo should exit.

Definition at line 581 of file event.c.

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

◆ sigtran_event_loop()

static void* sigtran_event_loop ( UNUSED void *  instance)
static

Enter the libosmo event loop.

Will run until the thread is killed, or signalled to exit on the ctrl_pipe.

Definition at line 470 of file event.c.

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

◆ sigtran_event_start()

int sigtran_event_start ( void  )

Start the libosmo event loop.

Definition at line 525 of file event.c.

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

◆ sigtran_event_submit()

int sigtran_event_submit ( struct osmo_fd *  ofd,
sigtran_transaction_t txn 
)

Send response.

Note
Works for both blocking and non-blocking sockets
Parameters
[in]ofdto write response notification to.
[in]txnwe're confirming.

Definition at line 283 of file event.c.

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

◆ sigtran_m3ua_route_from_conf()

static int sigtran_m3ua_route_from_conf ( UNUSED TALLOC_CTX *  ctx,
struct mtp_m3ua_client_link *  client,
sigtran_m3ua_route_t conf 
)
static

Add a route to an m3ua_association.

Definition at line 139 of file event.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ ctrl_pipe

int ctrl_pipe[2] = { -1, -1 }

Definition at line 78 of file event.c.

◆ do_exit

bool do_exit = false
static

Definition at line 81 of file event.c.

◆ event_thread

pthread_t event_thread
static

Definition at line 79 of file event.c.

◆ event_thread_running

sem_t event_thread_running
static

Definition at line 80 of file event.c.