Closed Race666 closed 6 years ago
Can you maybe give an example where the warning should be printed in addition to now?
The warning currently exists for localEP
because users still pass the result of InetAddress::getLocalHost
without knowing or taking into account the system configuration / host name (and resolution thereof). Then are surprised if the loopback is used (which is completly fine if intended).
I configured the calimero server to establish a tunnel connection (to 192.168.56.200) and this failed because the loopback (127.0.1.1) is as local endpoint for the connection used on a debian 9 system. But this is an other issue :-) I'm right that for a server tunnelconnection I cannot specify the local endpoint interface?
The issue here is that the error message is incorrect. The Log Message: 20:55:29:415 INFO calimero.knxnetip.KNXnet/IP Tunneling 192.168.56.200:3671 - establish connection from /127.0.1.1:48143 to /192.168.56.200:3671 20:55:29:419 ERROR calimero.knxnetip.KNXnet/IP Tunneling 192.168.56.200:3671 - communication failure on connect java.io.IOException: Invalid argument (sendto failed) at java.net.PlainDatagramSocketImpl.send(Native Method) at java.net.DatagramSocket.send(DatagramSocket.java:693)
is ok.
But the Exception Message is incorrect:
20:55:29:434 ERROR calimero.link - initial connection attempt
tuwien.auto.calimero.KNXException: connecting from 0.0.0.0/0.0.0.0:0 to /192.168.56.200:3671: Invalid argument (sendto failed)
at tuwien.auto.calimero.knxnetip.ClientConnection.connect(ClientConnection.java:184)
at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.
This is very confused because the ctrlSocket.send(p); throws an exception of an invalid argument. I investigated and found out that the invalid argument is the local endpoint which points to the loopback address 127.0.1.1 and not to 0.0.0.0 as shown in the message. 0.0.0.0 is an valid endpoint for outgoing connections and wouldn't throw an exception,
Ok, got it. The exception message should use local
, not the warning. I just pushed a commit.
The server tunnel was initially done to be used in a VPN/LAN, so having the same subnet would get you the right address. Your local endpoint does probably not have a 192.168.56.x address assigned. So no, a manual configuration of the default setting is currently not possible, you can see the init here.
My original thought was to not have surprises with dhcp, but thinking of it, a specific local endpoint can be quite useful.
I added an option to the server config (for now, the attribute is called netif
located in the knxSubnet
element), which allows to set the local network interface used for tunneling connections.
Ok cool.
The calimero server and the tunnel endpoint are on the same subnet. It seems there is another issue with the
private static boolean matchesPrefix(final InterfaceAddress ia, final InetAddress remote)
function which does in my case not found the correct NetworkAdapter for the subnet. Problem is here:
if ((a1[i] & (mask >> (24 - 8 * i))) != (a2[i] & (mask >> (24 - 8 * i))))
The bit shift of the mask is for Byte 0 and 3 = 0
24 - 8 0 = 0 24 - 8 3 = 0
I have already an patch and will open another push request
Warning Message shows the wrong local UDP Endpoint. InetSocketAddress local is used for the socket not localEP