aboutsummaryrefslogtreecommitdiffstats
path: root/src/libbsc/bsc_msc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libbsc/bsc_msc.c')
-rw-r--r--src/libbsc/bsc_msc.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/src/libbsc/bsc_msc.c b/src/libbsc/bsc_msc.c
index 508697ab..e9ffce39 100644
--- a/src/libbsc/bsc_msc.c
+++ b/src/libbsc/bsc_msc.c
@@ -23,8 +23,8 @@
#include <openbsc/debug.h>
#include <openbsc/ipaccess.h>
-#include <osmocore/write_queue.h>
-#include <osmocore/talloc.h>
+#include <osmocom/core/write_queue.h>
+#include <osmocom/core/talloc.h>
#include <arpa/inet.h>
#include <sys/socket.h>
@@ -36,13 +36,13 @@
static void connection_loss(struct bsc_msc_connection *con)
{
- struct bsc_fd *fd;
+ struct osmo_fd *fd;
fd = &con->write_queue.bfd;
close(fd->fd);
fd->fd = -1;
- fd->cb = write_queue_bfd_cb;
+ fd->cb = osmo_wqueue_bfd_cb;
fd->when = 0;
con->is_connected = 0;
@@ -59,12 +59,12 @@ static void msc_con_timeout(void *_con)
}
/* called in the case of a non blocking connect */
-static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
+static int msc_connection_connect(struct osmo_fd *fd, unsigned int what)
{
int rc;
int val;
struct bsc_msc_connection *con;
- struct write_queue *queue;
+ struct osmo_wqueue *queue;
socklen_t len = sizeof(val);
@@ -73,11 +73,11 @@ static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
return -1;
}
- queue = container_of(fd, struct write_queue, bfd);
+ queue = container_of(fd, struct osmo_wqueue, bfd);
con = container_of(queue, struct bsc_msc_connection, write_queue);
/* From here on we will either be connected or reconnect */
- bsc_del_timer(&con->timeout_timer);
+ osmo_timer_del(&con->timeout_timer);
/* check the socket state */
rc = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &val, &len);
@@ -92,7 +92,7 @@ static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
/* go to full operation */
- fd->cb = write_queue_bfd_cb;
+ fd->cb = osmo_wqueue_bfd_cb;
fd->when = BSC_FD_READ | BSC_FD_EXCEPT;
con->is_connected = 1;
@@ -102,11 +102,11 @@ static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
return 0;
error:
- bsc_unregister_fd(fd);
+ osmo_fd_unregister(fd);
connection_loss(con);
return -1;
}
-static void setnonblocking(struct bsc_fd *fd)
+static void setnonblocking(struct osmo_fd *fd)
{
int flags;
@@ -130,11 +130,24 @@ static void setnonblocking(struct bsc_fd *fd)
int bsc_msc_connect(struct bsc_msc_connection *con)
{
- struct bsc_fd *fd;
+ struct bsc_msc_dest *dest;
+ struct osmo_fd *fd;
struct sockaddr_in sin;
int on = 1, ret;
- LOGP(DMSC, LOGL_NOTICE, "Attempting to connect MSC at %s:%d\n", con->ip, con->port);
+ if (llist_empty(con->dests)) {
+ LOGP(DMSC, LOGL_ERROR, "No MSC connections configured.\n");
+ connection_loss(con);
+ return -1;
+ }
+
+ /* move to the next connection */
+ dest = (struct bsc_msc_dest *) con->dests->next;
+ llist_del(&dest->list);
+ llist_add_tail(&dest->list, con->dests);
+
+ LOGP(DMSC, LOGL_NOTICE, "Attempting to connect MSC at %s:%d\n",
+ dest->ip, dest->port);
con->is_connected = 0;
@@ -152,15 +165,15 @@ int bsc_msc_connect(struct bsc_msc_connection *con)
/* set the socket priority */
ret = setsockopt(fd->fd, IPPROTO_IP, IP_TOS,
- &con->prio, sizeof(con->prio));
+ &dest->dscp, sizeof(dest->dscp));
if (ret != 0)
- LOGP(DMSC, LOGL_ERROR, "Failed to set prio to %d. %s\n",
- con->prio, strerror(errno));
+ LOGP(DMSC, LOGL_ERROR, "Failed to set DSCP to %d. %s\n",
+ dest->dscp, strerror(errno));
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
- sin.sin_port = htons(con->port);
- inet_aton(con->ip, &sin.sin_addr);
+ sin.sin_port = htons(dest->port);
+ inet_aton(dest->ip, &sin.sin_addr);
setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin));
@@ -171,20 +184,20 @@ int bsc_msc_connect(struct bsc_msc_connection *con)
fd->cb = msc_connection_connect;
con->timeout_timer.cb = msc_con_timeout;
con->timeout_timer.data = con;
- bsc_schedule_timer(&con->timeout_timer, 20, 0);
+ osmo_timer_schedule(&con->timeout_timer, 20, 0);
} else if (ret < 0) {
perror("Connection failed");
connection_loss(con);
return ret;
} else {
fd->when = BSC_FD_READ | BSC_FD_EXCEPT;
- fd->cb = write_queue_bfd_cb;
+ fd->cb = osmo_wqueue_bfd_cb;
con->is_connected = 1;
if (con->connected)
con->connected(con);
}
- ret = bsc_register_fd(fd);
+ ret = osmo_fd_register(fd);
if (ret < 0) {
perror("Registering the fd failed");
close(fd->fd);
@@ -194,7 +207,7 @@ int bsc_msc_connect(struct bsc_msc_connection *con)
return ret;
}
-struct bsc_msc_connection *bsc_msc_create(const char *ip, int port, int prio)
+struct bsc_msc_connection *bsc_msc_create(void *ctx, struct llist_head *dests)
{
struct bsc_msc_connection *con;
@@ -204,20 +217,19 @@ struct bsc_msc_connection *bsc_msc_create(const char *ip, int port, int prio)
return NULL;
}
- con->ip = ip;
- con->port = port;
- con->prio = prio;
- write_queue_init(&con->write_queue, 100);
+ con->dests = dests;
+ con->write_queue.bfd.fd = -1;
+ osmo_wqueue_init(&con->write_queue, 100);
return con;
}
void bsc_msc_lost(struct bsc_msc_connection *con)
{
- write_queue_clear(&con->write_queue);
- bsc_del_timer(&con->timeout_timer);
+ osmo_wqueue_clear(&con->write_queue);
+ osmo_timer_del(&con->timeout_timer);
if (con->write_queue.bfd.fd >= 0)
- bsc_unregister_fd(&con->write_queue.bfd);
+ osmo_fd_unregister(&con->write_queue.bfd);
connection_loss(con);
}
@@ -234,7 +246,7 @@ void bsc_msc_schedule_connect(struct bsc_msc_connection *con)
LOGP(DMSC, LOGL_NOTICE, "Attempting to reconnect to the MSC.\n");
con->reconnect_timer.cb = reconnect_msc;
con->reconnect_timer.data = con;
- bsc_schedule_timer(&con->reconnect_timer, 5, 0);
+ osmo_timer_schedule(&con->reconnect_timer, 5, 0);
}
struct msgb *bsc_msc_id_get_resp(const char *token)
@@ -254,6 +266,6 @@ struct msgb *bsc_msc_id_get_resp(const char *token)
msg->l2h = msgb_v_put(msg, IPAC_MSGT_ID_RESP);
msgb_l16tv_put(msg, strlen(token) + 1,
- IPAC_IDTAG_UNITNAME, (u_int8_t *) token);
+ IPAC_IDTAG_UNITNAME, (uint8_t *) token);
return msg;
}