Split cbc_peer to its own .c and .h files
Change-Id: I41c890d81e76ac1a1c89d42af70a1f0631e9724e
This commit is contained in:
parent
f4741401e2
commit
1486ac0191
|
@ -1,5 +1,6 @@
|
|||
noinst_HEADERS = \
|
||||
cbc_data.h \
|
||||
cbc_peer.h \
|
||||
cbsp_server.h \
|
||||
charset.h \
|
||||
internal.h \
|
||||
|
|
|
@ -7,40 +7,9 @@
|
|||
#include <osmocom/gsm/protocol/gsm_48_049.h>
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
|
||||
struct osmo_cbsp_cbc_client;
|
||||
struct osmo_sabp_cbc_client;
|
||||
struct rest_it_op;
|
||||
|
||||
#define CBC_MAX_ADDRS 8
|
||||
|
||||
/*********************************************************************************
|
||||
* CBC Peer
|
||||
*********************************************************************************/
|
||||
|
||||
enum cbc_peer_protocol {
|
||||
CBC_PEER_PROTO_CBSP,
|
||||
CBC_PEER_PROTO_SABP,
|
||||
CBC_PEER_PROTO_SBcAP
|
||||
};
|
||||
|
||||
struct cbc_peer {
|
||||
struct llist_head list; /* linked to cbc.peers */
|
||||
const char *name;
|
||||
|
||||
char *remote_host[CBC_MAX_ADDRS]; /* remote IP address in string format */
|
||||
unsigned int num_remote_host; /* number of addresses present in remote_host */
|
||||
int remote_port; /* remote port number or -1 for random */
|
||||
bool unknown_dynamic_peer; /* dynamic/unknown peer; not saved in VTY */
|
||||
|
||||
enum cbc_peer_protocol proto;
|
||||
union {
|
||||
struct osmo_cbsp_cbc_client *cbsp;
|
||||
struct osmo_sabp_cbc_client *sabp;
|
||||
struct osmo_sbcap_cbc_client *sbcap;
|
||||
} client;
|
||||
};
|
||||
|
||||
extern const struct value_string cbc_peer_proto_name[];
|
||||
#define CBC_MAX_LOC_ADDRS 8
|
||||
|
||||
enum cbc_cell_id_type {
|
||||
CBC_CELL_ID_NONE,
|
||||
|
@ -176,7 +145,7 @@ struct cbc {
|
|||
int local_port;
|
||||
} cbsp;
|
||||
struct {
|
||||
char *local_host[CBC_MAX_ADDRS];
|
||||
char *local_host[CBC_MAX_LOC_ADDRS];
|
||||
unsigned int num_local_host;
|
||||
int local_port;
|
||||
} sbcap;
|
||||
|
@ -202,8 +171,3 @@ int cbc_message_del_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
|||
int cbc_message_add_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
||||
struct cbc_message_peer *smscb_peer_fsm_alloc(struct cbc_peer *peer, struct cbc_message *cbcmsg);
|
||||
struct cbc_message_peer *cbc_message_peer_get(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
||||
struct cbc_peer *cbc_peer_by_name(const char *name);
|
||||
struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote_port,
|
||||
enum cbc_peer_protocol proto);
|
||||
struct cbc_peer *cbc_peer_create(const char *name, enum cbc_peer_protocol proto);
|
||||
void cbc_peer_remove(struct cbc_peer *peer);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
|
||||
struct osmo_cbsp_cbc_client;
|
||||
struct osmo_sabp_cbc_client;
|
||||
struct osmo_sbcap_cbc_client;
|
||||
|
||||
#define CBC_MAX_REM_ADDRS 8
|
||||
|
||||
/*********************************************************************************
|
||||
* CBC Peer
|
||||
*********************************************************************************/
|
||||
|
||||
enum cbc_peer_protocol {
|
||||
CBC_PEER_PROTO_CBSP,
|
||||
CBC_PEER_PROTO_SABP,
|
||||
CBC_PEER_PROTO_SBcAP
|
||||
};
|
||||
|
||||
struct cbc_peer {
|
||||
struct llist_head list; /* linked to cbc.peers */
|
||||
const char *name;
|
||||
|
||||
char *remote_host[CBC_MAX_REM_ADDRS]; /* remote IP address in string format */
|
||||
unsigned int num_remote_host; /* number of addresses present in remote_host */
|
||||
int remote_port; /* remote port number or -1 for random */
|
||||
bool unknown_dynamic_peer; /* dynamic/unknown peer; not saved in VTY */
|
||||
|
||||
enum cbc_peer_protocol proto;
|
||||
union {
|
||||
struct osmo_cbsp_cbc_client *cbsp;
|
||||
struct osmo_sabp_cbc_client *sabp;
|
||||
struct osmo_sbcap_cbc_client *sbcap;
|
||||
} client;
|
||||
};
|
||||
|
||||
extern const struct value_string cbc_peer_proto_name[];
|
||||
|
||||
struct cbc_peer *cbc_peer_create(const char *name, enum cbc_peer_protocol proto);
|
||||
void cbc_peer_remove(struct cbc_peer *peer);
|
||||
|
||||
struct cbc_peer *cbc_peer_by_name(const char *name);
|
||||
struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote_port,
|
||||
enum cbc_peer_protocol proto);
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
struct osmo_cbsp_cbc_client;
|
||||
struct osmo_fsm_inst;
|
||||
struct cbc_peer;
|
||||
|
||||
/* a CBC server */
|
||||
struct osmo_cbsp_cbc {
|
||||
|
|
|
@ -13,6 +13,7 @@ typedef struct SBcAP_SBC_AP_PDU SBcAP_SBC_AP_PDU_t;
|
|||
|
||||
struct osmo_sbcap_cbc_client;
|
||||
struct osmo_fsm_inst;
|
||||
struct cbc_peer;
|
||||
|
||||
/* a CBC server */
|
||||
struct osmo_sbcap_cbc {
|
||||
|
|
|
@ -12,6 +12,7 @@ bin_PROGRAMS = osmo-cbc
|
|||
osmo_cbc_SOURCES = \
|
||||
cbc_main.c \
|
||||
cbc_data.c \
|
||||
cbc_peer.c \
|
||||
cbc_vty.c \
|
||||
cbsp_server.c \
|
||||
cbsp_server_fsm.c \
|
||||
|
|
|
@ -31,13 +31,6 @@
|
|||
#include <osmocom/cbc/cbc_data.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
|
||||
const struct value_string cbc_peer_proto_name[] = {
|
||||
{ CBC_PEER_PROTO_CBSP, "CBSP" },
|
||||
{ CBC_PEER_PROTO_SABP, "SABP" },
|
||||
{ CBC_PEER_PROTO_SBcAP, "SBc-AP" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* remove a peer from the message */
|
||||
int cbc_message_del_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer)
|
||||
{
|
||||
|
@ -79,80 +72,3 @@ int cbc_message_add_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* look-up of cbc_peer by name */
|
||||
struct cbc_peer *cbc_peer_by_name(const char *name)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
if (peer->name && !strcmp(name, peer->name))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up of cbc_peer by tuple of (remote host, protocol) */
|
||||
struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote_port,
|
||||
enum cbc_peer_protocol proto)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < peer->num_remote_host; i++) {
|
||||
if (peer->proto != proto)
|
||||
continue;
|
||||
if (!strcasecmp(remote_host, peer->remote_host[i])) {
|
||||
if (peer->remote_port == -1)
|
||||
return peer;
|
||||
else if (remote_port == peer->remote_port)
|
||||
return peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create a new cbc_peer */
|
||||
struct cbc_peer *cbc_peer_create(const char *name, enum cbc_peer_protocol proto)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
if (name && cbc_peer_by_name(name))
|
||||
return NULL;
|
||||
|
||||
peer = talloc_zero(g_cbc, struct cbc_peer);
|
||||
if (!peer)
|
||||
return NULL;
|
||||
|
||||
peer->proto = proto;
|
||||
peer->name = talloc_strdup(peer, name);
|
||||
llist_add_tail(&peer->list, &g_cbc->peers);
|
||||
|
||||
return peer;
|
||||
}
|
||||
|
||||
/* remove a cbc_peer */
|
||||
void cbc_peer_remove(struct cbc_peer *peer)
|
||||
{
|
||||
struct cbc_message *cbcmsg;
|
||||
|
||||
/* close any existing client connection */
|
||||
switch (peer->proto) {
|
||||
case CBC_PEER_PROTO_CBSP:
|
||||
if (peer->client.cbsp)
|
||||
cbsp_cbc_client_close(peer->client.cbsp);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
|
||||
/* iterate over messages; remove client from all message_peers */
|
||||
llist_for_each_entry(cbcmsg, &g_cbc->messages, list) {
|
||||
cbc_message_del_peer(cbcmsg, peer);
|
||||
}
|
||||
|
||||
llist_del(&peer->list);
|
||||
talloc_free(peer);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/* Osmocom CBC (Cell Broacast Centre) */
|
||||
|
||||
/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0+
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
|
||||
const struct value_string cbc_peer_proto_name[] = {
|
||||
{ CBC_PEER_PROTO_CBSP, "CBSP" },
|
||||
{ CBC_PEER_PROTO_SABP, "SABP" },
|
||||
{ CBC_PEER_PROTO_SBcAP, "SBc-AP" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* create a new cbc_peer */
|
||||
struct cbc_peer *cbc_peer_create(const char *name, enum cbc_peer_protocol proto)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
if (name && cbc_peer_by_name(name))
|
||||
return NULL;
|
||||
|
||||
peer = talloc_zero(g_cbc, struct cbc_peer);
|
||||
if (!peer)
|
||||
return NULL;
|
||||
|
||||
peer->proto = proto;
|
||||
peer->name = talloc_strdup(peer, name);
|
||||
llist_add_tail(&peer->list, &g_cbc->peers);
|
||||
|
||||
return peer;
|
||||
}
|
||||
|
||||
/* remove a cbc_peer */
|
||||
void cbc_peer_remove(struct cbc_peer *peer)
|
||||
{
|
||||
struct cbc_message *cbcmsg;
|
||||
|
||||
/* close any existing client connection */
|
||||
switch (peer->proto) {
|
||||
case CBC_PEER_PROTO_CBSP:
|
||||
if (peer->client.cbsp)
|
||||
cbsp_cbc_client_close(peer->client.cbsp);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
|
||||
/* iterate over messages; remove client from all message_peers */
|
||||
llist_for_each_entry(cbcmsg, &g_cbc->messages, list) {
|
||||
cbc_message_del_peer(cbcmsg, peer);
|
||||
}
|
||||
|
||||
llist_del(&peer->list);
|
||||
talloc_free(peer);
|
||||
}
|
||||
|
||||
/* look-up of cbc_peer by name */
|
||||
struct cbc_peer *cbc_peer_by_name(const char *name)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
if (peer->name && !strcmp(name, peer->name))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up of cbc_peer by tuple of (remote host, protocol) */
|
||||
struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote_port,
|
||||
enum cbc_peer_protocol proto)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < peer->num_remote_host; i++) {
|
||||
if (peer->proto != proto)
|
||||
continue;
|
||||
if (!strcasecmp(remote_host, peer->remote_host[i])) {
|
||||
if (peer->remote_port == -1)
|
||||
return peer;
|
||||
else if (remote_port == peer->remote_port)
|
||||
return peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
#include <osmocom/vty/vty.h>
|
||||
|
||||
#include <osmocom/cbc/cbc_data.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
#include <osmocom/cbc/internal.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
#include <osmocom/cbc/sbcap_server.h>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <osmocom/cbc/internal.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
|
||||
#if 0
|
||||
struct osmo_cbsp_bsc {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <osmocom/gsm/cbsp.h>
|
||||
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
#include <osmocom/cbc/internal.h>
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <osmocom/cbc/sbcap_msg.h>
|
||||
#include <osmocom/cbc/rest_it_op.h>
|
||||
#include <osmocom/cbc/internal.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
|
||||
/* convert cbc_message to osmo_cbsp_cell_list */
|
||||
static int cbcmsg_to_cbsp_cell_list(const void *ctx, struct osmo_cbsp_cell_list *list,
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include <osmocom/cbc/internal.h>
|
||||
#include <osmocom/cbc/sbcap_server.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
|
||||
const char *sbcap_cbc_client_name(const struct osmo_sbcap_cbc_client *client)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <osmocom/cbc/sbcap_server.h>
|
||||
#include <osmocom/cbc/internal.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
|
||||
#define S(x) (1 << (x))
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <osmocom/sbcap/sbcap_common.h>
|
||||
|
||||
#include <osmocom/cbc/cbc_data.h>
|
||||
#include <osmocom/cbc/cbc_peer.h>
|
||||
#include <osmocom/cbc/cbsp_server.h>
|
||||
#include <osmocom/cbc/sbcap_server.h>
|
||||
#include <osmocom/cbc/sbcap_msg.h>
|
||||
|
|
Loading…
Reference in New Issue