aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-01-20 12:43:45 +0100
committerMax <msuraev@sysmocom.de>2019-01-24 17:22:52 +0000
commit480073a6604af75d939efc25b30e527f71cb9f6c (patch)
tree01e1c2cd713f850e490ff030e7bb581f81c0c399
parent176a1fbab6ae45eb1c60e3d8b263b0765759e1da (diff)
Set local IP in ipa_server_link properly
When creating IPA link for server we might be called without explicit address (which is legit - it means bind to all available addresses). However in this case we won't have 'addr' field of ipa_server_link initialized properly. Fix this by following changes: * don't copy NULL value as address * use socket's local IP when no address set explicitly Change-Id: I33679bb35f426d4cafb223b9200fccbf407e0cf6
-rw-r--r--src/input/ipa.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/input/ipa.c b/src/input/ipa.c
index 09e3426..9853ffa 100644
--- a/src/input/ipa.c
+++ b/src/input/ipa.c
@@ -248,6 +248,7 @@ size_t ipa_client_conn_clear_queue(struct ipa_client_conn *link)
static int ipa_server_fd_cb(struct osmo_fd *ofd, unsigned int what)
{
int fd, ret;
+ char ipbuf[INET6_ADDRSTRLEN + 1];
struct sockaddr_in sa;
socklen_t sa_len = sizeof(sa);
struct ipa_server_link *link = ofd->data;
@@ -258,6 +259,13 @@ static int ipa_server_fd_cb(struct osmo_fd *ofd, unsigned int what)
"peer, reason=`%s'\n", strerror(errno));
return fd;
}
+
+ if (!link->addr) {
+ ret = osmo_sock_get_local_ip(fd, ipbuf, INET6_ADDRSTRLEN + 1);
+ if (ret == 0)
+ link->addr = talloc_strdup(link, ipbuf);
+ }
+
LOGP(DLINP, LOGL_NOTICE, "accept()ed new link from %s to port %u\n",
inet_ntoa(sa.sin_addr), link->port);
@@ -290,7 +298,8 @@ ipa_server_link_create(void *ctx, struct e1inp_line *line,
ipa_link->ofd.when |= BSC_FD_READ | BSC_FD_WRITE;
ipa_link->ofd.cb = ipa_server_fd_cb;
ipa_link->ofd.data = ipa_link;
- ipa_link->addr = talloc_strdup(ipa_link, addr);
+ if (addr)
+ ipa_link->addr = talloc_strdup(ipa_link, addr);
ipa_link->port = port;
ipa_link->accept_cb = accept_cb;
ipa_link->line = line;