aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-10-18 22:19:28 +0200
committerHarald Welte <laforge@osmocom.org>2020-10-19 12:05:17 +0200
commit806e7a37ddabd87b637b9151415f3f7375504e64 (patch)
treea725985a9436afc34fb9dca436cf92d6390f4a41
parent218b3753f1cf65fb89b85da8aa0fa57b1661f3c1 (diff)
use osmo_fd_setup() whenever applicableHEADmaster
-rw-r--r--src/ipaccess/abisip-find.c7
-rw-r--r--src/ipaccess/ipaccess-proxy.c19
-rw-r--r--src/osmo-bsc/bsc_rf_ctrl.c8
-rw-r--r--src/osmo-bsc/pcu_sock.c14
4 files changed, 15 insertions, 33 deletions
diff --git a/src/ipaccess/abisip-find.c b/src/ipaccess/abisip-find.c
index 11b2851ae..a414d1615 100644
--- a/src/ipaccess/abisip-find.c
+++ b/src/ipaccess/abisip-find.c
@@ -446,13 +446,12 @@ int main(int argc, char **argv)
else if (cmdline_opts.send_interval >= cmdline_opts.list_view_timeout)
fprintf(stdout, "\nWARNING: the --timeout should be larger than --interval.\n\n");
- bfd.cb = bfd_cb;
- bfd.when = OSMO_FD_READ | OSMO_FD_WRITE;
- bfd.fd = udp_sock(cmdline_opts.ifname, cmdline_opts.bind_ip);
- if (bfd.fd < 0) {
+ rc = udp_sock(cmdline_opts.ifname, cmdline_opts.bind_ip);
+ if (rc < 0) {
perror("Cannot create local socket for broadcast udp");
exit(1);
}
+ osmo_fd_setup(&bfd, rc, OSMO_FD_READ | OSMO_FD_WRITE, bfd_cb, NULL, 0);
rc = osmo_fd_register(&bfd);
if (rc < 0) {
diff --git a/src/ipaccess/ipaccess-proxy.c b/src/ipaccess/ipaccess-proxy.c
index d5dd8d4d5..1ed215db9 100644
--- a/src/ipaccess/ipaccess-proxy.c
+++ b/src/ipaccess/ipaccess-proxy.c
@@ -936,11 +936,7 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
}
bfd = &ipc->fd;
- bfd->fd = ret;
- bfd->data = ipc;
- bfd->priv_nr = listen_bfd->priv_nr;
- bfd->cb = proxy_ipaccess_fd_cb;
- bfd->when = OSMO_FD_READ;
+ osmo_fd_setup(bfd, ret, OSMO_FD_READ, proxy_ipaccess_fd_cb, ipc, listen_bfd->priv_nr);
ret = osmo_fd_register(bfd);
if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
@@ -1016,20 +1012,17 @@ static struct ipa_proxy_conn *connect_bsc(struct sockaddr_in *sa, int priv_nr, v
ipc->bts_conn = data;
- bfd = &ipc->fd;
- bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- bfd->cb = ipaccess_fd_cb;
- bfd->when = OSMO_FD_READ | OSMO_FD_WRITE;
- bfd->data = ipc;
- bfd->priv_nr = priv_nr;
-
- if (bfd->fd < 0) {
+ ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "Could not create socket: %s\n",
strerror(errno));
talloc_free(ipc);
return NULL;
}
+ bfd = &ipc->fd;
+ osmo_fd_setup(bfd, ret, OSMO_FD_READ | OSMO_FD_WRITE, ipaccess_fd_cb, ipc, priv_nr);
+
ret = setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "Could not set socket option\n");
diff --git a/src/osmo-bsc/bsc_rf_ctrl.c b/src/osmo-bsc/bsc_rf_ctrl.c
index 1e04f21c3..a845859be 100644
--- a/src/osmo-bsc/bsc_rf_ctrl.c
+++ b/src/osmo-bsc/bsc_rf_ctrl.c
@@ -372,9 +372,7 @@ static int rf_ctrl_accept(struct osmo_fd *bfd, unsigned int what)
}
osmo_wqueue_init(&conn->queue, 10);
- conn->queue.bfd.data = conn;
- conn->queue.bfd.fd = fd;
- conn->queue.bfd.when = OSMO_FD_READ | OSMO_FD_WRITE;
+ osmo_fd_setup(&conn->queue.bfd, fd, OSMO_FD_READ | OSMO_FD_WRITE, osmo_wqueue_bfd_cb, conn, 0);
conn->queue.read_cb = rf_read_cmd;
conn->queue.write_cb = rf_write_cmd;
conn->rf = rf;
@@ -484,9 +482,7 @@ static int rf_create_socket(struct osmo_bsc_rf *rf, const char *path)
return -1;
}
- bfd->when = OSMO_FD_READ;
- bfd->cb = rf_ctrl_accept;
- bfd->data = rf;
+ osmo_fd_setup(bfd, bfd->fd, OSMO_FD_READ, rf_ctrl_accept, rf, 0);
if (osmo_fd_register(bfd) != 0) {
LOGP(DLINP, LOGL_ERROR, "Failed to register bfd.\n");
diff --git a/src/osmo-bsc/pcu_sock.c b/src/osmo-bsc/pcu_sock.c
index a1a1cfc18..d59df33bb 100644
--- a/src/osmo-bsc/pcu_sock.c
+++ b/src/osmo-bsc/pcu_sock.c
@@ -672,10 +672,7 @@ static int pcu_sock_accept(struct osmo_fd *bfd, unsigned int flags)
return 0;
}
- conn_bfd->fd = rc;
- conn_bfd->when = OSMO_FD_READ;
- conn_bfd->cb = pcu_sock_cb;
- conn_bfd->data = state;
+ osmo_fd_setup(conn_bfd, rc, OSMO_FD_READ, pcu_sock_cb, state, 0);
if (osmo_fd_register(conn_bfd) != 0) {
LOGP(DPCU, LOGL_ERROR, "Failed to register new connection "
@@ -707,18 +704,15 @@ int pcu_sock_init(const char *path, struct gsm_bts *bts)
bfd = &state->listen_bfd;
- bfd->fd = osmo_sock_unix_init(SOCK_SEQPACKET, 0, path,
- OSMO_SOCK_F_BIND);
- if (bfd->fd < 0) {
+ rc = osmo_sock_unix_init(SOCK_SEQPACKET, 0, path, OSMO_SOCK_F_BIND);
+ if (rc < 0) {
LOGP(DPCU, LOGL_ERROR, "Could not create unix socket: %s\n",
strerror(errno));
talloc_free(state);
return -1;
}
- bfd->when = OSMO_FD_READ;
- bfd->cb = pcu_sock_accept;
- bfd->data = state;
+ osmo_fd_setup(bfd, rc, OSMO_FD_READ, pcu_sock_accept, state, 0);
rc = osmo_fd_register(bfd);
if (rc < 0) {