libosmogb  1.4.0.160-7619
Osmocom Gb library
gprs_ns2.h File Reference
#include <stdint.h>
#include <netinet/in.h>
#include <osmocom/core/prim.h>

Go to the source code of this file.

Data Structures

struct  osmo_gprs_ns2_prim
 

Typedefs

typedef int(* gprs_ns2_foreach_nsvc_cb) (struct gprs_ns2_vc *nsvc, void *ctx)
 a callback to iterate over all NSVC More...
 

Enumerations

enum  gprs_ns2_vc_mode {
  NS2_VC_MODE_BLOCKRESET,
  NS2_VC_MODE_ALIVE
}
 
enum  gprs_ns2_prim {
  PRIM_NS_UNIT_DATA,
  PRIM_NS_CONGESTION,
  PRIM_NS_STATUS
}
 Osmocom NS primitives according to 48.016 5.2 Service primitves. More...
 
enum  gprs_ns2_congestion_cause {
  NS_CONG_CAUSE_BACKWARD_BEGIN,
  NS_CONG_CAUSE_BACKWARD_END,
  NS_CONG_CAUSE_FORWARD_BEGIN,
  NS_CONG_CAUSE_FORWARD_END
}
 Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves. More...
 
enum  gprs_ns2_affecting_cause {
  NS_AFF_CAUSE_VC_FAILURE,
  NS_AFF_CAUSE_VC_RECOVERY,
  NS_AFF_CAUSE_FAILURE,
  NS_AFF_CAUSE_RECOVERY,
  NS_AFF_CAUSE_SNS_CONFIGURED,
  NS_AFF_CAUSE_SNS_FAILURE
}
 Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves. More...
 
enum  gprs_ns2_change_ip_endpoint {
  NS_ENDPOINT_NO_CHANGE,
  NS_ENDPOINT_REQUEST_CHANGE,
  NS_ENDPOINT_CONFIRM_CHANGE
}
 Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves. More...
 

Functions

struct gprs_ns2_instgprs_ns2_instantiate (void *ctx, osmo_prim_cb cb, void *cb_data)
 Create a new GPRS NS instance. More...
 
void gprs_ns2_free (struct gprs_ns2_inst *inst)
 Destroy a NS Instance (including all its NSEs, binds, ...). More...
 
int gprs_ns2_dynamic_create_nse (struct gprs_ns2_inst *nsi, bool create_nse)
 Configure whether a NS Instance should dynamically create NSEs based on incoming traffic. More...
 
int gprs_ns2_recv_prim (struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph)
 Receive a primitive from the NS User (Gb). More...
 
int gprs_ns2_nse_foreach_nsvc (struct gprs_ns2_nse *nse, gprs_ns2_foreach_nsvc_cb cb, void *cb_data)
 Iterate over all nsvc of a NS Entity and call the callback. More...
 
struct gprs_ns2_nsegprs_ns2_nse_by_nsei (struct gprs_ns2_inst *nsi, uint16_t nsei)
 Resolve a NS Entity based on its NSEI. More...
 
struct gprs_ns2_nsegprs_ns2_create_nse (struct gprs_ns2_inst *nsi, uint16_t nsei)
 Create a NS Entity within given NS instance. More...
 
uint16_t gprs_ns2_nse_nsei (struct gprs_ns2_nse *nse)
 Return the NSEI. More...
 
void gprs_ns2_free_nse (struct gprs_ns2_nse *nse)
 Destroy given NS Entity. More...
 
void gprs_ns2_free_nses (struct gprs_ns2_inst *nsi)
 
void gprs_ns2_free_nsvc (struct gprs_ns2_vc *nsvc)
 Destroy/release given NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_nsvc_by_nsvci (struct gprs_ns2_inst *nsi, uint16_t nsvci)
 Resolve a NS-VC Entity based on its NS-VCI. 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_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...
 
