Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8158519

Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface

    XMLWordPrintable

Details

    • b123
    • linux
    • Not verified

    Description

      Details copied from descriptions posted to net-dev, see...
        http://mail.openjdk.java.net/pipermail/net-dev/2014-December/008806.html
        http://mail.openjdk.java.net/pipermail/net-dev/2015-January/008829.html

      ---
      Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface

      Output from ip addr command on the linux box:

      1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
           link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
           inet 127.0.0.1/8 scope host lo
           inet6 ::1/128 scope host
              valid_lft forever preferred_lft forever
      2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
      state UP qlen 1000
           link/ether 08:00:27:fc:25:9f brd ff:ff:ff:ff:ff:ff
           inet 192.168.1.4/24 brd 192.168.1.255 scope global eth0
           inet6 fe80::a00:27ff:fefc:259f/64 scope link
              valid_lft forever preferred_lft forever
      3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
      state UP qlen 1000
           link/ether 08:00:27:b1:42:d0 brd ff:ff:ff:ff:ff:ff
           inet 192.168.240.1/24 brd 192.168.240.255 scope global eth1
           inet 192.168.241.1/24 brd 192.168.241.255 scope global eth1
           inet 192.168.239.1/24 brd 192.168.239.255 scope global eth1
           inet 10.0.0.1/22 brd 10.0.3.255 scope global eth1
           inet6 fe80::a00:27ff:feb1:42d0/64 scope link
              valid_lft forever preferred_lft forever

      And this is the output of a test java program that uses
      NetworkInterfaces class to display all IP addresses and their
      corresponding settings:

      eth1:10.0.0.1/24 broadcast:192.168.240.255
      eth1:192.168.239.1/24 broadcast:192.168.240.255
      eth1:192.168.241.1/24 broadcast:192.168.240.255
      eth1:192.168.240.1/24 broadcast:192.168.240.255
      eth0:192.168.1.4/24 broadcast:192.168.1.255
      lo:127.0.0.1/8

      There are 2 problems visible here:

      1. On all eth1 lines same broadcast is displayed. The value is the
      broadcast of the first IP address set on that interface

      2. All addresses are with prefix length of 24 which is not correct. We
      have 10.0.0.1/22 in the "ip addr" output.

      So the problem is in NetworkInterfaces native code for Unix.

      For IPv4 addresses that code uses 2 functions (getBordacast and
      getSubnet and these 2 functions use ioctl with SIOCGIFNETMASK and
      SIOCGIFBRDADDR. Both of these requests receive as parameter interface
      name. They are not prepared to work in environments where you can
      specify more then one IP on the same interface without using virtual
      interfaces.

      So using virutal interfaces is the only workaround of this problem for
      the moment.

      ---
      In order to setup dummy interface with test values you can use these
      commands:

      ip link add dummy0 type dummy

      ip addr add 10.5.5.1/28 brd 10.5.5.15 dev dummy0
      ip addr add 10.6.0.1/23 brd 10.6.1.255 dev dummy0
      ip addr add 10.7.0.1/25 brd 10.7.0.127 dev dummy0

      The output from NetworkInterface test
      test/java/net/NetworkInterface/NetParamsTest.java for this interface is:

      dummy0 :
          Status: DOWN
          Hardware Address: 56:ffffffd4:fffffffd:ffffffc2:ffffffec:ffffff82:
          Loopback: false
          Point to Point: false
          Virtual: false
          Multicast: false
          MTU: 1500
          Bindings:
              /10.7.0.1/25 [/10.7.0.127]
              /10.6.0.1/23 [/10.6.1.255]
              /10.5.5.1/28 [/10.5.5.15]

      This is the output from Java 1.8.0_25. Same output is produced with
      existing version of NetworkInterface.c in JDK 9

      dummy0 :
          Status: DOWN
          Hardware Address: 56:ffffffd4:fffffffd:ffffffc2:ffffffec:ffffff82:
          Loopback: false
          Point to Point: false
          Virtual: false
          Multicast: false
          MTU: 1500
          Bindings:
              /10.7.0.1/28 [/10.5.5.15]
              /10.6.0.1/28 [/10.5.5.15]
              /10.5.5.1/28 [/10.5.5.15]

      Attachments

        Issue Links

          Activity

            People

              chegar Chris Hegarty
              chegar Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: