diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-07-13 13:58:28 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-07-13 13:58:28 +0200 |
commit | 91a0c20bb3cc483b099e788fd2f87ae1947d51b2 (patch) | |
tree | 1f6ffb1b24fdbcc3829ef234d6dbfbf51700d922 | |
parent | dd94566f7b69cf5b18f5e82ea66059aab76f7891 (diff) |
VIRT-PHY: mcast_sock: Don't keep subscribed multicast group around
We can avoid having to keep around the multicast group in a chunk of
dynamically allocated memory and simplify related code.
Change-Id: Ic39ffe73dfd2cb8ffefb9614340e275dac87bd50
-rw-r--r-- | src/host/virt_phy/include/virtphy/osmo_mcast_sock.h | 1 | ||||
-rw-r--r-- | src/host/virt_phy/src/shared/osmo_mcast_sock.c | 17 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/host/virt_phy/include/virtphy/osmo_mcast_sock.h b/src/host/virt_phy/include/virtphy/osmo_mcast_sock.h index 3c5954d8..ba5237a0 100644 --- a/src/host/virt_phy/include/virtphy/osmo_mcast_sock.h +++ b/src/host/virt_phy/include/virtphy/osmo_mcast_sock.h @@ -9,7 +9,6 @@ struct mcast_server_sock { struct mcast_client_sock { struct osmo_fd osmo_fd; - struct ip_mreq *mcast_group; }; struct mcast_bidir_sock { diff --git a/src/host/virt_phy/src/shared/osmo_mcast_sock.c b/src/host/virt_phy/src/shared/osmo_mcast_sock.c index a06d7069..b42a5e46 100644 --- a/src/host/virt_phy/src/shared/osmo_mcast_sock.c +++ b/src/host/virt_phy/src/shared/osmo_mcast_sock.c @@ -47,11 +47,9 @@ mcast_client_sock_setup(void *ctx, char* mcast_group, int mcast_port, void *osmo_fd_data) { struct mcast_client_sock *client_sock = talloc_zero(ctx, struct mcast_client_sock); + struct ip_mreq mreq; int rc, loopback = 1, all = 0; - /* TODO: why allocate those dynamically ?!? */ - client_sock->mcast_group = talloc_zero(client_sock, struct ip_mreq); - client_sock->osmo_fd.cb = fd_rx_cb; client_sock->osmo_fd.when = BSC_FD_READ; client_sock->osmo_fd.data = osmo_fd_data; @@ -75,10 +73,10 @@ mcast_client_sock_setup(void *ctx, char* mcast_group, int mcast_port, } /* Configure and join the multicast group */ - client_sock->mcast_group->imr_multiaddr.s_addr = inet_addr(mcast_group); - client_sock->mcast_group->imr_interface.s_addr = htonl(INADDR_ANY); - rc = setsockopt(client_sock->osmo_fd.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - client_sock->mcast_group, sizeof(*client_sock->mcast_group)); + memset(&mreq, 0, sizeof(mreq)); + mreq.imr_multiaddr.s_addr = inet_addr(mcast_group); + mreq.imr_interface.s_addr = htonl(INADDR_ANY); + rc = setsockopt(client_sock->osmo_fd.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (rc < 0) { perror("Failed to join to mcast goup"); return NULL; @@ -137,13 +135,12 @@ int mcast_bidir_sock_rx(struct mcast_bidir_sock *bidir_sock, void* buf, int buf_ void mcast_client_sock_close(struct mcast_client_sock *client_sock) { - setsockopt(client_sock->osmo_fd.fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, - client_sock->mcast_group, sizeof(*client_sock->mcast_group)); + /* multicast memberships of socket are implicitly dropped when + * socket is closed */ osmo_fd_unregister(&client_sock->osmo_fd); client_sock->osmo_fd.fd = -1; client_sock->osmo_fd.when = 0; close(client_sock->osmo_fd.fd); - talloc_free(client_sock->mcast_group); talloc_free(client_sock); } |