libosmogb 1.13.1.1-afb4 Osmocom Gb library

Data Structures | Macros | Functions | Variables
gprs_ns2_frgre.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 <osmocom/core/byteswap.h>`
`#include <osmocom/core/logging.h>`
`#include <osmocom/core/msgb.h>`
`#include <osmocom/core/select.h>`
`#include <osmocom/core/socket.h>`
`#include <osmocom/core/talloc.h>`
`#include <osmocom/gprs/gprs_ns2.h>`
`#include "gprs_ns2_internal.h"`

## Data Structures
struct | gre_hdr
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

## Functions
struct gre_hdr | __attribute__ ((packed))
static void | free_bind (struct gprs_ns2_vc_bind *bind)
| clean up all private driver state. More...
static int | frgre_sendmsg (struct gprs_ns2_vc_bind *bind, struct msgb *msg, struct osmo_sockaddr *dest)
static void | free_vc (struct gprs_ns2_vc *nsvc)
static struct priv_vc * | frgre_alloc_vc (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_vc *nsvc, struct osmo_sockaddr *remote, uint16_t dlci)
static int | handle_rx_gre_ipv6 (struct osmo_fd *bfd, struct msgb *msg, struct ip6_hdr *ip6hdr, struct gre_hdr *greh)
static int | handle_rx_gre_ipv4 (struct osmo_fd *bfd, struct msgb *msg, struct iphdr *iph, struct gre_hdr *greh)
static struct msgb * | read_nsfrgre_msg (struct osmo_fd *bfd, int *error, struct osmo_sockaddr *saddr, uint16_t *dlci, const struct gprs_ns2_vc_bind *bind)
static int | ns2_find_vc_by_dlci (struct gprs_ns2_vc_bind *bind, uint16_t dlci, struct gprs_ns2_vc **result)
static int | handle_nsfrgre_read (struct osmo_fd *bfd)
static int | handle_nsfrgre_write (struct osmo_fd *bfd)
static int | frgre_vc_sendmsg (struct gprs_ns2_vc *nsvc, struct msgb *msg)
static int | frgre_fd_cb (struct osmo_fd *bfd, unsigned int what)
int | gprs_ns2_is_frgre_bind (struct gprs_ns2_vc_bind *bind)
| determine if given bind is for FR-GRE encapsulation. More...
int | gprs_ns2_frgre_bind (struct gprs_ns2_inst *nsi, const char *name, const struct osmo_sockaddr *local, int dscp, struct gprs_ns2_vc_bind **result)
| Create a new bind for NS over FR-GRE. More...

## Variables
uint16_t | flags
uint16_t | ptype
struct gprs_ns2_vc_driver | vc_driver_frgre
struct priv_bind | __attribute__

## 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

## ◆ 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

## Function Documentation

## ◆ free_bind()

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, llist_empty(), gprs_ns2_vc_bind::nsvc, OSMO_ASSERT, osmo_fd_close(), and gprs_ns2_vc_bind::priv.

## ◆ free_vc()

static void free_vc | ( | struct gprs_ns2_vc * | nsvc | ) |
| static

References OSMO_ASSERT, and gprs_ns2_vc::priv.

Referenced by gprs_ns2_frgre_bind().

## ◆ frgre_alloc_vc()

static struct priv_vc * frgre_alloc_vc | ( | struct gprs_ns2_vc_bind * | bind,
|  | struct gprs_ns2_vc * | nsvc,
|  | struct osmo_sockaddr * | remote,
|  | uint16_t | dlci
| ) |  |
| static

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

Referenced by handle_nsfrgre_read().

## ◆ frgre_fd_cb()

static int frgre_fd_cb | ( | struct osmo_fd * | bfd,
|  | unsigned int | what
| ) |  |
| static

References handle_nsfrgre_read(), handle_nsfrgre_write(), OSMO_FD_READ, and OSMO_FD_WRITE.

Referenced by gprs_ns2_frgre_bind().

## ◆ frgre_sendmsg()

static int frgre_sendmsg | ( | struct gprs_ns2_vc_bind * | bind,
|  | struct msgb * | msg,
|  | struct osmo_sockaddr * | dest
| ) |  |
| inline static

References osmo_fd::fd, priv_bind::fd, msg, msgb_free(), gprs_ns2_vc_bind::priv, osmo_sockaddr::sa, and osmo_sockaddr::u.

Referenced by frgre_vc_sendmsg(), and handle_nsfrgre_read().

## ◆ frgre_vc_sendmsg()

static int frgre_vc_sendmsg | ( | struct gprs_ns2_vc * | nsvc,
|  | struct msgb * | msg
| ) |  |
| static

References priv_bind::dlci, gre_hdr::flags, frgre_sendmsg(), GRE_PTYPE_FR, msg, msgb_length(), msgb_push(), NS_CTR_BYTES_OUT, NS_CTR_BYTES_OUT_DROP, NS_CTR_PKTS_OUT, NS_CTR_PKTS_OUT_DROP, gprs_ns2_vc_bind::nsvc, osmo_htons, OSMO_LIKELY, gprs_ns2_vc::priv, gprs_ns2_vc_bind::priv, gre_hdr::ptype, RATE_CTR_ADD_NS, RATE_CTR_INC_NS, and priv_vc::remote.

Referenced by gprs_ns2_frgre_bind().

## ◆ gprs_ns2_frgre_bind()

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

Create a new bind for NS over FR-GRE.

Parameters

  [in] | nsi | NS instance in which to create the bind
  [in] | local | local address on which to bind
  [in] | dscp | DSCP/TOS bits to use for transmitted data on this bind
  [out] | result | pointer to the created bind or if a bind with the name exists return the bind.

Returns
  0 on success; negative on error. -EALREADY returned in case a bind with the name exists

References priv_bind::addr, osmo_fd::cb, osmo_fd::data, gprs_ns2_vc_bind::driver, priv_bind::dscp, priv_bind::fd, FRAME_RELAY_SDU, free_vc(), gprs_ns2_vc_bind::free_vc, frgre_fd_cb(), frgre_vc_sendmsg(), gprs_ns2_bind_by_name(), gprs_ns2_free_bind(), GPRS_NS2_LL_FR_GRE, INIT_LLIST_HEAD, IPPROTO_GRE, gprs_ns2_vc_bind::ll, gprs_ns2_vc_bind::mtu, name, ns2_bind_alloc(), gprs_ns2_vc_bind::nsi, gprs_ns2_vc_bind::nsvc, OSMO_SOCK_F_BIND, OSMO_SOCK_F_DSCP, osmo_sock_init_osa_ofd(), gprs_ns2_vc_bind::priv, osmo_sockaddr::sa, gprs_ns2_vc_bind::send_vc, gprs_ns2_vc_bind::transfer_capability, osmo_sockaddr::u, and vc_driver_frgre.

## ◆ 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, and vc_driver_frgre.

## ◆ handle_nsfrgre_read()

static int handle_nsfrgre_read | ( | struct osmo_fd * | bfd | ) |
| static

References osmo_fd::data, frgre_alloc_vc(), frgre_sendmsg(), LOGBIND, LOGL_INFO, msg, msgb_free(), ns2_create_vc(), NS2_CS_CREATED, NS2_CS_ERROR, NS2_CS_FOUND, NS2_CS_REJECTED, NS2_CS_SKIPPED, ns2_find_vc_by_dlci(), ns2_recv_vc(), ns2_vc_fsm_start(), and read_nsfrgre_msg().

Referenced by frgre_fd_cb().

## ◆ handle_nsfrgre_write()

static int handle_nsfrgre_write | ( | struct osmo_fd * | bfd | ) |
| static

Referenced by frgre_fd_cb().

## ◆ handle_rx_gre_ipv4()

static int handle_rx_gre_ipv4 | ( | struct osmo_fd * | bfd,
|  | struct msgb * | msg,
|  | struct iphdr * | iph,
|  | struct gre_hdr * | greh
| ) |  |
| static

References osmo_fd::data, osmo_fd::fd, priv_bind::fd, GRE_PTYPE_KAR, IPPROTO_GRE, LOGBIND, LOGL_DEBUG, LOGL_ERROR, msg, osmo_htons, gprs_ns2_vc_bind::priv, and gre_hdr::ptype.

Referenced by read_nsfrgre_msg().

## ◆ handle_rx_gre_ipv6()

static int handle_rx_gre_ipv6 | ( | struct osmo_fd * | bfd,
|  | struct msgb * | msg,
|  | struct ip6_hdr * | ip6hdr,
|  | struct gre_hdr * | greh
| ) |  |
| static

References osmo_fd::data, osmo_fd::fd, priv_bind::fd, GRE_PTYPE_KAR, IPPROTO_GRE, LOGBIND, LOGL_DEBUG, LOGL_ERROR, msg, osmo_htons, gprs_ns2_vc_bind::priv, and gre_hdr::ptype.

Referenced by read_nsfrgre_msg().

## ◆ ns2_find_vc_by_dlci()

static int ns2_find_vc_by_dlci | ( | struct gprs_ns2_vc_bind * | bind,
|  | uint16_t | dlci,
|  | struct gprs_ns2_vc ** | result
| ) |  |
| static

References priv_vc::dlci, llist_for_each_entry, gprs_ns2_vc_bind::nsvc, and gprs_ns2_vc::priv.

Referenced by handle_nsfrgre_read().

## ◆ read_nsfrgre_msg()

static struct msgb * read_nsfrgre_msg | ( | struct osmo_fd * | bfd,
|  | int * | error,
|  | struct osmo_sockaddr * | saddr,
|  | uint16_t * | dlci,
|  | const struct gprs_ns2_vc_bind * | bind
| ) |  |
| static

References osmo_fd::fd, gre_hdr::flags, GRE_PTYPE_FR, GRE_PTYPE_IPv4, GRE_PTYPE_IPv6, handle_rx_gre_ipv4(), handle_rx_gre_ipv6(), if(), LOGBIND, LOGL_ERROR, LOGL_NOTICE, msg, msgb_alloc(), msgb_free(), msgb_put(), NS_ALLOC_SIZE, osmo_ntohs, gre_hdr::ptype, osmo_sockaddr::sa, and osmo_sockaddr::u.

Referenced by handle_nsfrgre_read().

## Variable Documentation

## ◆ __attribute__

struct priv_bind __attribute__

## ◆ flags

uint16_t flags

## ◆ ptype

uint16_t ptype

## ◆ vc_driver_frgre

struct gprs_ns2_vc_driver vc_driver_frgre

Initial value:
= {
.name = "GB frame relay over GRE",
.free_bind = free_bind,
}
free_bind
static void free_bind(struct gprs_ns2_vc_bind *bind)
clean up all private driver state.
Definition: gprs_ns2_frgre.c:135

Referenced by gprs_ns2_frgre_bind(), and gprs_ns2_is_frgre_bind().