summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso2011-06-07 11:25:49 +0200
committerPablo Neira Ayuso2011-06-07 11:25:49 +0200
commitf67471fb7f691cfe19622693c2bd59a6b9837cd4 (patch)
tree7734d43644834012d973e738be59f9b77778b6f1
parentmissing logging header in trau_frame.c (diff)
downloadlibosmo-abis-f67471fb7f691cfe19622693c2bd59a6b9837cd4.tar.gz
libosmo-abis-f67471fb7f691cfe19622693c2bd59a6b9837cd4.tar.xz
libosmo-abis-f67471fb7f691cfe19622693c2bd59a6b9837cd4.zip
src: use new socket API in libosmocore
get rid of internal copy of openbsc/libcommon/socket.c, we now use the new socket API available in libosmocore.
-rw-r--r--src/Makefile.am3
-rw-r--r--src/input/hsl.c17
-rw-r--r--src/input/ipaccess.c28
-rw-r--r--src/socket.c109
4 files changed, 40 insertions, 117 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 292d01e..ce053cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,5 +13,4 @@ lib_LTLIBRARIES = libosmoabis.la
libosmoabis_la_LIBADD = input/libosmoabis-input.la
libosmoabis_la_SOURCES = e1_input.c \
subchan_demux.c \
- trau_frame.c \
- socket.c
+ trau_frame.c
diff --git a/src/input/hsl.c b/src/input/hsl.c
index 2ff9d39..211768c 100644
--- a/src/input/hsl.c
+++ b/src/input/hsl.c
@@ -50,6 +50,7 @@
#include <osmocom/gsm/abis/e1_input.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsm/protocol/ipaccess.h>
+#include <osmocom/core/socket.h>
/*#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/abis_nm.h>
@@ -268,8 +269,20 @@ hsl_line_update(struct e1inp_line *line, enum e1inp_line_role role)
switch(role) {
case E1INP_LINE_R_BSC:
- ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY,
- HSL_TCP_PORT, 0, listen_fd_cb, line);
+ ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
+ "0.0.0.0", HSL_TCP_PORT, 1);
+ if (ret < 0)
+ return ret;
+
+ e1h->listen_fd.fd = ret;
+ e1h->listen_fd.when |= BSC_FD_READ;
+ e1h->listen_fd.cb = listen_fd_cb;
+ e1h->listen_fd.data = line;
+
+ if (osmo_fd_register(&e1h->listen_fd) < 0) {
+ close(ret);
+ return ret;
+ }
break;
case E1INP_LINE_R_BTS:
/* XXX: not implemented yet. */
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index 5777d56..9894920 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -41,6 +41,7 @@
#include <talloc.h>
#include <osmocom/gsm/abis/e1_input.h>
#include <osmocom/gsm/abis/ipaccess.h>
+#include <osmocom/core/socket.h>
/*#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/abis_nm.h>
@@ -424,16 +425,35 @@ ipaccess_line_update(struct e1inp_line *line, enum e1inp_line_role role)
switch(role) {
case E1INP_LINE_R_BSC:
/* Listen for OML connections */
- ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY,
- IPA_TCP_PORT_OML, 0, listen_fd_cb, line);
+ ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
+ "0.0.0.0", IPA_TCP_PORT_OML, 1);
if (ret < 0)
return ret;
+ e1h->listen_fd.fd = ret;
+ e1h->listen_fd.when |= BSC_FD_READ;
+ e1h->listen_fd.cb = listen_fd_cb;
+ e1h->listen_fd.data = line;
+
+ if (osmo_fd_register(&e1h->listen_fd) < 0) {
+ close(ret);
+ return ret;
+ }
/* Listen for RSL connections */
- ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, INADDR_ANY,
- IPA_TCP_PORT_RSL, 0, rsl_listen_fd_cb, NULL);
+ ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
+ "0.0.0.0", IPA_TCP_PORT_RSL, 1);
if (ret < 0)
return ret;
+
+ e1h->rsl_listen_fd.fd = ret;
+ e1h->rsl_listen_fd.when |= BSC_FD_READ;
+ e1h->rsl_listen_fd.cb = rsl_listen_fd_cb;
+ e1h->rsl_listen_fd.data = NULL;
+
+ if (osmo_fd_register(&e1h->rsl_listen_fd) < 0) {
+ close(ret);
+ return ret;
+ }
break;
case E1INP_LINE_R_BTS:
/* XXX: no implemented yet. */
diff --git a/src/socket.c b/src/socket.c
deleted file mode 100644
index f0f8fe3..0000000
--- a/src/socket.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* OpenBSC sokcet code, taken from Abis input driver for ip.access */
-
-/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
- * (C) 2010 by Holger Hans Peter Freyther
- * (C) 2010 by On-Waves
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "internal.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <sys/fcntl.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <arpa/inet.h>
-
-#include <osmocom/core/select.h>
-#include <osmocom/core/msgb.h>
-#include <osmocom/core/logging.h>
-#include <talloc.h>
-
-int make_sock(struct osmo_fd *bfd, int proto,
- uint32_t ip, uint16_t port, int priv_nr,
- int (*cb)(struct osmo_fd *fd, unsigned int what), void *data)
-{
- struct sockaddr_in addr;
- int ret, on = 1;
- int type = SOCK_STREAM;
-
- switch (proto) {
- case IPPROTO_TCP:
- type = SOCK_STREAM;
- break;
- case IPPROTO_UDP:
- type = SOCK_DGRAM;
- break;
- case IPPROTO_GRE:
- type = SOCK_RAW;
- break;
- default:
- return -EINVAL;
- }
-
- bfd->fd = socket(AF_INET, type, proto);
- bfd->cb = cb;
- bfd->when = BSC_FD_READ;
- bfd->data = data;
- bfd->priv_nr = priv_nr;
-
- if (bfd->fd < 0) {
- LOGP(DINP, LOGL_ERROR, "could not create socket.\n");
- return -EIO;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- if (ip != INADDR_ANY)
- addr.sin_addr.s_addr = htonl(ip);
- else
- addr.sin_addr.s_addr = INADDR_ANY;
-
- setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-
- ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
- if (ret < 0) {
- LOGP(DINP, LOGL_ERROR, "could not bind socket %s\n",
- strerror(errno));
- close(bfd->fd);
- return -EIO;
- }
-
- if (proto == IPPROTO_TCP) {
- ret = listen(bfd->fd, 1);
- if (ret < 0) {
- perror("listen");
- close(bfd->fd);
- return ret;
- }
- }
-
- ret = osmo_fd_register(bfd);
- if (ret < 0) {
- perror("register_listen_fd");
- close(bfd->fd);
- return ret;
- }
- return 0;
-}