void gprs_ns2_bind_set_mode (struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode)
 Set the mode of given bind. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, struct gprs_ns2_nse *nse, uint16_t nsvci)
 Create, connect and activate a new IP-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect2 (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, uint16_t nsei, uint16_t nsvci)
 Create, connect and activate a new IP-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect_inactive (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, struct gprs_ns2_nse *nse, uint16_t nsvci)
 Create, and connect an inactive, new IP-based NS-VC. More...
 
void gprs_ns2_free_bind (struct gprs_ns2_vc_bind *bind)
 Destroy a given bind. More...
 
void gprs_ns2_free_binds (struct gprs_ns2_inst *nsi)
 
int gprs_ns2_ip_connect_sns (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, uint16_t nsei)
 Create, connect and activate a new IP-SNS NSE. More...
 
const struct osmo_sockaddrgprs_ns2_nse_sns_remote (struct gprs_ns2_nse *nse)
 Return the initial SNS remote socket address. 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...
 
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...
 
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...
 
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...
 
int gprs_ns2_frgre_bind (struct gprs_ns2_inst *nsi, const struct osmo_sockaddr *local, int dscp, struct gprs_ns2_vc_bind **result)
 Create a new bind for NS over FR-GRE. More...
 
int gprs_ns2_is_frgre_bind (struct gprs_ns2_vc_bind *bind)
 determine if given bind is for FR-GRE encapsulation. More...
 
struct gprs_ns2_vcgprs_ns2_nsvc_by_sockaddr_nse (struct gprs_ns2_nse *nse, const struct osmo_sockaddr *sockaddr)
 Find NS-VC for given socket address. More...
 
void gprs_ns2_start_alive_all_nsvcs (struct gprs_ns2_nse *nse)
 Start the NS-ALIVE FSM in all NS-VCs of given NSE. More...
 
const char * gprs_ns2_cause_str (int cause)
 Obtain a human-readable string for NS cause value. More...
 
