libosmo-sigtran  1.8.1
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/netif/stream.h>
#include <osmocom/netif/ipa.h>
#include <osmocom/netif/sctp.h>
#include "sccp_internal.h"
#include "xua_internal.h"
#include "ss7_internal.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)
 
int ss7_asp_proto_to_ip_proto (enum osmo_ss7_asp_protocol proto)
 
int osmo_ss7_asp_protocol_port (enum osmo_ss7_asp_protocol prot)
 
void osmo_ss7_asp_peer_init (struct osmo_ss7_asp_peer *peer)
 
int osmo_ss7_asp_peer_snprintf (char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer)
 
int osmo_ss7_asp_peer_set_hosts2 (struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const *hosts, size_t host_cnt, int idx_primary)
 Set (copy) addresses for a given ASP peer. More...
 
int osmo_ss7_asp_peer_set_hosts (struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const *hosts, size_t host_cnt)
 Set (copy) addresses for a given ASP peer. More...
 
static bool host_is_ip_anyaddr (const char *host, bool is_v6)
 
int osmo_ss7_asp_peer_add_host2 (struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host, bool is_primary_addr)
 Append (copy) address to a given ASP peer. More...
 
int osmo_ss7_asp_peer_add_host (struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host)
 Append (copy) address to a given ASP peer. More...
 
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)
 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, 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)
 
static int ipa_cli_read_cb (struct osmo_stream_cli *conn)
 
static int xua_cli_connect_cb (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)
 
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_cb (struct osmo_stream_srv *conn)
 
int ss7_asp_xua_srv_conn_cb (struct osmo_stream_srv *conn)
 
static void xua_cli_close (struct osmo_stream_cli *cli)
 
static void xua_cli_close_and_reconnect (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...
 

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

◆ host_is_ip_anyaddr()

static bool host_is_ip_anyaddr ( const char *  host,
bool  is_v6 
)
inlinestatic

◆ ipa_cli_read_cb()

static int ipa_cli_read_cb ( struct osmo_stream_cli *  conn)
static

◆ log_sctp_notification()

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

◆ osmo_ss7_asp_active()

◆ osmo_ss7_asp_destroy()

◆ osmo_ss7_asp_disconnect()

void osmo_ss7_asp_disconnect ( struct osmo_ss7_asp asp)

◆ 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

◆ osmo_ss7_asp_peer_add_host()

int osmo_ss7_asp_peer_add_host ( struct osmo_ss7_asp_peer peer,
void *  talloc_ctx,
const char *  host 
)

Append (copy) address to a given ASP peer.

Previous addresses are kept.

Parameters
[in]peerApplication Server Process peer the address is appended to.
[in]talloc_ctxtalloc context used to allocate new address.
[in]hoststring containing an IP address.
Returns
0 on success; negative otherwise

References osmo_ss7_asp_peer_add_host2().

Referenced by osmo_sccp_simple_server_add_clnt(), osmo_ss7_xua_server_add_local_host(), and ss7_asp_set_default_peer_hosts().

◆ osmo_ss7_asp_peer_add_host2()

int osmo_ss7_asp_peer_add_host2 ( struct osmo_ss7_asp_peer peer,
void *  talloc_ctx,
const char *  host,
bool  is_primary_addr 
)

Append (copy) address to a given ASP peer.

Previous addresses are kept.

Parameters
[in]peerApplication Server Process peer the address is appended to.
[in]talloc_ctxtalloc context used to allocate new address.
[in]hoststring containing an IP address.
[in]is_primary_addrwhether this IP address is to be added as SCTP Primary Address
Returns
0 on success; negative otherwise

References osmo_ss7_asp_peer::host, osmo_ss7_asp_peer::host_cnt, host_is_ip_anyaddr(), and osmo_ss7_asp_peer::idx_primary.

Referenced by DEFUN_ATTR(), and osmo_ss7_asp_peer_add_host().

◆ osmo_ss7_asp_peer_init()

void osmo_ss7_asp_peer_init ( struct osmo_ss7_asp_peer peer)

References osmo_ss7_asp_peer::idx_primary.

Referenced by ss7_asp_alloc().

◆ osmo_ss7_asp_peer_set_hosts()

int osmo_ss7_asp_peer_set_hosts ( struct osmo_ss7_asp_peer peer,
void *  talloc_ctx,
const char *const *  hosts,
size_t  host_cnt 
)

Set (copy) addresses for a given ASP peer.

Previous addresses are freed.

Parameters
[in]peerApplication Server Process peer whose addresses are to be set.
[in]talloc_ctxtalloc context used to allocate new addresses.
[in]hostsArray of strings containing IP addresses.
[in]host_cntNumber of strings in hosts
Returns
0 on success; negative otherwise

References osmo_ss7_asp_peer_set_hosts2().

Referenced by osmo_sccp_simple_client_on_ss7_id(), osmo_sccp_simple_server_add_clnt(), osmo_ss7_xua_server_set_local_hosts(), and xua_accept_cb().

◆ osmo_ss7_asp_peer_set_hosts2()

int osmo_ss7_asp_peer_set_hosts2 ( struct osmo_ss7_asp_peer peer,
void *  talloc_ctx,
const char *const *  hosts,
size_t  host_cnt,
int  idx_primary 
)

Set (copy) addresses for a given ASP peer.

Previous addresses are freed.

Parameters
[in]peerApplication Server Process peer whose addresses are to be set.
[in]talloc_ctxtalloc context used to allocate new addresses.
[in]hostsArray of strings containing IP addresses.
[in]host_cntNumber of strings in hosts
[in]idx_primaryIndex in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set
Returns
0 on success; negative otherwise

References osmo_ss7_asp_peer::host, osmo_ss7_asp_peer::host_cnt, and osmo_ss7_asp_peer::idx_primary.

Referenced by osmo_ss7_asp_peer_set_hosts().

◆ osmo_ss7_asp_peer_snprintf()

int osmo_ss7_asp_peer_snprintf ( char *  buf,
size_t  buf_len,
struct osmo_ss7_asp_peer peer 
)

◆ 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_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)

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, osmo_ss7_asp_peer::host_cnt, host_is_ip_anyaddr(), osmo_ss7_asp::inst, osmo_ss7_asp::list, osmo_ss7_asp::local, osmo_ss7_instances, osmo_ss7_asp_peer::port, osmo_ss7_asp::remote, and ss7_initialized.

Referenced by xua_accept_cb().

◆ ss7_asp_ipa_srv_conn_cb()

int ss7_asp_ipa_srv_conn_cb ( struct osmo_stream_srv *  conn)

◆ ss7_asp_proto_to_ip_proto()

int ss7_asp_proto_to_ip_proto ( enum osmo_ss7_asp_protocol  proto)

◆ ss7_asp_rx_unknown()

int ss7_asp_rx_unknown ( struct osmo_ss7_asp asp,
int  ppid_mux,
struct msgb *  msg 
)

◆ ss7_asp_set_default_peer_hosts()

◆ ss7_asp_xua_srv_conn_cb()

◆ ss7_asp_xua_srv_conn_closed_cb()

◆ xua_cli_close()

static void xua_cli_close ( struct osmo_stream_cli *  cli)
static

◆ xua_cli_close_and_reconnect()

static void xua_cli_close_and_reconnect ( struct osmo_stream_cli *  cli)
static

◆ xua_cli_connect_cb()

◆ xua_cli_read_cb()

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:279
@ OSMO_SS7_ASP_PROT_NONE
Definition: osmo_ss7.h:278
@ OSMO_SS7_ASP_PROT_IPA
Definition: osmo_ss7.h:281
@ OSMO_SS7_ASP_PROT_M3UA
Definition: osmo_ss7.h:280

Referenced by DEFUN(), osmo_ss7_asp_protocol_name(), osmo_ss7_xua_server_bind(), osmo_ss7_xua_server_create(), 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:384
@ OSMO_SS7_ASP_ROLE_ASP
Definition: osmo_ss7.h:383
@ OSMO_SS7_ASP_ROLE_IPSP
Definition: osmo_ss7.h:385

Referenced by DEFUN().

◆ prot2port

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

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_internal.h:34
@ SS7_ASP_CTR_PKT_RX_UNKNOWN
Definition: ss7_internal.h:33
@ SS7_ASP_CTR_PKT_RX_TOTAL
Definition: ss7_internal.h:32

◆ 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:157

Referenced by ss7_asp_alloc().