Split cbsp/sbcap server socket creation from struct allocation
This will be needed when we add client support, since clients will require the mgr structs to be available during VTY parsing. Change-Id: I14e49d8d2e603925d7f06a7edb710c0eceb02ea3
This commit is contained in:
parent
5661cef889
commit
a97e166ee7
|
@ -24,7 +24,8 @@ struct cbc_cbsp_mgr {
|
|||
int (*rx_cb)(struct cbc_cbsp_link *link, struct osmo_cbsp_decoded *dec);
|
||||
};
|
||||
|
||||
struct cbc_cbsp_mgr *cbc_cbsp_mgr_create(void *ctx);
|
||||
struct cbc_cbsp_mgr *cbc_cbsp_mgr_alloc(void *ctx);
|
||||
int cbc_cbsp_mgr_open_srv(struct cbc_cbsp_mgr *mgr);
|
||||
|
||||
/* a CBSP link with a single (remote) peer connected to us */
|
||||
struct cbc_cbsp_link {
|
||||
|
|
|
@ -26,7 +26,8 @@ struct cbc_sbcap_mgr {
|
|||
/* receive call-back; called for every received message */
|
||||
int (*rx_cb)(struct cbc_sbcap_link *link, SBcAP_SBC_AP_PDU_t *pdu);
|
||||
};
|
||||
struct cbc_sbcap_mgr *cbc_sbcap_mgr_create(void *ctx);
|
||||
struct cbc_sbcap_mgr *cbc_sbcap_mgr_alloc(void *ctx);
|
||||
int cbc_sbcap_mgr_open_srv(struct cbc_sbcap_mgr *mgr);
|
||||
|
||||
/* an SBc-AP link with a single (remote) peer connected to us */
|
||||
struct cbc_sbcap_link {
|
||||
|
|
|
@ -54,6 +54,12 @@ struct cbc *cbc_alloc(void *ctx)
|
|||
OSMO_ASSERT(cbc->it_q.rest2main);
|
||||
osmo_fd_register(&cbc->it_q.rest2main->event_ofd);
|
||||
|
||||
cbc->cbsp.mgr = cbc_cbsp_mgr_alloc(cbc);
|
||||
OSMO_ASSERT(cbc->cbsp.mgr);
|
||||
|
||||
cbc->sbcap.mgr = cbc_sbcap_mgr_alloc(cbc);
|
||||
OSMO_ASSERT(cbc->sbcap.mgr);
|
||||
|
||||
return cbc;
|
||||
}
|
||||
|
||||
|
@ -64,14 +70,14 @@ int cbc_start(struct cbc *cbc)
|
|||
|
||||
tall_rest_ctx = talloc_named_const(cbc, 0, "REST");
|
||||
|
||||
if (!(cbc->cbsp.mgr = cbc_cbsp_mgr_create(cbc))) {
|
||||
if ((rc = cbc_cbsp_mgr_open_srv(cbc->cbsp.mgr)) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error binding CBSP port\n");
|
||||
return -EIO;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!(cbc->sbcap.mgr = cbc_sbcap_mgr_create(cbc))) {
|
||||
if ((rc = cbc_sbcap_mgr_open_srv(cbc->sbcap.mgr)) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error binding SBc-AP port\n");
|
||||
return -EIO;
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = rest_api_init(tall_rest_ctx, cbc->config.ecbe.local_host, cbc->config.ecbe.local_port);
|
||||
|
|
|
@ -225,35 +225,44 @@ void cbc_cbsp_link_close(struct cbc_cbsp_link *link)
|
|||
osmo_stream_srv_destroy(link->conn);
|
||||
}
|
||||
|
||||
/* initialize the CBC-side CBSP server */
|
||||
struct cbc_cbsp_mgr *cbc_cbsp_mgr_create(void *ctx)
|
||||
/*
|
||||
* CBSP Manager
|
||||
*/
|
||||
struct cbc_cbsp_mgr *cbc_cbsp_mgr_alloc(void *ctx)
|
||||
{
|
||||
struct cbc_cbsp_mgr *mgr;
|
||||
|
||||
mgr = talloc_zero(ctx, struct cbc_cbsp_mgr);
|
||||
OSMO_ASSERT(mgr);
|
||||
mgr->rx_cb = cbc_cbsp_link_rx_cb;
|
||||
INIT_LLIST_HEAD(&mgr->links);
|
||||
|
||||
return mgr;
|
||||
}
|
||||
|
||||
/* initialize the CBC-side CBSP server */
|
||||
int cbc_cbsp_mgr_open_srv(struct cbc_cbsp_mgr *mgr)
|
||||
{
|
||||
struct cbc_cbsp_mgr *cbc = talloc_zero(ctx, struct cbc_cbsp_mgr);
|
||||
int rc;
|
||||
char *bind_ip = g_cbc->config.cbsp.local_host;
|
||||
int bind_port = g_cbc->config.cbsp.local_port;
|
||||
struct osmo_stream_srv_link *srv_link;
|
||||
int rc;
|
||||
|
||||
if (bind_port == -1)
|
||||
bind_port = CBSP_TCP_PORT;
|
||||
|
||||
OSMO_ASSERT(cbc);
|
||||
cbc->rx_cb = cbc_cbsp_link_rx_cb;
|
||||
INIT_LLIST_HEAD(&cbc->links);
|
||||
cbc->srv_link = osmo_stream_srv_link_create(cbc);
|
||||
osmo_stream_srv_link_set_data(cbc->srv_link, cbc);
|
||||
osmo_stream_srv_link_set_nodelay(cbc->srv_link, true);
|
||||
osmo_stream_srv_link_set_port(cbc->srv_link, bind_port);
|
||||
srv_link = osmo_stream_srv_link_create(mgr);
|
||||
osmo_stream_srv_link_set_data(srv_link, mgr);
|
||||
osmo_stream_srv_link_set_nodelay(srv_link, true);
|
||||
osmo_stream_srv_link_set_port(srv_link, bind_port);
|
||||
if (bind_ip)
|
||||
osmo_stream_srv_link_set_addr(cbc->srv_link, bind_ip);
|
||||
osmo_stream_srv_link_set_accept_cb(cbc->srv_link, cbsp_cbc_accept_cb);
|
||||
rc = osmo_stream_srv_link_open(cbc->srv_link);
|
||||
osmo_stream_srv_link_set_addr(srv_link, bind_ip);
|
||||
osmo_stream_srv_link_set_accept_cb(srv_link, cbsp_cbc_accept_cb);
|
||||
rc = osmo_stream_srv_link_open(srv_link);
|
||||
if (rc < 0) {
|
||||
osmo_stream_srv_link_destroy(cbc->srv_link);
|
||||
talloc_free(cbc);
|
||||
return NULL;
|
||||
osmo_stream_srv_link_destroy(srv_link);
|
||||
talloc_free(mgr);
|
||||
return -EIO;
|
||||
}
|
||||
mgr->srv_link = srv_link;
|
||||
LOGP(DCBSP, LOGL_NOTICE, "Listening for CBSP at %s\n",
|
||||
osmo_stream_srv_link_get_sockname(cbc->srv_link));
|
||||
|
||||
return cbc;
|
||||
osmo_stream_srv_link_get_sockname(mgr->srv_link));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -255,31 +255,46 @@ void cbc_sbcap_link_close(struct cbc_sbcap_link *link)
|
|||
osmo_stream_srv_destroy(link->conn);
|
||||
}
|
||||
|
||||
/* initialize the CBC-side SBc-AP server */
|
||||
struct cbc_sbcap_mgr *cbc_sbcap_mgr_create(void *ctx)
|
||||
/*
|
||||
* CBSP Manager
|
||||
*/
|
||||
struct cbc_sbcap_mgr *cbc_sbcap_mgr_alloc(void *ctx)
|
||||
{
|
||||
struct cbc_sbcap_mgr *cbc = talloc_zero(ctx, struct cbc_sbcap_mgr);
|
||||
int rc;
|
||||
int bind_port = g_cbc->config.sbcap.local_port;
|
||||
struct cbc_sbcap_mgr *mgr;
|
||||
|
||||
if (bind_port == -1)
|
||||
bind_port = SBcAP_SCTP_PORT;
|
||||
mgr = talloc_zero(ctx, struct cbc_sbcap_mgr);
|
||||
OSMO_ASSERT(mgr);
|
||||
mgr->rx_cb = cbc_sbcap_link_rx_cb;
|
||||
INIT_LLIST_HEAD(&mgr->links);
|
||||
|
||||
OSMO_ASSERT(cbc);
|
||||
cbc->rx_cb = cbc_sbcap_link_rx_cb;
|
||||
INIT_LLIST_HEAD(&cbc->links);
|
||||
cbc->srv_link = osmo_stream_srv_link_create(cbc);
|
||||
osmo_stream_srv_link_set_proto(cbc->srv_link, IPPROTO_SCTP);
|
||||
osmo_stream_srv_link_set_data(cbc->srv_link, cbc);
|
||||
osmo_stream_srv_link_set_nodelay(cbc->srv_link, true);
|
||||
osmo_stream_srv_link_set_port(cbc->srv_link, bind_port);
|
||||
osmo_stream_srv_link_set_addrs(cbc->srv_link, (const char **)g_cbc->config.sbcap.local_host,
|
||||
g_cbc->config.sbcap.num_local_host);
|
||||
osmo_stream_srv_link_set_accept_cb(cbc->srv_link, sbcap_cbc_accept_cb);
|
||||
rc = osmo_stream_srv_link_open(cbc->srv_link);
|
||||
OSMO_ASSERT(rc == 0);
|
||||
LOGP(DSBcAP, LOGL_NOTICE, "Listening for SBc-AP at %s\n",
|
||||
osmo_stream_srv_link_get_sockname(cbc->srv_link));
|
||||
|
||||
return cbc;
|
||||
return mgr;
|
||||
}
|
||||
|
||||
/* initialize the CBC-side SBc-AP server */
|
||||
int cbc_sbcap_mgr_open_srv(struct cbc_sbcap_mgr *mgr)
|
||||
{
|
||||
int bind_port = g_cbc->config.sbcap.local_port;
|
||||
struct osmo_stream_srv_link *srv_link;
|
||||
int rc;
|
||||
|
||||
srv_link = osmo_stream_srv_link_create(mgr);
|
||||
osmo_stream_srv_link_set_proto(srv_link, IPPROTO_SCTP);
|
||||
osmo_stream_srv_link_set_data(srv_link, mgr);
|
||||
osmo_stream_srv_link_set_nodelay(srv_link, true);
|
||||
osmo_stream_srv_link_set_port(srv_link, bind_port);
|
||||
osmo_stream_srv_link_set_addrs(srv_link,
|
||||
(const char **)g_cbc->config.sbcap.local_host,
|
||||
g_cbc->config.sbcap.num_local_host);
|
||||
osmo_stream_srv_link_set_accept_cb(srv_link, sbcap_cbc_accept_cb);
|
||||
rc = osmo_stream_srv_link_open(srv_link);
|
||||
if (rc < 0) {
|
||||
osmo_stream_srv_link_destroy(srv_link);
|
||||
talloc_free(mgr);
|
||||
return -EIO;
|
||||
}
|
||||
mgr->srv_link = srv_link;
|
||||
LOGP(DSBcAP, LOGL_NOTICE, "Listening for SBc-AP at %s\n",
|
||||
osmo_stream_srv_link_get_sockname(mgr->srv_link));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue