OpENer icon indicating copy to clipboard operation
OpENer copied to clipboard

Producing connections without raw sockets

Open PeterChristen577 opened this issue 3 years ago • 16 comments

Added a global UDP socket for io messaging to g_network_status CreateUdpSocket is called once in OpenCommunicationChannels CloseUdpSocket is called once in CloseCommunicationChannelsAndRemoveFromActiveConnectionsList CreateUdpSocket adapted parameters removed, open the global socket, doing a bind(2) to define the src port Remove all socket configuring stuff from all functions called in EstablishIoConnection New functions created for additional TTL and Multicast settings formerly done in CreateUdpSocket Renamed CheckAndHandleConsumingUdpSockets to CheckAndHandleConsumingUdpSocket

PeterChristen577 avatar Jul 17 '21 15:07 PeterChristen577

Do I understand this correctly, that there is always only one outgoing UDP port? What if the originator wants two connections with two different ports? I am not sure if this is covered by this patch and the conformance tester tests

MartinMelikMerkumians avatar Jul 20 '21 10:07 MartinMelikMerkumians

Yes you do understand correctly this. I understood that for implicit IO messaging always port 2222 should used for src and dest port, isnt it?

PeterChristen577 avatar Jul 20 '21 15:07 PeterChristen577

@CapXilinx: I did implement, what we discussed related to issue #157, the functionality of the stack should remain the same as before. There is no change in the port addressing except the source port in the IO messages sent will be always 2222 (as before). How shall we proceed now?

PeterChristen577 avatar Jul 23 '21 20:07 PeterChristen577

@CapXilinx Hi Martin It is quite a while since we have been in touch. In the meantime I tested it with the Posix port as also with my new STM32 port together with a Rockwell PLC and it works fine in the modes Unicast and Multicast. Your concern: "What if the originator wants two connections with two different ports?" can be answered in the way that I did not touch the handling of the remote (dest) address (and port). Can you provide any guidance how I could test this? BR Peter

PeterChristen577 avatar Aug 29 '21 19:08 PeterChristen577

Hi @PeterChristen577, sorry for the very late reply. For every Forward Open there needs to be an additional Sockaddr Info Item in the message, defining the O->T and T->O connections. For PtP there the sin_port field can be any port. Port 0x8AE (2222) is recommended, so perhaps in 90% of all cases this should pose no problem, but there could be vendors or users who do not want to use this port. Also, with the CIP Security extension, secure connections will use port 2221 (0x8AD) so this will become a problem in the future if we only can have one port.

My fix for that would be to allow multiple sockets for different ports, but as you have implemented it now, only one socket per port and scanning all ports sequentially and reroute the messages to the correct connections.

How to test this all... that's the hardest question. I don't know of any software to do this easy. One solution would be to create one connection via ENIPExplorer and then send a second request via the Messaging Tool in the ODVA Conformance Test Tool or the Molex or Hilscher ENIP Tool, where you can then specify also the Sockaddr Info Item.

But I am not sure if this really works, such low level test are unfortunately hard to do. Another possibility would be to create a small Python script to send the Forward Open with the needed Sockaddr Item.

I hope that helps, and I am happy to help you in testing and programming if you want to extend your patch regarding the things mentioned above.

I would like to try to extend this myself, but currently, I am busy on CIP Security, CIP File and updating the core to conform with the new specification, so I unfortunately can't right now.

Best regards, Martin

MartinMelikMerkumians avatar Sep 28 '21 11:09 MartinMelikMerkumians

Oh, what I forget to mention, I have some problems putting your branch on the current master. Not sure if this a problem with my setup but I can't merge it properly

MartinMelikMerkumians avatar Sep 28 '21 11:09 MartinMelikMerkumians

@CapXilinx Hi Martin Thanks for your answer. Let me think about a little about that. Just for my understanding two questions:

  1. When you are talking about port 2221, do you mean the source or destination port?
  2. I have only very old versions of THE CIP NETWORKS LIBRARY, Volume 1 and 2 (Edition 1.4, November 2007) where can I can more recents versions of it? About your mention concerning the merge. I had to resolve some conflicts, this has been done now.

PeterChristen577 avatar Sep 29 '21 19:09 PeterChristen577

Hi @PeterChristen577,

ad 1): again, this can be both for originator and target. At least it seems that CIP Security does not allow the use of other ports for their communication. ad 2): At the ODVA (https://www.odva.org/). The most recent version should be April 2021,the next version will be probably released in November.

MartinMelikMerkumians avatar Oct 04 '21 11:10 MartinMelikMerkumians

@CapXilinx Hi Martin

  1. I had a look using WireShark to the Forward open message - sent by ENIPExplorer: There I expect to see any address information, but I could not find it: Forward Open O-T but in the response from the target to the originator this information is included: Forward Open T-O

  2. I do not have $1000 spare to buy the specs ;)

If you could provide some guidance in this topic. this would be great.

About testing: I am able to compile ENIPExplorer. I could create a version where the port(s) can be configured and then use two instances of it with different ports set up.

PeterChristen577 avatar Oct 04 '21 20:10 PeterChristen577

Hi @PeterChristen577 ,

sorry again for the long delay. Flu season starts it seems ':)

If no address information is sent, then the default (2222) is assumed.

MartinMelikMerkumians avatar Nov 02 '21 11:11 MartinMelikMerkumians

@PeterChristen577 perhaps you want to skype on your open questions? I think that would be easier than discussing it here

MartinMelikMerkumians avatar Nov 23 '21 12:11 MartinMelikMerkumians

@CapXilinx yes this is a very good proposal. Let me know when it would fit in time for you.

PeterChristen577 avatar Nov 23 '21 21:11 PeterChristen577

@CapXilinx Hi Martin I took the source code from the Hilscher Ethernet/IP Tool and added the possibility the change the IP port in the forward open request.

Forward Open with port 2222 (standard): Forward open port 2222 IO date T>O: CIP IO T-O port 2222 Forward Open with port with port 2221: Forward open port 2221 IO date T>O: CIP IO T-O port 2221

This has been tested with both branches: master and this pull request without raw sockets. The behaviour is equal for both branches.

PeterChristen577 avatar Dec 18 '21 21:12 PeterChristen577

Has there been a final decision made on this PR yet? It worksforme (TM) communicating with a simple Allen Bradley PLC and I am very tempted to use it instead of master since not needing Administrator rights on Windows would be quite nice.

BartVanhauwaert avatar Jun 13 '22 12:06 BartVanhauwaert

Finally time to get its tested, looks good so far

MartinMelikMerkumians avatar Jul 16 '22 08:07 MartinMelikMerkumians

Great! If I can support it, let mw know

PeterChristen577 avatar Jul 16 '22 11:07 PeterChristen577

Is there anything I can help with to bring this branch forward?

BartVanhauwaert avatar Aug 31 '22 13:08 BartVanhauwaert

We are currently testing it. We have identified an issue with the last commit 'RPI Timer fix' to produce errors in the CT, where it does not receive some messages. Without that commit is seems to work fine.

MartinMelikMerkumians avatar Aug 31 '22 13:08 MartinMelikMerkumians

Can you provide a more specific information about the issues with 'RPI Timer fix'? After vacation season I would have time to do some analysis.

PeterChristen577 avatar Sep 07 '22 19:09 PeterChristen577

I found an issue in cases where the elapsed time is higher than the RPI set up. This has been fixes. The implementation before was more proof of concept, sorry for the circumstances. Please test it again

PeterChristen577 avatar Sep 10 '22 15:09 PeterChristen577

Tests done, I will merge it today

MartinMelikMerkumians avatar Oct 03 '22 12:10 MartinMelikMerkumians

Merged in 6068d32066358e71f832e4f0cf21599cfe7e6cbe Seems like Github didn't recognize it

MartinMelikMerkumians avatar Oct 03 '22 15:10 MartinMelikMerkumians