libosmo-sigtran 2.0.0.52-6412
Osmocom SIGTRAN library
osmo_ss7_asp.c File Reference
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <inttypes.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <osmocom/sigtran/osmo_ss7.h>
#include <osmocom/sigtran/mtp_sap.h>
#include <osmocom/sigtran/protocol/mtp.h>
#include <osmocom/sigtran/protocol/sua.h>
#include <osmocom/sigtran/protocol/m3ua.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/select.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/sockaddr_str.h>
#include <osmocom/core/osmo_io.h>
#include <osmocom/netif/stream.h>
#include <osmocom/netif/ipa.h>
#include <osmocom/netif/sctp.h>
#include "sccp_internal.h"
#include "xua_internal.h"
#include "ss7_as.h"
#include "ss7_asp.h"
#include "ss7_internal.h"
#include "ss7_xua_srv.h"
#include "xua_asp_fsm.h"
#include "xua_as_fsm.h"

Functions

static int _setsockopt_peer_primary_addr (int fd, const struct osmo_sockaddr *saddr)
 
static int _setsockopt_primary_addr (int fd, const struct osmo_sockaddr *saddr)
 
bool ss7_asp_protocol_check_trans_proto (enum osmo_ss7_asp_protocol proto, int trans_proto)
 
int ss7_default_trans_proto_for_asp_proto (enum osmo_ss7_asp_protocol proto)
 
int osmo_ss7_asp_protocol_port (enum osmo_ss7_asp_protocol prot)
 
int ss7_asp_apply_new_local_address (const struct osmo_ss7_asp *asp, unsigned int loc_idx)
 
int ss7_asp_apply_drop_local_address (const struct osmo_ss7_asp *asp, unsigned int loc_idx)
 
int ss7_asp_apply_peer_primary_address (const struct osmo_ss7_asp *asp)
 
int ss7_asp_apply_primary_address (const struct osmo_ss7_asp *asp)
 
static bool sctp_peer_addr_change_ev_addr_matches_our_primary (const struct osmo_ss7_asp *asp, const union sctp_notification *notif)
 
static void asp_handle_sctp_notif_monitor_primary_address (const struct osmo_ss7_asp *asp, const union sctp_notification *notif)
 
bool ss7_asp_set_default_peer_hosts (struct osmo_ss7_asp *asp)
 
static uint16_t get_in_port (struct sockaddr *sa)
 
static void chop_v4_mapped_on_v6_prefix (char *buf)
 
struct osmo_ss7_aspss7_asp_find_by_socket_addr (int fd, int trans_proto)
 Find an ASP definition matching the local+remote IP/PORT of given fd. More...
 
struct osmo_ss7_aspss7_asp_alloc (struct osmo_ss7_instance *inst, const char *name, uint16_t remote_port, uint16_t local_port, int trans_proto, enum osmo_ss7_asp_protocol proto)
 
void osmo_ss7_asp_destroy (struct osmo_ss7_asp *asp)
 
static int xua_cli_read_cb (struct osmo_stream_cli *conn, int res, struct msgb *msg)
 
static int ipa_cli_read_cb (struct osmo_stream_cli *conn, int res, struct msgb *msg)
 
static int m3ua_tcp_cli_read_cb (struct osmo_stream_cli *conn, int res, struct msgb *msg)
 
static int xua_cli_connect_cb (struct osmo_stream_cli *cli)
 
static int xua_cli_close_and_reconnect (struct osmo_stream_cli *cli)
 
int osmo_ss7_asp_restart (struct osmo_ss7_asp *asp)
 
bool osmo_ss7_asp_active (const struct osmo_ss7_asp *asp)
 
bool ss7_asp_is_started (const struct osmo_ss7_asp *asp)
 
static int get_logevel_by_sn_type (int sn_type)
 
static void log_sctp_notification (struct osmo_ss7_asp *asp, const char *pfx, union sctp_notification *notif)
 
int ss7_asp_ipa_srv_conn_rx_cb (struct osmo_stream_srv *conn, int res, struct msgb *msg)
 
int ss7_asp_xua_srv_conn_rx_cb (struct osmo_stream_srv *conn, int res, struct msgb *msg)
 
int xua_tcp_segmentation_cb (struct msgb *msg)
 
int ss7_asp_m3ua_tcp_srv_conn_rx_cb (struct osmo_stream_srv *conn, int res, struct msgb *msg)
 
static void xua_cli_close (struct osmo_stream_cli *cli)
 
int ss7_asp_xua_srv_conn_closed_cb (struct osmo_stream_srv *srv)
 
int osmo_ss7_asp_send (struct osmo_ss7_asp *asp, struct msgb *msg)
 send a fully encoded msgb via a given ASP More...
 
void osmo_ss7_asp_disconnect (struct osmo_ss7_asp *asp)
 
void osmo_ss7_register_rx_unknown_cb (osmo_ss7_asp_rx_unknown_cb *cb)
 Register a call-back function for unknown SCTP PPID / IPA Stream ID. More...
 
int ss7_asp_rx_unknown (struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg)
 
int osmo_ss7_asp_get_log_subsys (const struct osmo_ss7_asp *asp)
 Get the logging subsystem for a given ASP. More...
 
const char * osmo_ss7_asp_get_name (const struct osmo_ss7_asp *asp)
 Get the name of a given ASP. More...
 
enum osmo_ss7_asp_protocol osmo_ss7_asp_get_proto (const struct osmo_ss7_asp *asp)
 Get the proto of a given ASP. More...
 
int osmo_ss7_asp_get_trans_proto (const struct osmo_ss7_asp *asp)
 Get the transport proto of a given ASP. More...
 
int ss7_asp_get_fd (const struct osmo_ss7_asp *asp)
 Get the fd of a given ASP. More...
 

Variables

struct value_string osmo_ss7_asp_protocol_vals []
 
const struct value_string osmo_ss7_asp_role_names []
 
static const uint16_t prot2port []
 
static const struct rate_ctr_desc ss7_asp_rcd []
 
static const struct rate_ctr_group_desc ss7_asp_rcgd
 
static unsigned int g_ss7_asp_rcg_idx
 
static osmo_ss7_asp_rx_unknown_cbg_osmo_ss7_asp_rx_unknown_cb
 

Function Documentation

◆ _setsockopt_peer_primary_addr()

static int _setsockopt_peer_primary_addr ( int  fd,
const struct osmo_sockaddr *  saddr 
)
static

◆ _setsockopt_primary_addr()

static int _setsockopt_primary_addr ( int  fd,
const struct osmo_sockaddr *  saddr 
)
static

◆ asp_handle_sctp_notif_monitor_primary_address()

static void asp_handle_sctp_notif_monitor_primary_address ( const struct osmo_ss7_asp asp,
const union sctp_notification *  notif 
)
static

◆ chop_v4_mapped_on_v6_prefix()

static void chop_v4_mapped_on_v6_prefix ( char *  buf)
static

References len.

Referenced by ss7_asp_find_by_socket_addr().

◆ get_in_port()

static uint16_t get_in_port ( struct sockaddr *  sa)
static

◆ get_logevel_by_sn_type()

static int get_logevel_by_sn_type ( int  sn_type)
static

Referenced by log_sctp_notification().

◆ ipa_cli_read_cb()

static int ipa_cli_read_cb ( struct osmo_stream_cli *  conn,
int  res,
struct msgb *  msg 
)
static

◆ log_sctp_notification()

static void log_sctp_notification ( struct osmo_ss7_asp asp,
const char *  pfx,
union sctp_notification *  notif 
)
static

◆ m3ua_tcp_cli_read_cb()

static int m3ua_tcp_cli_read_cb ( struct osmo_stream_cli *  conn,
int  res,
struct msgb *  msg 
)
static

◆ osmo_ss7_asp_active()

◆ osmo_ss7_asp_destroy()

◆ osmo_ss7_asp_disconnect()

◆ osmo_ss7_asp_get_log_subsys()

int osmo_ss7_asp_get_log_subsys ( const struct osmo_ss7_asp asp)

◆ osmo_ss7_asp_get_name()

const char * osmo_ss7_asp_get_name ( const struct osmo_ss7_asp asp)

Get the name of a given ASP.

Parameters
[in]aspThe ASP for which the name is requested
Returns
The name of the ASP, or NULL if not set

