java.net.NetworkInterfaces and Linux with multiple addresses on single interface

Doychin Bondzhev doychin at dsoft-bg.com
Mon Dec 29 20:37:23 UTC 2014


Yes, It is only a matter of implementation in the native code. There 
will be no changes in the public API.

To be honest  I don't have much experience in C development and I'm not 
sure the function that I'm offering is supported on all UNIX platforms 
that OpenJDK targets.

I can test only on Linux.



On 29.12.2014 г. 22:21 ч., Chris Hegarty wrote:
>
> On 27 Dec 2014, at 15:53, Doychin Bondzhev <doychin at dsoft-bg.com> wrote:
>
>> This is a copy of my email that I sent earlier to core-libs-dev.
>> -----------
>>
>> Hi,
>>
>> I want to report for a problem that I see when I have more then one IP addresses assigned to same interface.
>>
>> Here is an output from ip addr command on my 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
>>
>> As you can see 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.
>>
>> I propose another method of reading ip address information for interfaces that will use getifaddrs/freeifaddrs.
>>
>> getifaddrs knows how to handle this case properly. It returns all the necessary information in an array of "struct ifaddrs"
>>
>> Any toughs on this proposition?
>
> This sounds reasonable. It is an implementation only issue, right? No impact on the public NetworkInterface API.
>
> -Chris.
>
>
>> --
>> Doychin Bondzhev
>> dSoft-Bulgaria Ltd.
>> PowerPro - billing & provisioning solution for Service providers
>> PowerStor - Warehouse & POS
>> http://www.dsoft-bg.com/
>> Mobile: +359888243116
>> <doychin.vcf>
>
>


-- 
Doychin Bondzhev
dSoft-Bulgaria Ltd.
PowerPro - billing & provisioning solution for Service providers
PowerStor - Warehouse & POS
http://www.dsoft-bg.com/
Mobile: +359888243116
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doychin.vcf
Type: text/x-vcard
Size: 268 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20141229/7f992584/doychin-0001.vcf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5924 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20141229/7f992584/smime-0001.p7s>


More information about the net-dev mailing list