libosmogb  1.4.0.171-b3b83
Osmocom Gb library
gprs_ns2_udp.c File Reference

NS-over-UDP implementation. More...

#include <errno.h>
#include <osmocom/core/select.h>
#include <osmocom/core/sockaddr_str.h>
#include <osmocom/core/socket.h>
#include <osmocom/gprs/gprs_ns2.h>
#include "common_vty.h"
#include "gprs_ns2_internal.h"

Data Structures

struct  priv_bind
 
struct  priv_vc
 

Functions

static void free_bind (struct gprs_ns2_vc_bind *bind)
 clean up all private driver state. More...
 
static void free_vc (struct gprs_ns2_vc *nsvc)
 
static void dump_vty (const struct gprs_ns2_vc_bind *bind, struct vty *vty, bool _stats)
 
struct gprs_ns2_vcgprs_ns2_nsvc_by_sockaddr_bind (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *saddr)
 Find a NS-VC by its remote socket address. More...
 
static int nsip_sendmsg (struct gprs_ns2_vc_bind *bind, struct msgb *msg, struct osmo_sockaddr *dest)
 
static int nsip_vc_sendmsg (struct gprs_ns2_vc *nsvc, struct msgb *msg)
 send the msg and free it afterwards. More...
 
static struct msgbread_nsip_msg (struct osmo_fd *bfd, int *error, struct osmo_sockaddr *saddr)
 
static struct priv_vcns2_driver_alloc_vc (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_vc *nsvc, struct osmo_sockaddr *remote)
 
static int handle_nsip_read (struct osmo_fd *bfd)
 
static int handle_nsip_write (struct osmo_fd *bfd)
 
static int nsip_fd_cb (struct osmo_fd *bfd, unsigned int what)
 
struct gprs_ns2_vc_bindgprs_ns2_ip_bind_by_sockaddr (struct gprs_ns2_inst *nsi, const struct osmo_sockaddr *sockaddr)
 Find NS bind for a given socket address. More...
 
int gprs_ns2_ip_bind (struct gprs_ns2_inst *nsi, const struct osmo_sockaddr *local, int dscp, struct gprs_ns2_vc_bind **result)
 Bind to an IPv4/IPv6 address. More...
 
struct gprs_ns2_vcgprs_ns2_ip_bind_connect (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_nse *nse, const struct osmo_sockaddr *remote)
 Create new NS-VC to a given remote address. More...
 
const struct osmo_sockaddrgprs_ns2_ip_vc_local (const struct gprs_ns2_vc *nsvc)
 Return the socket address of the local peer of a NS-VC. More...
 
const struct osmo_sockaddrgprs_ns2_ip_vc_remote (const struct gprs_ns2_vc *nsvc)
 Return the socket address of the remote peer of a NS-VC. More...
 
bool gprs_ns2_ip_vc_equal (const struct gprs_ns2_vc *nsvc, const struct osmo_sockaddr *local, const struct osmo_sockaddr *remote, uint16_t nsvci)
 Compare the NS-VC with the given parameter. More...
 
const struct osmo_sockaddrgprs_ns2_ip_bind_sockaddr (struct gprs_ns2_vc_bind *bind)
 Return the locally bound socket address of the bind. More...
 
int gprs_ns2_is_ip_bind (struct gprs_ns2_vc_bind *bind)
 Is the given bind an IP bind? More...
 
int gprs_ns2_ip_bind_set_dscp (struct gprs_ns2_vc_bind *bind, int dscp)
 Set the DSCP (TOS) bit value of the given bind. More...
 

Variables

struct gprs_ns2_vc_driver vc_driver_ip
 

Detailed Description

NS-over-UDP implementation.

GPRS Networks Service (NS) messages on the Gb interface. 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) as well as its successor 3GPP TS 48.016

Function Documentation

static void free_bind ( struct gprs_ns2_vc_bind bind)
static

clean up all private driver state.

Should be only called by gprs_ns2_free_bind()

References priv_bind::fd, osmo_fd_close(), priv, and gprs_ns2_vc_bind::priv.

static void free_vc ( struct gprs_ns2_vc nsvc)
static

References gprs_ns2_vc::priv.

Referenced by gprs_ns2_ip_bind().

int gprs_ns2_ip_bind ( struct gprs_ns2_inst nsi,
const struct osmo_sockaddr local,
int  dscp,
struct gprs_ns2_vc_bind **  result 
)

Bind to an IPv4/IPv6 address.

Parameters
[in]nsiNS Instance in which to create the NSVC
[in]localthe local address to bind to
[in]dscpthe DSCP/TOS bits used for transmitted data
[out]resultif set, returns the bind object
Returns
0 on success; negative in case of error

References priv_bind::addr, gprs_ns2_inst::binding, osmo_fd::cb, osmo_fd::data, DLNS, gprs_ns2_vc_bind::driver, priv_bind::dscp, dump_vty(), gprs_ns2_vc_bind::dump_vty, osmo_fd::fd, priv_bind::fd, free_vc(), gprs_ns2_vc_bind::free_vc, gprs_ns2_ip_bind_by_sockaddr(), INIT_LLIST_HEAD, gprs_ns2_vc_bind::list, llist_add(), LOGL_ERROR, LOGP, ns2_vty_bind_apply(), gprs_ns2_vc_bind::nsi, nsip_fd_cb(), nsip_vc_sendmsg(), gprs_ns2_vc_bind::nsvc, OSMO_SOCK_F_BIND, osmo_sock_init_osa_ofd(), priv, gprs_ns2_vc_bind::priv, osmo_sockaddr::sa, gprs_ns2_vc_bind::send_vc, osmo_sockaddr::u, and vc_driver_ip.

Referenced by gprs_ns2_vty_create().

struct gprs_ns2_vc_bind* gprs_ns2_ip_bind_by_sockaddr ( struct gprs_ns2_inst nsi,
const struct osmo_sockaddr sockaddr 
)

Find NS bind for a given socket address.

Parameters
[in]nsiNS instance
[in]sockaddrsocket address to search for
Returns

References gprs_ns2_inst::binding, gprs_ns2_ip_bind_sockaddr(), gprs_ns2_is_ip_bind(), llist_for_each_entry, OSMO_ASSERT, and osmo_sockaddr_cmp().

Referenced by gprs_ns2_ip_bind().

struct gprs_ns2_vc* gprs_ns2_ip_bind_connect ( struct gprs_ns2_vc_bind bind,
struct gprs_ns2_nse nse,
const struct osmo_sockaddr remote 
)

Create new NS-VC to a given remote address.

Parameters
[in]bindthe bind we want to connect
[in]nseNS entity to be used for the new NS-VC
[in]remoteremote address to connect to
Returns
pointer to newly-allocated and connected NS-VC; NULL on error

References gprs_ns2_free_nsvc(), GPRS_NS_LL_UDP, gprs_ns2_vc::ll, ns2_vc_alloc(), priv, gprs_ns2_vc::priv, and priv_vc::remote.

Referenced by gprs_ns2_ip_connect_inactive(), and gprs_ns2_ip_connect_sns().

int gprs_ns2_ip_bind_set_dscp ( struct gprs_ns2_vc_bind bind,
int  dscp 
)

Set the DSCP (TOS) bit value of the given bind.

References DLNS, priv_bind::dscp, osmo_fd::fd, priv_bind::fd, LOGL_ERROR, LOGP, priv, and gprs_ns2_vc_bind::priv.

Referenced by DEFUN().

const struct osmo_sockaddr* gprs_ns2_ip_bind_sockaddr ( struct gprs_ns2_vc_bind bind)

Return the locally bound socket address of the bind.

Parameters
[in]bindThe bind whose local address we want to know
Returns
address of the local bind

References priv_bind::addr, priv, and gprs_ns2_vc_bind::priv.

Referenced by gprs_ns2_ip_bind_by_sockaddr(), gprs_ns2_ll_str_buf(), and ns2_sns_bss_fsm_start().

bool gprs_ns2_ip_vc_equal ( const struct gprs_ns2_vc nsvc,
const struct osmo_sockaddr local,
const struct osmo_sockaddr remote,
uint16_t  nsvci 
)

Compare the NS-VC with the given parameter.

Parameters
[in]nsvcNS-VC to compare with
[in]localThe local address
[in]remoteThe remote address
[in]nsvciNS-VCI will only be used if the NS-VC in BLOCKRESET mode otherwise NS-VCI isn't applicable.
Returns
true if the NS-VC has the same properties as given