References osmo_ss7_asp::cfg, and osmo_ss7_asp::name.

◆ osmo_ss7_asp_get_proto()

enum osmo_ss7_asp_protocol osmo_ss7_asp_get_proto ( const struct osmo_ss7_asp asp)

Get the proto of a given ASP.

Parameters
[in]aspThe ASP for which the proto is requested
Returns
The proto of the ASP

References osmo_ss7_asp::cfg, and osmo_ss7_asp::proto.

◆ osmo_ss7_asp_get_trans_proto()

int osmo_ss7_asp_get_trans_proto ( const struct osmo_ss7_asp asp)

Get the transport proto of a given ASP.

Parameters
[in]aspThe ASP for which the transport proto is requested
Returns
The transport proto of the ASP (one of IPPROTO_*)

References osmo_ss7_asp::cfg, and osmo_ss7_asp::trans_proto.

◆ osmo_ss7_asp_protocol_port()

◆ osmo_ss7_asp_restart()

◆ osmo_ss7_asp_send()

int osmo_ss7_asp_send ( struct osmo_ss7_asp asp,
struct msgb *  msg 
)

◆ osmo_ss7_register_rx_unknown_cb()

void osmo_ss7_register_rx_unknown_cb ( osmo_ss7_asp_rx_unknown_cb cb)

Register a call-back function for unknown SCTP PPID / IPA Stream ID.

References g_osmo_ss7_asp_rx_unknown_cb.

◆ sctp_peer_addr_change_ev_addr_matches_our_primary()

static bool sctp_peer_addr_change_ev_addr_matches_our_primary ( const struct osmo_ss7_asp asp,
const union sctp_notification *  notif 
)
static

◆ ss7_asp_alloc()

◆ ss7_asp_apply_drop_local_address()

int ss7_asp_apply_drop_local_address ( const struct osmo_ss7_asp asp,
unsigned int  loc_idx 
)

◆ ss7_asp_apply_new_local_address()

int ss7_asp_apply_new_local_address ( const struct osmo_ss7_asp asp,
unsigned int  loc_idx 
)

◆ ss7_asp_apply_peer_primary_address()

◆ ss7_asp_apply_primary_address()

◆ ss7_asp_find_by_socket_addr()

struct osmo_ss7_asp * ss7_asp_find_by_socket_addr ( int  fd,
int  trans_proto 
)

Find an ASP definition matching the local+remote IP/PORT of given fd.

Parameters
[in]fdsocket descriptor of given socket
Returns
SS7 ASP in case a matching one is found; NULL otherwise

References osmo_ss7_instance::asp_list, osmo_ss7_asp::cfg, chop_v4_mapped_on_v6_prefix(), get_in_port(), osmo_ss7_asp_peer::host_cnt, osmo_ss7_asp::inst, osmo_ss7_asp::list, osmo_ss7_asp::local, osmo_ss7_instances, osmo_ss7_asp_peer::port, osmo_ss7_asp::remote, ss7_asp_peer_match_host(), ss7_initialized, and osmo_ss7_asp::trans_proto.

Referenced by xua_accept_cb().

◆ ss7_asp_get_fd()

int ss7_asp_get_fd ( const struct osmo_ss7_asp asp)

Get the fd of a given ASP.

Parameters
[in]aspThe ASP for which the fd is requested
Returns
The fd of the ASP if acailable, negative otherwise

References osmo_ss7_asp::cfg, osmo_ss7_asp::client, osmo_ss7_asp::is_server, and osmo_ss7_asp::server.

Referenced by show_one_asp(), show_one_asp_assoc_status_tcp(), and show_one_asp_remaddr_tcp().

◆ ss7_asp_ipa_srv_conn_rx_cb()

int ss7_asp_ipa_srv_conn_rx_cb ( struct osmo_stream_srv *  conn,
int  res,
struct msgb *  msg 
)

◆ ss7_asp_is_started()

bool ss7_asp_is_started ( const struct osmo_ss7_asp asp)

◆ ss7_asp_m3ua_tcp_srv_conn_rx_cb()

int ss7_asp_m3ua_tcp_srv_conn_rx_cb ( struct osmo_stream_srv *  conn,
int  res,
struct msgb *  msg 
)

◆ ss7_asp_protocol_check_trans_proto()

bool ss7_asp_protocol_check_trans_proto ( enum osmo_ss7_asp_protocol  proto,
int  trans_proto 
)

◆ ss7_asp_rx_unknown()

◆ ss7_asp_set_default_peer_hosts()

◆ ss7_asp_xua_srv_conn_closed_cb()

◆ ss7_asp_xua_srv_conn_rx_cb()

◆ ss7_default_trans_proto_for_asp_proto()

◆ xua_cli_close()

static void xua_cli_close ( struct osmo_stream_cli *  cli)
static

◆ xua_cli_close_and_reconnect()

static int xua_cli_close_and_reconnect ( struct osmo_stream_cli *  cli)
static

◆ xua_cli_connect_cb()

◆ xua_cli_read_cb()

◆ xua_tcp_segmentation_cb()

int xua_tcp_segmentation_cb ( struct msgb *  msg)

Variable Documentation

◆ g_osmo_ss7_asp_rx_unknown_cb

osmo_ss7_asp_rx_unknown_cb* g_osmo_ss7_asp_rx_unknown_cb
static

◆ g_ss7_asp_rcg_idx

unsigned int g_ss7_asp_rcg_idx
static

Referenced by ss7_asp_alloc().

◆ osmo_ss7_asp_protocol_vals

struct value_string osmo_ss7_asp_protocol_vals[]
Initial value:
= {
{ 0, NULL }
}
@ OSMO_SS7_ASP_PROT_SUA
Definition: osmo_ss7.h:155
@ OSMO_SS7_ASP_PROT_NONE
Definition: osmo_ss7.h:154
@ OSMO_SS7_ASP_PROT_IPA
Definition: osmo_ss7.h:157
@ OSMO_SS7_ASP_PROT_M3UA
Definition: osmo_ss7.h:156

Referenced by osmo_ss7_asp_protocol_name(), parse_asp_proto(), show_one_asp(), ss7_xua_server_bind(), ss7_xua_server_create2(), vty_dump_xua_server(), write_one_xua(), and xua_accept_cb().

◆ osmo_ss7_asp_role_names

const struct value_string osmo_ss7_asp_role_names[]
Initial value:
= {
{ 0, NULL }
}
@ OSMO_SS7_ASP_ROLE_SG
Definition: osmo_ss7.h:240
@ OSMO_SS7_ASP_ROLE_ASP
Definition: osmo_ss7.h:239
@ OSMO_SS7_ASP_ROLE_IPSP
Definition: osmo_ss7.h:241

Referenced by show_one_asp(), and write_one_asp().

◆ prot2port

const uint16_t prot2port[]
static
Initial value:
= {
}
#define M3UA_PORT
Definition: m3ua.h:26
#define SUA_PORT
Definition: sua.h:29

Referenced by osmo_ss7_asp_protocol_port().

◆ ss7_asp_rcd

const struct rate_ctr_desc ss7_asp_rcd[]
static
Initial value:
= {
[SS7_ASP_CTR_PKT_RX_TOTAL] = { "rx:packets:total", "Total number of packets received" },
[SS7_ASP_CTR_PKT_RX_UNKNOWN] = { "rx:packets:unknown", "Number of packets received for unknown PPID" },
[SS7_ASP_CTR_PKT_TX_TOTAL] = { "tx:packets:total", "Total number of packets transmitted" },
}
@ SS7_ASP_CTR_PKT_TX_TOTAL
Definition: ss7_asp.h:25
@ SS7_ASP_CTR_PKT_RX_UNKNOWN
Definition: ss7_asp.h:24
@ SS7_ASP_CTR_PKT_RX_TOTAL
Definition: ss7_asp.h:23

◆ ss7_asp_rcgd

const struct rate_ctr_group_desc ss7_asp_rcgd
static
Initial value:
= {
.group_name_prefix = "sigtran_asp",
.group_description = "SIGTRAN Application Server Process",
.num_ctr = ARRAY_SIZE(ss7_asp_rcd),
.ctr_desc = ss7_asp_rcd,
}
static const struct rate_ctr_desc ss7_asp_rcd[]
Definition: osmo_ss7_asp.c:186

Referenced by ss7_asp_alloc().