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/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. Change subject: VIRT-PHY: mcast_sock: Don't keep subscribed multicast group around ...................................................................... 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 --- M src/host/virt_phy/include/virtphy/osmo_mcast_sock.h M src/host/virt_phy/src/shared/osmo_mcast_sock.c 2 files changed, 7 insertions(+), 11 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified 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 3c5954d..ba5237a 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_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 a06d706..b42a5e4 100644 --- a/src/host/virt_phy/src/shared/osmo_mcast_sock.c +++ b/src/host/virt_phy/src/shared/osmo_mcast_sock.c @@ -47,10 +47,8 @@ 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; @@ -75,10 +73,10 @@ } /* 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 @@ 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); } -- To view, visit https://gerrit.osmocom.org/3233 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic39ffe73dfd2cb8ffefb9614340e275dac87bd50 Gerrit-PatchSet: 1 Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder