Giter Site home page Giter Site logo

BindAddress listening on wrong IP about milo HOT 7 CLOSED

eclipse avatar eclipse commented on June 5, 2024
BindAddress listening on wrong IP

from milo.

Comments (7)

kevinherron avatar kevinherron commented on June 5, 2024

I think the best thing I could do here is make it so OpcUaServer#getHostnames(String) is user-configurable.

I don't think there's any implementation we could come up with that would satisfy every use case.

For example, I can see your logic about the canonical hostname being included in the endpoints being confusing since we're bound to localhost, but without including it that would prevent an OPC-UA client application running on the same machine from accessing the server at my-host:4840, which seems overly strict to me.

from milo.

kevinherron avatar kevinherron commented on June 5, 2024

My original thought when writing getHostnames() was to lean towards being lenient/flexible, including as many hostnames in the endpoints as I reasonably could.

In the real world we've found that the majority of servers end up being configured (or misconfigured...) with either incorrect or unreachable hostnames in the endpoints, which has lead to pretty much all UA client application implementations having logic that replaces the hostname in the endpoints provided by servers with the hostname/address used to get the endpoints in the first place.

from milo.

Pro avatar Pro commented on June 5, 2024

I just ran into the problem using open62541 and I think that I identified the problem.

You are using the value of bindAddress to create the socket here:
https://github.com/eclipse/milo/blob/master/opc-ua-stack/stack-server/src/main/java/org/eclipse/milo/opcua/stack/server/tcp/UaTcpStackServer.java#L148

String bindAddress = endpoint.getBindAddress().orElse(endpointUri.getHost());

I just hacked it to test with:

String bindAddress = endpointUri.getHost();

and tadaaa, it works. In ubuntu the local IP for the hostname is 127.0.1.1 compared to localhost 127.0.0.1

[main] INFO org.domain.UaServer - startDiscoveryServer()
[main] INFO org.eclipse.milo.opcua.sdk.server.namespaces.OpcUaNamespace - Loaded nodes in 589ms.
[main] INFO org.eclipse.milo.opcua.sdk.server.NamespaceManager - added namespace index=0, uri=http://opcfoundation.org/UA/
[main] INFO org.eclipse.milo.opcua.sdk.server.NamespaceManager - registered and added namespace index=1, uri=urn:domain:opcua:discovery:server
[main] INFO org.eclipse.milo.opcua.sdk.server.OpcUaServer - Binding endpoint opc.tcp://my-host:4840 to localhost [None/None]
[main] INFO org.eclipse.milo.opcua.sdk.server.OpcUaServer - Binding endpoint opc.tcp://localhost:4840 to localhost [None/None]
[main] INFO org.eclipse.milo.opcua.sdk.server.OpcUaServer - Binding endpoint opc.tcp://127.0.0.1:4840 to localhost [None/None]
[main] INFO org.eclipse.milo.opcua.sdk.server.OpcUaServer - eclipse milo opc-ua stack version: dev
[main] INFO org.eclipse.milo.opcua.sdk.server.OpcUaServer - eclipse milo opc-ua sdk version: dev
[main] INFO org.eclipse.milo.opcua.sdk.server.NamespaceManager - registered and added namespace index=2, uri=urn:eclipse:milo:opcua:test-namespace
[main] INFO org.eclipse.milo.opcua.stack.server.tcp.UaTcpStackServer - opc.tcp://my-host:4840 bound to /127.0.1.1:4840 [None/None]
[main] INFO org.eclipse.milo.opcua.stack.server.tcp.UaTcpStackServer - opc.tcp://localhost:4840 bound to /127.0.0.1:4840 [None/None]
[main] INFO org.eclipse.milo.opcua.stack.server.tcp.UaTcpStackServer - opc.tcp://127.0.0.1:4840 bound to /127.0.0.1:4840 [None/None]

Is there a specific reason why you are using getBindAddress() instead of endpointUrl.getHost()?

from milo.

kevinherron avatar kevinherron commented on June 5, 2024

I think I set a bad example in the ExampleServer implementation by using "localhost" as a bind address.

The intention is that bind addresses are always configured as IP addresses and not as a hostnames because I want the addresses the server is configured to bind to to be un-ambiguous.

From there, the server tries to intelligently figure out what hostnames and endpoint URLs to use (the getHostnames() function I'm talking about making extensible).

from milo.

Pro avatar Pro commented on June 5, 2024

Hmm, maybe you could ad a check if the value of setBindAddresses([]) is a hostname or IP and then warn the user.
But I think that the cleaner solution is to use the endpoint.getHost() to bind to, because then the OS has to figure out the correct ip.

And yes, the example should be changed then :)

from milo.

kevinherron avatar kevinherron commented on June 5, 2024

But I think that the cleaner solution is to use the endpoint.getHost() to bind to, because then the OS has to figure out the correct ip.

The whole point is I don't want the OS to figure it out. In a system with multiple NICs I need to be able to be very specific about which address I'm binding to, and then there's room to be less strict on top of that by allowing more than one endpoint URL to point to that NIC.

So I think this is making my point about there not being one solution that will please all... I'll figure out how to make this more configurable.

from milo.

kevinherron avatar kevinherron commented on June 5, 2024

@Pro if you get a chance, check out this PR/branch and see if you can accomplish what you need with it. I'll leave the PR open for a few days before merging it.

from milo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.