libosmo-sigtran 2.0.0.52-6412
Osmocom SIGTRAN library
osmo_ss7_asp_peer.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/core/utils.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/sockaddr_str.h>
#include <osmocom/sigtran/osmo_ss7.h>
#include "ss7_asp_peer.h"
#include "ss7_internal.h"

Functions

void ss7_asp_peer_init (struct osmo_ss7_asp_peer *peer)
 
int ss7_asp_peer_snprintf (char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer)
 
int 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 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 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 ss7_asp_peer_del_host (struct osmo_ss7_asp_peer *peer, const char *host)
 Remove address from a given ASP peer. More...
 
int 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...
 
bool ss7_asp_peer_match_host (const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6)
 
int ss7_asp_peer_find_host (const struct osmo_ss7_asp_peer *peer, const char *host)
 Find the exact IP address match and return its index in the array. More...
 

Function Documentation

◆ host_is_ip_anyaddr()

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

◆ ss7_asp_peer_add_host()

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

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

◆ ss7_asp_peer_add_host2()

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

◆ ss7_asp_peer_del_host()

int ss7_asp_peer_del_host ( struct osmo_ss7_asp_peer peer,
const char *  host 
)

Remove address from a given ASP peer.

Parameters
[in]peerApplication Server Process peer the address is removed from.
[in]hoststring containing an IP address.
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 DEFUN_ATTR(), and ss7_xua_server_del_local_host().

◆ ss7_asp_peer_find_host()

int ss7_asp_peer_find_host ( const struct osmo_ss7_asp_peer peer,
const char *  host 
)

Find the exact IP address match and return its index in the array.

Parameters
[in]peerApplication Server Process peer where the address is looked up.
[in]hoststring containing an IP address.
Returns
>=0 on success containing the index of the host; negative otherwise

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

Referenced by DEFUN_ATTR().

◆ ss7_asp_peer_init()

void ss7_asp_peer_init ( struct osmo_ss7_asp_peer peer)

References osmo_ss7_asp_peer::idx_primary.

Referenced by ss7_asp_alloc().

◆ ss7_asp_peer_match_host()

bool ss7_asp_peer_match_host ( const struct osmo_ss7_asp_peer peer,
const char *  host,
bool  host_is_v6 
)

◆ ss7_asp_peer_set_hosts()

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

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

◆ ss7_asp_peer_set_hosts2()

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

◆ ss7_asp_peer_snprintf()