[PATCH 2/3] libcommon: socket: extend make_sock() prototype

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

pablo at gnumonks.org pablo at gnumonks.org
Tue Apr 5 16:45:18 UTC 2011


From: Pablo Neira Ayuso <pablo at gnumonks.org>

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.
---
 openbsc/include/openbsc/socket.h     |    5 +++--
 openbsc/src/libabis/input/hsl.c      |    4 ++--
 openbsc/src/libabis/input/ipaccess.c |    8 ++++----
 openbsc/src/libcommon/socket.c       |   10 ++++++----
 openbsc/src/libgb/gprs_ns.c          |    2 +-
 openbsc/src/libgb/gprs_ns_frgre.c    |    2 +-
 openbsc/src/osmo-bsc_nat/bsc_ussd.c  |    2 +-
 7 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/openbsc/include/openbsc/socket.h b/openbsc/include/openbsc/socket.h
index faca764..dac4ca7 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 d8f284e..2b9ab1d 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 f074616..ab1d41d 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 42d7b48..5ca7ec9 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 877a065..95e5a55 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 98b1ad6..85019e1 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 0dd0d87..50c50ed 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,
-- 
1.7.2.3





More information about the OpenBSC mailing list