JDK-4790745 : Multihomed machines choose same interface for multicasting
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.1,6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2002-12-09
  • Updated: 2007-06-28
  • Resolved: 2007-06-28
Related Reports
Duplicate :  
Description

Name: nt126004			Date: 12/09/2002


FULL PRODUCT VERSION :
java -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)



FULL OPERATING SYSTEM VERSION : Suse 8.0 Linux 2.4.18


EXTRA RELEVANT SYSTEM CONFIGURATION :
2 Ethernet interfaces
eth0 -> 192.168.1.11/24
eth1 -> 192.168.2.104/24


A DESCRIPTION OF THE PROBLEM :
Basically a multicast socket is created and bound to 2
different IP addresses using 'socket.setInterface', but the
multicasts are coming out the same interface and TTL is 1
even though it is set up 10.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.java Mxmit 239.192.101.100 11000 10 192.168.2.104
2.java Mxmit 239.192.100.100 11000 10 192.168.1.11

EXPECTED VERSUS ACTUAL BEHAVIOR :

The expected results are that there will be multicast stream
on eth1 interface also.

netstat -g reports

eth0            1      239.192.100.100
eth1            1      239.192.101.100

netstat -rn reports
192.168.2.0 0.0.0.0 255.255.255.0 U 40 0  0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 40 0  0 eth0
224.0.0.0   0.0.0.0 240.0.0.0     U 40 0  0 eth0
224.0.0.0   0.0.0.0 240.0.0.0     U 40 0  0 eth1
0.0.0.0     192.168.1.1 0.0.0.0   UG  40 0 0 eth0





ERROR MESSAGES/STACK TRACES THAT OCCUR :
tcpdump reports both streams coming out the eth0 interface.

17:46:53.032452 192.168.1.11.11000 > 239.192.100.100.11000: udp 31 (DF) [ttl 1]
17:46:54.602099 192.168.1.11.12000 > 239.192.101.100.12000: udp 30 (DF) [ttl 1]
17:46:58.041458 192.168.1.11.11000 > 239.192.100.100.11000: udp 31 (DF) [ttl 1]
17:46:59.612518 192.168.1.11.12000 > 239.192.101.100.12000: udp 30 (DF) [ttl 1]



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Mxmit.java

  import java.net.*;
  import java.io.*;
  import java.lang.*;
  import java.util.*;
  import java.text.DateFormat;

  class Mxmit {
    public static void main( String[] args) {
      if ( args.length != 4) {
        System.err.println(" Syntax -> java Mxmit <address/group> <port> <ttl>
<hostIP>");
        System.exit(-1);
      }
      int delta = Integer.parseInt(args[2]);
      try {
        int port = Integer.parseInt(args[1]);
        MulticastSocket socket = new MulticastSocket(port);

        InetAddress group = InetAddress.getByName(args[0]);
        InetAddress local = InetAddress.getByName(args[3]);

        System.out.println( local );

        socket.setInterface(local);
        socket.joinGroup(group);
        System.out.println(local);
        socket.setTimeToLive(delta);
        System.out.println("TTL -> " +  socket.getTimeToLive());
        Date today = new Date();
        String ok = DateFormat.getDateInstance().format(today);
        System.out.println(ok);
        System.out.println(today);

        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String cmd, send;
        int counter = 0;
        while (true) {
          send = new Date() + " " + String.valueOf( counter );
          DatagramPacket packet = new DatagramPacket(send.getBytes(),
send.length(), group, port);
          socket.send(packet);
          Thread.sleep(5000);
          counter++;
        }
      } catch (Exception e) {
       e.printStackTrace();
      }
    }
  }


---------- END SOURCE ----------

CUSTOMER WORKAROUND :
I will have to continue to try to make stream come out eth1
interface.
(Review ID: 178881) 
======================================================================

Comments
EVALUATION Fixed since 4742177 has been fixed now.
28-06-2007

EVALUATION There is an indeed an issue with MulticastSocket.setInterface (additionally setNetworkInterface and setTimeToLive) when run on a Linux machine with multiple adapets and IPv6 compiled into the kernel. If the application doesn't care about IPv6 then the issue can be worked around but running with the java.net.preferIPv4Stack system property set to "true". The reason that the multicast packet is sent from the primary interface is because the IPV6_MULTICAST_IF socket option is only setting the outgoing interface for IPv6 multicasts. This is one of a number of issues with the Linux/USAGI IPv6 support - see 4742177 for a list of issues that need to be examined. To address this issue we need to examine setting both IP_MULTICAST_IF and IPV6_MULTICAST_IF when setInterface/setNetworkInterface is used. ###@###.### 2002-12-09
09-12-2002