libosmogb 1.9.0.192-1c24
Osmocom Gb library
gprs_ns2_fr.c File Reference

NS-over-FR-over-GRE implementation. More...

#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <arpa/inet.h>
#include <linux/if.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <linux/if_ether.h>
#include <linux/hdlc.h>
#include <linux/hdlc/ioctl.h>
#include <linux/sockios.h>
#include <osmocom/gprs/frame_relay.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gprs/gprs_ns2.h>
#include <osmocom/core/netdev.h>
#include <osmocom/gprs/protocol/gsm_08_16.h>
#include <osmocom/gprs/protocol/gsm_08_18.h>
#include "config.h"
#include "common_vty.h"
#include "gprs_ns2_internal.h"

Data Structures

struct  priv_bind
 
struct  priv_vc
 

Macros

#define GRE_PTYPE_FR   0x6559
 
#define GRE_PTYPE_IPv4   0x0800
 
#define GRE_PTYPE_IPv6   0x86dd
 
#define GRE_PTYPE_KAR   0x0000 /* keepalive response */
 
#define IPPROTO_GRE   47
 
#define E1_LINERATE   2048000
 
#define E1_SLOTS_TOTAL   32
 
#define E1_SLOTS_USED   31
 
#define SUPERCHANNEL_LINERATE   (E1_LINERATE*E1_SLOTS_USED)/E1_SLOTS_TOTAL
 
#define BIT_DURATION_NS   (1000000000 / SUPERCHANNEL_LINERATE)
 
#define LMI_Q933A_DLCI   0
 

Functions

static void free_bind (struct gprs_ns2_vc_bind *bind)
 clean up all private driver state. More...
 
static int fr_dlci_rx_cb (void *cb_data, struct msgb *msg)
 
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)
 
static void fr_dlci_status_cb (struct osmo_fr_dlc *dlc, void *cb_data, bool active)
 
static struct priv_vcfr_alloc_vc (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_vc *nsvc, uint16_t dlci)
 
int gprs_ns2_find_vc_by_dlci (struct gprs_ns2_vc_bind *bind, uint16_t dlci, struct gprs_ns2_vc **result)
 
static int fr_netif_ofd_cb (struct osmo_fd *bfd, uint32_t what)
 
static int fr_netif_write_one (struct gprs_ns2_vc_bind *bind, struct msgb *msg)
 
int gprs_ns2_is_fr_bind (struct gprs_ns2_vc_bind *bind)
 determine if given bind is for FR-GRE encapsulation. More...
 
static int fr_vc_sendmsg (struct gprs_ns2_vc *nsvc, struct msgb *msg)
 
static void enqueue_at_head (struct gprs_ns2_vc_bind *bind, struct msgb *msg)
 
static void enqueue_at_tail (struct gprs_ns2_vc_bind *bind, struct msgb *msg)
 
static int backlog_enqueue_or_free (struct gprs_ns2_vc_bind *bind, struct msgb *msg)
 
static void fr_backlog_timer_cb (void *data)
 
int fr_tx_cb (void *data, struct msgb *msg)
 
static int devname2ifindex (const char *ifname)
 
static int open_socket (int ifindex, const struct gprs_ns2_vc_bind *nsbind)
 
static int gprs_n2_fr_ifupdown_ind_cb (struct osmo_netdev *netdev, bool if_running)
 
static int gprs_n2_fr_mtu_chg_cb (struct osmo_netdev *netdev, uint32_t new_mtu)
 
static int set_ifupdown (const char *netif, bool up)
 
static int setup_device (const char *netif, const struct gprs_ns2_vc_bind *bind)
 
int gprs_ns2_fr_bind (struct gprs_ns2_inst *nsi, const char *name, const char *netif, struct osmo_fr_network *fr_network, enum osmo_fr_role fr_role, struct gprs_ns2_vc_bind **result)
 Create a new bind for NS over FR. More...
 
enum osmo_fr_role gprs_ns2_fr_bind_role (struct gprs_ns2_vc_bind *bind)
 Return the frame relay role of a bind. More...
 
const char * gprs_ns2_fr_bind_netif (struct gprs_ns2_vc_bind *bind)
 Return the network interface of the bind. More...
 
struct gprs_ns2_vc_bindgprs_ns2_fr_bind_by_netif (struct gprs_ns2_inst *nsi, const char *netif)
 Find NS bind for a given network interface. More...
 
struct gprs_ns2_vcgprs_ns2_fr_connect (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_nse *nse, uint16_t nsvci, uint16_t dlci)
 Create, connect and activate a new FR-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_fr_connect2 (struct gprs_ns2_vc_bind *bind, uint16_t nsei, uint16_t nsvci, uint16_t dlci)
 Create, connect and activate a new FR-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_fr_nsvc_by_dlci (struct gprs_ns2_vc_bind *bind, uint16_t dlci)
 Return the nsvc by dlci. More...
 
