NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/59486: compat_linux should ignore IP_MULTICAST_ALL



>Number:         59486
>Category:       kern
>Synopsis:       compat_linux should ignore IP_MULTICAST_ALL
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 26 19:40:00 +0000 2025
>Originator:     csaba mate
>Release:        10.1
>Organization:
freertr.org
>Environment:
netbsd 10.1 amd64, i386
>Description:
i'm trying to run latest-greatest openjdk from jdk.java.net after modload compat_linux to have an alternative os for my freertr.org project, huwever the udp socket does not work;

they do the following: https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libnio/ch/Net.c#L300 and errors out.

i saw that you already have a workaround possibility in place: https://github.com/NetBSD/src/blob/trunk/sys/compat/linux/common/linux_socket.c#L1080

but no defined workarounds for udp yet: https://github.com/NetBSD/src/blob/trunk/sys/compat/linux/common/linux_socket.c#L1008


>How-To-Repeat:
echo "
import java.net.DatagramSocket;

public class socktest {
    public static void main(String args[]) throws Exception
    {
        DatagramSocket ds = new DatagramSocket();
    }
}
" > socktest.java



echo "
#include <stdio.h>
#include <sys/socket.h>
#include <dlfcn.h>
#include <errno.h>

#define paramsetsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen)

int (*originalsetsockopt) paramsetsockopt;

int setsockopt paramsetsockopt {
    if (!originalsetsockopt) {
        originalsetsockopt = (int (*) paramsetsockopt )dlsym(RTLD_NEXT, "setsockopt");
    }

    int res = originalsetsockopt(fd, level, optname, optval, optlen);
    printf("hook called optname=%i res=%i errno=%i!\n", optname, res, errno);

    return 0;
}
"

# javac socktest
# clang -shared -fPIC sockhook.c -o sockhook.so -ldl
#
#

# /mnt/java/bin/java -cp /mnt/rtr/ zzz
Exception in thread "main" java.net.SocketException: Invalid argument
    at java.base/sun.nio.ch.Net.socket0(Native Method)
    at java.base/sun.nio.ch.Net.socket(Unknown Source)
    at java.base/sun.nio.ch.DatagramChannelImpl.<init>(Unknown Source)
    at java.base/sun.nio.ch.DatagramChannelImpl.<init>(Unknown Source)
    at java.base/sun.nio.ch.SelectorProviderImpl.openUninterruptibleDatagramChannel(Unknown Source)
    at java.base/java.net.DatagramSocket.createDelegate(Unknown Source)
    at java.base/java.net.DatagramSocket.<init>(Unknown Source)
    at java.base/java.net.DatagramSocket.<init>(Unknown Source)
    at zzz.main(zzz.java:7)
#
#
#
# LD_PRELOAD=/mnt/rtr/sockhook.so /mnt/java/bin/java -cp /mnt/rtr/ zzz
hook called optname=15 res=-1 errno=22!
hook called optname=49 res=-1 errno=22!
hook called optname=6 res=0 errno=22!
#
#

>Fix:

so if you could add the following:


diff -crB a/linux_socket.c b/linux_socket.c
*** a/linux_socket.c	2021-09-23 08:56:27.000000000 +0200
--- b/linux_socket.c	2025-06-26 21:32:40.762049616 +0200
***************
*** 1006,1011 ****
--- 1006,1013 ----
  {
  
  	switch (lopt) {
+ 	case LINUX_IP_MULTICAST_ALL:
+ 		return -2;	/* ignored */
  	default:
  		return -1;
  	}
diff -crB a/linux_socket.h b/linux_socket.h
*** a/linux_socket.h	2021-09-23 08:56:27.000000000 +0200
--- b/linux_socket.h	2025-06-26 21:32:13.626277518 +0200
***************
*** 110,115 ****
--- 110,116 ----
  #define	LINUX_IP_MULTICAST_LOOP	34
  #define	LINUX_IP_ADD_MEMBERSHIP	35
  #define	LINUX_IP_DROP_MEMBERSHIP 36
+ #define LINUX_IP_MULTICAST_ALL 49
  
  /*
   * Options for [gs]etsockopt(2), IPV6 level.


that would help here a lot here...





Home | Main Index | Thread Index | Old Index