Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change the UDP multicast to a administratively scoped range #4314

Closed
wants to merge 1 commit into from

Conversation

juanarbol
Copy link
Contributor

@juanarbol juanarbol commented Feb 13, 2024

Fixes: #4263

@juanarbol juanarbol changed the title darwin: WIP change subnet in multicast join test: change the UDP multicast to a administratively scoped range Apr 25, 2024
@juanarbol
Copy link
Contributor Author

juanarbol commented Apr 25, 2024

After a lot of pain and horrible macOS documentation, I did not found the actual reason, but I created a a minimal repro case for this issue, and it is persistent, even without libuv.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <net/if.h>

#define MULTICAST_ADDR "239.255.0.1"
#define PORT 9123

int main() {
    int sockfd;
    struct sockaddr_in addr;
    struct ip_mreq mreq;
    struct ifreq ifr;

    // Create a UDP socket
    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        perror("socket creation failed");
        exit(1);
    }

    // Set up the multicast address
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(PORT);

    // Bind the socket
    if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
        perror("bind failed");
        exit(1);
    }

    // Set up multicast group membership
    memset(&mreq, 0, sizeof(mreq));
    mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_ADDR);
    mreq.imr_interface.s_addr = INADDR_ANY;
    if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
        perror("setsockopt failed");
        exit(1);
    }

    printf("Multicast group joined successfully\n");

    // Close the socket
    close(sockfd);

    return 0;
}

That prints setsockopt failed: Exec format error, other IP address like 235.0.0.0 behaves more weird. It passes for the first time, then it fails with -16 errno, then -8 forever. Some IPs, within the range 235.0.0.0 to 238.255.255.255 first fails with -16, then -8, then it just always passes.

➜ ./build/uv_run_tests_a udp_multicast_join udp_multicast_join
Assertion failed in /Users/juanjose/GitHub/libuv/test/test-udp-multicast-join.c on line 131: `r == 0` (-16 == 0)
[1]    56998 abort      ./build/uv_run_tests_a udp_multicast_join udp_multicast_join

libuv on  juan/fix-macos-test [⇡!]
➜ ./build/uv_run_tests_a udp_multicast_join udp_multicast_join
setsockopt failed: : Exec format error
Assertion failed in /Users/juanjose/GitHub/libuv/test/test-udp-multicast-join.c on line 163: `r == 0` (-8 == 0)
[1]    57723 abort      ./build/uv_run_tests_a udp_multicast_join udp_multicast_join

I'm sorry for not getting an answer for this, macOS is simply obscure or I'm not the best at searching or both.

@bnoordhuis
Copy link
Member

@juanarbol thanks for investigating. I don't really have suggestions what to do next. Maybe we should just chalk this up as "fact of life" (and: "closed-source proprietary operating systems suck")

Fixes: libuv#4263
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
@juanarbol
Copy link
Contributor Author

@juanarbol thanks for investigating. I don't really have suggestions what to do next. Maybe we should just chalk this up as "fact of life" (and: "closed-source proprietary operating systems suck")

I found the solution, you were completely right since the beginning.

Screenshot 2024-05-09 at 1 52 19

After those settings, I get the regular "Allow this..." and the test never fails in v1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS: test udp_multicast_join fails on macOS 13 and above
3 participants