uint16_t gprs_ns2_fr_nsvc_dlci (const struct gprs_ns2_vc *nsvc)
 Return the dlci of the nsvc. More...
 

Variables

struct gprs_ns2_vc_driver vc_driver_fr
 

Detailed Description

NS-over-FR-over-GRE 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

Macro Definition Documentation

◆ BIT_DURATION_NS

#define BIT_DURATION_NS   (1000000000 / SUPERCHANNEL_LINERATE)

◆ E1_LINERATE

#define E1_LINERATE   2048000

◆ E1_SLOTS_TOTAL

#define E1_SLOTS_TOTAL   32

◆ E1_SLOTS_USED

#define E1_SLOTS_USED   31

◆ GRE_PTYPE_FR

#define GRE_PTYPE_FR   0x6559

◆ GRE_PTYPE_IPv4

#define GRE_PTYPE_IPv4   0x0800

◆ GRE_PTYPE_IPv6

#define GRE_PTYPE_IPv6   0x86dd

◆ GRE_PTYPE_KAR

#define GRE_PTYPE_KAR   0x0000 /* keepalive response */

◆ IPPROTO_GRE

#define IPPROTO_GRE   47

◆ LMI_Q933A_DLCI

#define LMI_Q933A_DLCI   0

◆ SUPERCHANNEL_LINERATE

#define SUPERCHANNEL_LINERATE   (E1_LINERATE*E1_SLOTS_USED)/E1_SLOTS_TOTAL

Function Documentation

◆ backlog_enqueue_or_free()

◆ devname2ifindex()

static int devname2ifindex ( const char *  ifname)
static

References OSMO_STRLCPY_ARRAY.

Referenced by gprs_ns2_fr_bind().

◆ dump_vty()

◆ enqueue_at_head()

◆ enqueue_at_tail()

◆ fr_alloc_vc()

◆ fr_backlog_timer_cb()

◆ fr_dlci_rx_cb()

static int fr_dlci_rx_cb ( void *  cb_data,
struct msgb msg 
)
static

References msg, and ns2_recv_vc().

Referenced by fr_alloc_vc().

◆ fr_dlci_status_cb()

static void fr_dlci_status_cb ( struct osmo_fr_dlc dlc,
void *  cb_data,
bool  active 
)
static

◆ fr_netif_ofd_cb()

static int fr_netif_ofd_cb ( struct osmo_fd bfd,
uint32_t  what 
)
static

◆ fr_netif_write_one()

static int fr_netif_write_one ( struct gprs_ns2_vc_bind bind,
struct msgb msg 
)
static

◆ fr_tx_cb()

int fr_tx_cb ( void *  data,
struct msgb msg 
)

◆ fr_vc_sendmsg()

◆ free_bind()

◆ free_vc()

static void free_vc ( struct gprs_ns2_vc nsvc)
static

◆ gprs_n2_fr_ifupdown_ind_cb()

◆ gprs_n2_fr_mtu_chg_cb()

◆ gprs_ns2_find_vc_by_dlci()

int gprs_ns2_find_vc_by_dlci ( struct gprs_ns2_vc_bind bind,
uint16_t  dlci,
struct gprs_ns2_vc **  result 
)

◆ gprs_ns2_fr_bind()

int gprs_ns2_fr_bind ( struct gprs_ns2_inst nsi,
const char *  name,
const char *  netif,
struct osmo_fr_network fr_network,
enum osmo_fr_role  fr_role,
struct gprs_ns2_vc_bind **  result 
)

◆ gprs_ns2_fr_bind_by_netif()

struct gprs_ns2_vc_bind * gprs_ns2_fr_bind_by_netif ( struct gprs_ns2_inst nsi,
const char *  netif 
)

Find NS bind for a given network interface.

Parameters
[in]nsiNS instance
[in]netifthe network interface to search for
Returns
the bind or NULL if not found

References gprs_ns2_inst::binding, gprs_ns2_fr_bind_netif(), gprs_ns2_is_fr_bind(), list, llist_for_each_entry, gprs_ns2_vc_bind::nsi, and OSMO_ASSERT.

Referenced by DEFUN().

◆ gprs_ns2_fr_bind_netif()

const char * gprs_ns2_fr_bind_netif ( struct gprs_ns2_vc_bind bind)

Return the network interface of the bind.

Parameters
[in]bindThe bind
Returns
the network interface

References gprs_ns2_vc_bind::driver, priv_bind::netif, gprs_ns2_vc_bind::priv, and vc_driver_fr.

Referenced by config_write_nsvc(), config_write_vbind(), gprs_ns2_fr_bind_by_netif(), and gprs_ns2_ll_str_buf().

◆ gprs_ns2_fr_bind_role()

enum osmo_fr_role gprs_ns2_fr_bind_role ( struct gprs_ns2_vc_bind bind)

Return the frame relay role of a bind.

Parameters
[in]bindThe bind
Returns
the frame relay role or -EINVAL if bind is not frame relay

References gprs_ns2_vc_bind::driver, priv_bind::link, gprs_ns2_vc_bind::priv, osmo_fr_link::role, and vc_driver_fr.

Referenced by config_write_vbind().

◆ gprs_ns2_fr_connect()

struct gprs_ns2_vc * gprs_ns2_fr_connect ( struct gprs_ns2_vc_bind bind,
struct gprs_ns2_nse nse,
uint16_t  nsvci,
uint16_t  dlci 
)

Create, connect and activate a new FR-based NS-VC.

Parameters
[in]bindbind in which the new NS-VC is to be created
[in]nseiNSEI of the NS Entity in which the NS-VC is to be created
[in]dlciData Link connection identifier
Returns
pointer to newly-allocated, connected and activated NS-VC; NULL on error

References priv_bind::dlci, fr_alloc_vc(), gprs_ns2_fr_nsvc_by_dlci(), gprs_ns2_free_nsvc(), gprs_ns2_is_fr_bind(), gprs_ns2_lltype_str(), GPRS_NS2_VC_MODE_BLOCKRESET, gprs_ns2_nse::ll, priv_bind::netif, ns2_vc_alloc(), gprs_ns2_nse::nsei, gprs_ns2_vc::nsvci, gprs_ns2_vc::nsvci_is_valid, OSMO_ASSERT, osmo_identifier_sanitize_buf(), gprs_ns2_vc::priv, and gprs_ns2_vc_bind::priv.

Referenced by DEFUN(), and gprs_ns2_fr_connect2().

◆ gprs_ns2_fr_connect2()

struct gprs_ns2_vc * gprs_ns2_fr_connect2 ( struct gprs_ns2_vc_bind bind,
uint16_t  nsei,
uint16_t  nsvci,
uint16_t  dlci 
)

Create, connect and activate a new FR-based NS-VC.

Parameters
[in]bindbind in which the new NS-VC is to be created
[in]nseiNSEI of the NS Entity in which the NS-VC is to be created
[in]dlciData Link connection identifier
Returns
pointer to newly-allocated, connected and activated NS-VC; NULL on error

References gprs_ns2_create_nse(), GPRS_NS2_DIALECT_STATIC_RESETBLOCK, gprs_ns2_fr_connect(), gprs_ns2_free_nse(), gprs_ns2_is_fr_bind(), GPRS_NS2_LL_FR, gprs_ns2_nse_by_nsei(), nsei, gprs_ns2_vc_bind::nsi, gprs_ns2_nse::nsvc, and OSMO_ASSERT.

◆ gprs_ns2_fr_nsvc_by_dlci()

struct gprs_ns2_vc * gprs_ns2_fr_nsvc_by_dlci ( struct gprs_ns2_vc_bind bind,
uint16_t  dlci 
)

Return the nsvc by dlci.

Parameters
[in]bind
[in]dlciData Link connection identifier
Returns
the nsvc or NULL if not found

References priv_vc::dlci, gprs_ns2_is_fr_bind(), llist_for_each_entry, gprs_ns2_vc_bind::nsvc, OSMO_ASSERT, and gprs_ns2_vc::priv.

Referenced by DEFUN(), and gprs_ns2_fr_connect().

◆ gprs_ns2_fr_nsvc_dlci()

uint16_t gprs_ns2_fr_nsvc_dlci ( const struct gprs_ns2_vc nsvc)

Return the dlci of the nsvc.

Parameters
[in]nsvc
Returns
the dlci or 0 on error. 0 is not a valid dlci.

References gprs_ns2_vc::bind, priv_vc::dlci, gprs_ns2_vc_bind::driver, gprs_ns2_vc::priv, and vc_driver_fr.

Referenced by config_write_nsvc(), and gprs_ns2_ll_str_buf().

◆ gprs_ns2_is_fr_bind()

int gprs_ns2_is_fr_bind ( struct gprs_ns2_vc_bind bind)

◆ open_socket()

static int open_socket ( int  ifindex,
const struct gprs_ns2_vc_bind nsbind 
)
static

References fd, LOGBIND, and LOGL_ERROR.

Referenced by gprs_ns2_fr_bind().

◆ set_ifupdown()

static int set_ifupdown ( const char *  netif,
bool  up 
)
static

References OSMO_STRLCPY_ARRAY.

Referenced by setup_device().

◆ setup_device()

static int setup_device ( const char *  netif,
const struct gprs_ns2_vc_bind bind 
)
static

Variable Documentation

◆ vc_driver_fr

struct gprs_ns2_vc_driver vc_driver_fr
Initial value:
= {
.name = "GB frame relay",
.free_bind = free_bind,
}
static void free_bind(struct gprs_ns2_vc_bind *bind)
clean up all private driver state.
Definition: gprs_ns2_fr.c:154

Referenced by gprs_ns2_fr_bind(), gprs_ns2_fr_bind_netif(), gprs_ns2_fr_bind_role(), gprs_ns2_fr_nsvc_dlci(), and gprs_ns2_is_fr_bind().