aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libbsc/bsc_msc.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-04-23 23:31:31 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-04-26 09:36:19 +0200
commite188010512388acdb1408f3d1a0749c25c2c99e3 (patch)
tree5df9a436d79f1bf3674a0316474af66aa9a26d9c /openbsc/src/libbsc/bsc_msc.c
parent2a9eeaa588a2a3b63fadd94d6760879b44b14af5 (diff)
bsc: Allow to have a list of MSCs/MUXs to connect to
Be able to configure a list of destinations (duplicates allowed) that will be tried in a round robin fashion. The change is in the bsc_msc_connection to operate on a list. We achieve the round robin nature with the same trick used in the paging code to delete and append the current entry. The nat code was updated to compile but one can only configure one destination.
Diffstat (limited to 'openbsc/src/libbsc/bsc_msc.c')
-rw-r--r--openbsc/src/libbsc/bsc_msc.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/openbsc/src/libbsc/bsc_msc.c b/openbsc/src/libbsc/bsc_msc.c
index aa084b83e..8eef6f4e6 100644
--- a/openbsc/src/libbsc/bsc_msc.c
+++ b/openbsc/src/libbsc/bsc_msc.c
@@ -130,11 +130,24 @@ static void setnonblocking(struct bsc_fd *fd)
int bsc_msc_connect(struct bsc_msc_connection *con)
{
+ struct bsc_msc_dest *dest;
struct bsc_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));
@@ -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,9 +217,8 @@ 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;
+ con->dests = dests;
+ con->write_queue.bfd.fd = -1;
write_queue_init(&con->write_queue, 100);
return con;
}