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.orgReview at https://gerrit.osmocom.org/3279 VIRT-PHY: Use new OSMO_SOCK_F_NO_MCAST_{LOOP,ALL} flags libosmocore has recently gained support for flags like OSMO_SOCK_F_NO_MCAST_LOOP and OSMO_SOCK_F_NO_MCAST_ALL that can be passed to the socket initializer functions, further reducing complexity of the code in osmo_mcast_sock.c here. The related change-IDs are I5ab5de45c0b64ceb3636ea98245a23defa24ffd4 and I24a5b1ebc3f84d2d5d4734e54df50efaea26490b in libosmocore.git. Change-Id: I961aa07a381fef2cf9a2fb5357937864364ca04b --- M src/host/virt_phy/src/shared/osmo_mcast_sock.c 1 file changed, 8 insertions(+), 36 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/79/3279/1 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 df3abc3..0521c0d 100644 --- a/src/host/virt_phy/src/shared/osmo_mcast_sock.c +++ b/src/host/virt_phy/src/shared/osmo_mcast_sock.c @@ -28,21 +28,16 @@ uint16_t tx_mcast_port, bool loopback) { int rc; + unsigned int flags = OSMO_SOCK_F_CONNECT; + + if (!loopback) + flags |= OSMO_SOCK_F_NO_MCAST_LOOP; /* setup mcast server socket */ rc = osmo_sock_init_ofd(ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, - tx_mcast_group, tx_mcast_port, OSMO_SOCK_F_CONNECT); + tx_mcast_group, tx_mcast_port, flags); if (rc < 0) { perror("Failed to create Multicast Server Socket"); - return rc; - } - - /* determines whether sent mcast packets should be looped back to the local sockets. - * loopback must be enabled if the mcast client is on the same machine */ - rc = setsockopt(ofd->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loopback, sizeof(loopback)); - if (rc < 0) { - perror("Failed to configure multicast loopback.\n"); - fd_close(ofd); return rc; } @@ -56,8 +51,7 @@ int (*fd_rx_cb)(struct osmo_fd *ofd, unsigned int what), void *osmo_fd_data) { - struct ip_mreq mreq; - int rc, loopback = 1, all = 0; + int rc; ofd->cb = fd_rx_cb; ofd->when = BSC_FD_READ; @@ -65,38 +59,16 @@ /* Create mcast client socket */ rc = osmo_sock_init_ofd(ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, - NULL, mcast_port, OSMO_SOCK_F_BIND); + NULL, mcast_port, OSMO_SOCK_F_BIND|OSMO_SOCK_F_NO_MCAST_ALL); if (rc < 0) { perror("Could not create mcast client socket"); return rc; } - /* Enable loopback of msgs to the host. */ - /* Loopback must be enabled for the client, so multiple - * processes are able to receive a mcast package. */ - rc = setsockopt(ofd->fd, IPPROTO_IP, IP_MULTICAST_LOOP, - &loopback, sizeof(loopback)); - if (rc < 0) { - perror("Failed to enable IP_MULTICAST_LOOP"); - fd_close(ofd); - return rc; - } - /* Configure and join the multicast 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(ofd->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + rc = osmo_sock_mcast_subscribe(ofd->fd, mcast_group); if (rc < 0) { perror("Failed to join to mcast goup"); - fd_close(ofd); - return rc; - } - - /* this option will set the delivery option so that only packets - * from sockets we are subscribed to via IP_ADD_MEMBERSHIP are received */ - if (setsockopt(ofd->fd, IPPROTO_IP, IP_MULTICAST_ALL, &all, sizeof(all)) < 0) { - perror("Failed to modify delivery policy to explicitly joined.\n"); fd_close(ofd); return rc; } -- To view, visit https://gerrit.osmocom.org/3279 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I961aa07a381fef2cf9a2fb5357937864364ca04b Gerrit-PatchSet: 1 Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org>