const char * gprs_ns2_ll_str (struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC to a thread-local static buffer. More...
 
char * gprs_ns2_ll_str_buf (char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC into a user-supplied buffer. More...
 
char * gprs_ns2_ll_str_c (const void *ctx, struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC to a dynamically allocated string. More...
 
int gprs_ns2_vty_init (struct gprs_ns2_inst *nsi, const struct osmo_sockaddr_str *default_bind)
 gprs_ns2_vty_init initialize the vty More...
 
int gprs_ns2_vty_create ()
 gprs_ns2_vty_create parse the vty tree into ns nodes It has to be in different steps to ensure the bind is created before creating VCs. More...
 
void gprs_ns2_vty_force_vc_mode (bool force, enum gprs_ns2_vc_mode mode, const char *reason)
 ns2_vty_force_vc_mode force a mode and prevents the vty from overwriting it. More...
 

Typedef Documentation

◆ gprs_ns2_foreach_nsvc_cb

typedef int(* gprs_ns2_foreach_nsvc_cb) (struct gprs_ns2_vc *nsvc, void *ctx)

a callback to iterate over all NSVC

Enumeration Type Documentation

◆ gprs_ns2_affecting_cause

Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves.

Enumerator
NS_AFF_CAUSE_VC_FAILURE 
NS_AFF_CAUSE_VC_RECOVERY 
NS_AFF_CAUSE_FAILURE 
NS_AFF_CAUSE_RECOVERY 
NS_AFF_CAUSE_SNS_CONFIGURED 
NS_AFF_CAUSE_SNS_FAILURE 

◆ gprs_ns2_change_ip_endpoint

Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves.

Enumerator
NS_ENDPOINT_NO_CHANGE 
NS_ENDPOINT_REQUEST_CHANGE 
NS_ENDPOINT_CONFIRM_CHANGE 

◆ gprs_ns2_congestion_cause

Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves.

Enumerator
NS_CONG_CAUSE_BACKWARD_BEGIN 
NS_CONG_CAUSE_BACKWARD_END 
NS_CONG_CAUSE_FORWARD_BEGIN 
NS_CONG_CAUSE_FORWARD_END 

◆ gprs_ns2_prim

Osmocom NS primitives according to 48.016 5.2 Service primitves.

Enumerator
PRIM_NS_UNIT_DATA 
PRIM_NS_CONGESTION 
PRIM_NS_STATUS 

◆ gprs_ns2_vc_mode

Enumerator
NS2_VC_MODE_BLOCKRESET 

The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK.

This is what is needed for Frame Relay transport, and if you use a R97/R99 Gb interface over an IP transport (never standardized by 3GPP)

NS2_VC_MODE_ALIVE 

The VC will only use ALIVE/ACK (no RESET/BLOCK/UNBLOCK), which is for Gb-IP interface compliant to 3GPP Rel=4 or later.

Function Documentation

◆ gprs_ns2_frgre_bind()

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

Create a new bind for NS over FR-GRE.

Parameters
[in]nsiNS instance in which to create the bind
[in]locallocal address on which to bind
[in]dscpDSCP/TOS bits to use for transmitted data on this bind
[out]resultpointer to created bind
Returns
0 on success; negative on error

References priv_bind::addr, gprs_ns2_inst::binding, osmo_fd::cb, osmo_fd::data, DLNS, gprs_ns2_vc_bind::driver, priv_bind::dscp, osmo_fd::fd, priv_bind::fd, free_vc(), gprs_ns2_vc_bind::free_vc, frgre_fd_cb(), frgre_vc_sendmsg(), INIT_LLIST_HEAD, IPPROTO_GRE, gprs_ns2_vc_bind::list, llist_add(), LOGL_ERROR, LOGP, ns2_vty_bind_apply(), gprs_ns2_vc_bind::nsi, 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_frgre.

◆ 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().

◆ gprs_ns2_ip_bind_by_sockaddr()

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().

◆ gprs_ns2_ip_bind_set_dscp()

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().

◆ gprs_ns2_ip_bind_sockaddr()

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().

◆ gprs_ns2_ip_vc_equal()

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.

◆ gprs_ns2_ip_vc_local()

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.

◆ gprs_ns2_ip_vc_remote()

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().

◆ gprs_ns2_is_frgre_bind()

int gprs_ns2_is_frgre_bind ( struct gprs_ns2_vc_bind bind)

determine if given bind is for FR-GRE encapsulation.

References gprs_ns2_vc_bind::driver.

◆ gprs_ns2_is_ip_bind()

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().

◆ gprs_ns2_nse_sns_remote()

const struct osmo_sockaddr* gprs_ns2_nse_sns_remote ( struct gprs_ns2_nse nse)

Return the initial SNS remote socket address.

Parameters
nseNS Entity
Returns
address of the initial SNS connection; NULL in case of error

References gprs_ns2_nse::bss_sns_fi, ns2_sns_state::initial, and osmo_fsm_inst::priv.

◆ gprs_ns2_nsvc_by_sockaddr_bind()

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().

◆ gprs_ns2_vty_create()

◆ gprs_ns2_vty_force_vc_mode()

void gprs_ns2_vty_force_vc_mode ( bool  force,
enum gprs_ns2_vc_mode  mode,
const char *  reason 
)

ns2_vty_force_vc_mode force a mode and prevents the vty from overwriting it.

Parameters
forceif true mode and reason will be set. false to allow modification via vty.
mode
reasonA description shown to the user when a vty command wants to change the mode.

References ns2_vty_priv::force_vc_mode, ns2_vty_priv::force_vc_mode_reason, priv, and ns2_vty_priv::vc_mode.

◆ gprs_ns2_vty_init()

int gprs_ns2_vty_init ( struct gprs_ns2_inst nsi,
const struct osmo_sockaddr_str default_bind 
)

gprs_ns2_vty_init initialize the vty

Parameters
[in,out]nsi
[in]default_bindset the default address to bind to. Can be NULL.
Returns
0 on success

References CFG_LOG_NODE, CONFIG_NODE, config_write_ns(), INIT_LLIST_HEAD, install_lib_element(), install_lib_element_ve(), install_node(), L_NS_NODE, NS2_VC_MODE_BLOCKRESET, priv, ns2_vty_priv::udp, ns2_vty_priv::vc_mode, and ns2_vty_priv::vtyvc.