References priv_bind::addr, gprs_ns2_vc::bind, GPRS_NS_LL_UDP, gprs_ns2_vc::ll, gprs_ns2_vc::mode, NS2_VC_MODE_BLOCKRESET, gprs_ns2_vc::nsvci, osmo_sockaddr_cmp(), gprs_ns2_vc::priv, gprs_ns2_vc_bind::priv, and priv_vc::remote.

const struct osmo_sockaddr* gprs_ns2_ip_vc_local ( const struct gprs_ns2_vc nsvc)

Return the socket address of the local peer of a NS-VC.

Parameters
[in]nsvcNS-VC whose local peer we want to know
Returns
address of the local peer; NULL in case of error

References priv_bind::addr, gprs_ns2_vc::bind, gprs_ns2_vc_bind::driver, GPRS_NS_LL_UDP, gprs_ns2_vc::ll, priv, and gprs_ns2_vc_bind::priv.

const struct osmo_sockaddr* gprs_ns2_ip_vc_remote ( const struct gprs_ns2_vc nsvc)

Return the socket address of the remote peer of a NS-VC.

Parameters
[in]nsvcNS-VC whose remote peer we want to know
Returns
address of the remote peer; NULL in case of error

References GPRS_NS_LL_UDP, gprs_ns2_vc::ll, priv, gprs_ns2_vc::priv, and priv_vc::remote.

Referenced by create_missing_nsvcs(), do_sns_change_weight(), do_sns_delete(), dump_nsvc(), gprs_ns2_ll_str_buf(), and gprs_ns2_nsvc_by_sockaddr_nse().

int gprs_ns2_is_ip_bind ( struct gprs_ns2_vc_bind bind)

Is the given bind an IP bind?

References gprs_ns2_vc_bind::driver.

Referenced by DEFUN(), gprs_ns2_ip_bind_by_sockaddr(), gprs_ns2_ll_str_buf(), and ns2_sns_bss_fsm_start().

struct gprs_ns2_vc* gprs_ns2_nsvc_by_sockaddr_bind ( struct gprs_ns2_vc_bind bind,
const struct osmo_sockaddr saddr 
)

Find a NS-VC by its remote socket address.

Parameters
[in]bindin which to search
[in]saddrremote peer socket adddress to search
Returns
NS-VC matching sockaddr; NULL if none found

References llist_for_each_entry, gprs_ns2_vc_bind::nsvc, osmo_sockaddr_cmp(), gprs_ns2_vc::priv, priv_vc::remote, osmo_sockaddr::sa, and osmo_sockaddr::u.

Referenced by handle_nsip_read().

static int handle_nsip_write ( struct osmo_fd bfd)
static

Referenced by nsip_fd_cb().

static struct priv_vc* ns2_driver_alloc_vc ( struct gprs_ns2_vc_bind bind,
struct gprs_ns2_vc nsvc,
struct osmo_sockaddr remote 
)
static

References priv, gprs_ns2_vc::priv, and priv_vc::remote.

Referenced by handle_nsip_read().

static int nsip_fd_cb ( struct osmo_fd bfd,
unsigned int  what 
)
static
static int nsip_sendmsg ( struct gprs_ns2_vc_bind bind,
struct msgb msg,
struct osmo_sockaddr dest 
)
inlinestatic
static int nsip_vc_sendmsg ( struct gprs_ns2_vc nsvc,
struct msgb msg 
)
static

send the msg and free it afterwards.

Parameters
nsvcNS-VC on which the message shall be sent
msgmessage to be sent
Returns
number of bytes transmitted; negative on error

References gprs_ns2_vc::bind, nsip_sendmsg(), priv, gprs_ns2_vc::priv, and priv_vc::remote.

Referenced by gprs_ns2_ip_bind().

static struct msgb* read_nsip_msg ( struct osmo_fd bfd,
int *  error,
struct osmo_sockaddr saddr 
)
static

Variable Documentation

struct gprs_ns2_vc_driver vc_driver_ip
Initial value:
= {
.name = "GB UDP IPv4/IPv6",
.free_bind = free_bind,
}
static void free_bind(struct gprs_ns2_vc_bind *bind)
clean up all private driver state.
Definition: gprs_ns2_udp.c:59

Referenced by gprs_ns2_ip_bind().