summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2011-04-05 18:33:24 +0200
committerPablo Neira Ayuso <pablo@gnumonks.org>2011-04-05 18:33:24 +0200
commit165fe562608cc9691b9f4da449b4977c68dc32a4 (patch)
treecd32c841fdcb15a00c4e933768cfd034d921f943
parentf22e348287409d2ec63b0f21e2baa88a248be678 (diff)
libcommon: socket: extend make_sock() prototype
This patch extends the make_sock() prototype so you can fully set the fields priv_nr and data of the bsc_fd structure. This is the first step to get rid of the internal make_sock() implementation that ipaccess-proxy uses. This patch includes a minor cleanup to pass INADDR_ANY instead of zero, if you do not want to bind the socket to one specific address.
-rw-r--r--openbsc/include/openbsc/socket.h5
-rw-r--r--openbsc/src/libabis/input/hsl.c4
-rw-r--r--openbsc/src/libabis/input/ipaccess.c8
-rw-r--r--openbsc/src/libcommon/socket.c10
-rw-r--r--openbsc/src/libgb/gprs_ns.c2
-rw-r--r--openbsc/src/libgb/gprs_ns_frgre.c2
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_ussd.c2
7 files changed, 18 insertions, 15 deletions
diff --git a/openbsc/include/openbsc/socket.h b/openbsc/include/openbsc/socket.h
index faca7647b..dac4ca7ae 100644
--- a/openbsc/include/openbsc/socket.h
+++ b/openbsc/include/openbsc/socket.h
@@ -8,7 +8,8 @@
#define IPPROTO_GRE 47
#endif
-int make_sock(struct bsc_fd *bfd, int proto, u_int32_t ip, u_int16_t port,
- int (*cb)(struct bsc_fd *fd, unsigned int what));
+int make_sock(struct bsc_fd *bfd, int proto,
+ u_int32_t ip, u_int16_t port, int priv_nr,
+ int (*cb)(struct bsc_fd *fd, unsigned int what), void *data);
#endif /* _BSC_SOCKET_H */
diff --git a/openbsc/src/libabis/input/hsl.c b/openbsc/src/libabis/input/hsl.c
index d8f284e3f..2b9ab1d1e 100644
--- a/openbsc/src/libabis/input/hsl.c
+++ b/openbsc/src/libabis/input/hsl.c
@@ -451,8 +451,8 @@ int hsl_setup(struct gsm_network *gsmnet)
e1h->gsmnet = gsmnet;
/* Listen for connections */
- ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, 0, HSL_TCP_PORT,
- listen_fd_cb);
+ ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY, HSL_TCP_PORT,
+ 0, listen_fd_cb, NULL);
if (ret < 0)
return ret;
diff --git a/openbsc/src/libabis/input/ipaccess.c b/openbsc/src/libabis/input/ipaccess.c
index f0746161a..ab1d41d8b 100644
--- a/openbsc/src/libabis/input/ipaccess.c
+++ b/openbsc/src/libabis/input/ipaccess.c
@@ -782,14 +782,14 @@ int ipaccess_setup(struct gsm_network *gsmnet)
e1h->gsmnet = gsmnet;
/* Listen for OML connections */
- ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, 0, IPA_TCP_PORT_OML,
- listen_fd_cb);
+ ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY,
+ IPA_TCP_PORT_OML, 0, listen_fd_cb, NULL);
if (ret < 0)
return ret;
/* Listen for RSL connections */
- ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, 0,
- IPA_TCP_PORT_RSL, rsl_listen_fd_cb);
+ ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, INADDR_ANY,
+ IPA_TCP_PORT_RSL, 0, rsl_listen_fd_cb, NULL);
if (ret < 0)
return ret;
diff --git a/openbsc/src/libcommon/socket.c b/openbsc/src/libcommon/socket.c
index 42d7b48d9..5ca7ec90f 100644
--- a/openbsc/src/libcommon/socket.c
+++ b/openbsc/src/libcommon/socket.c
@@ -40,8 +40,9 @@
#include <openbsc/gsm_data.h>
#include <osmocom/core/talloc.h>
-int make_sock(struct bsc_fd *bfd, int proto, u_int32_t ip, u_int16_t port,
- int (*cb)(struct bsc_fd *fd, unsigned int what))
+int make_sock(struct bsc_fd *bfd, int proto,
+ u_int32_t ip, u_int16_t port, int priv_nr,
+ int (*cb)(struct bsc_fd *fd, unsigned int what), void *data)
{
struct sockaddr_in addr;
int ret, on = 1;
@@ -64,7 +65,8 @@ int make_sock(struct bsc_fd *bfd, int proto, u_int32_t ip, u_int16_t port,
bfd->fd = socket(AF_INET, type, proto);
bfd->cb = cb;
bfd->when = BSC_FD_READ;
- //bfd->data = line;
+ bfd->data = data;
+ bfd->priv_nr = priv_nr;
if (bfd->fd < 0) {
LOGP(DINP, LOGL_ERROR, "could not create socket.\n");
@@ -74,7 +76,7 @@ int make_sock(struct bsc_fd *bfd, int proto, u_int32_t ip, u_int16_t port,
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- if (ip)
+ if (ip != INADDR_ANY)
addr.sin_addr.s_addr = htonl(ip);
else
addr.sin_addr.s_addr = INADDR_ANY;
diff --git a/openbsc/src/libgb/gprs_ns.c b/openbsc/src/libgb/gprs_ns.c
index 877a06545..95e5a55d7 100644
--- a/openbsc/src/libgb/gprs_ns.c
+++ b/openbsc/src/libgb/gprs_ns.c
@@ -946,7 +946,7 @@ int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi)
int ret;
ret = make_sock(&nsi->nsip.fd, IPPROTO_UDP, nsi->nsip.local_ip,
- nsi->nsip.local_port, nsip_fd_cb);
+ nsi->nsip.local_port, 0, nsip_fd_cb, NULL);
if (ret < 0)
return ret;
diff --git a/openbsc/src/libgb/gprs_ns_frgre.c b/openbsc/src/libgb/gprs_ns_frgre.c
index 98b1ad602..85019e1a4 100644
--- a/openbsc/src/libgb/gprs_ns_frgre.c
+++ b/openbsc/src/libgb/gprs_ns_frgre.c
@@ -292,7 +292,7 @@ int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi)
return 0;
rc = make_sock(&nsi->frgre.fd, IPPROTO_GRE, nsi->frgre.local_ip,
- 0, nsfrgre_fd_cb);
+ 0, 0, nsfrgre_fd_cb, NULL);
if (rc < 0) {
LOGP(DNS, LOGL_ERROR, "Error creating GRE socket (%s)\n",
strerror(errno));
diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
index 0dd0d8731..50c50ed1f 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
@@ -251,7 +251,7 @@ int bsc_ussd_init(struct bsc_nat *nat)
nat->ussd_listen.data = nat;
return make_sock(&nat->ussd_listen, IPPROTO_TCP,
- ntohl(addr.s_addr), 5001, ussd_listen_cb);
+ ntohl(addr.s_addr), 5001, 0, ussd_listen_cb, NULL);
}
static int forward_ussd(struct sccp_connections *con, const struct ussd_request *req,