-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bind receiving socket to specific interface #1
base: master
Are you sure you want to change the base?
Conversation
This makes sure the receiving socket only gets one answer from the switch, even if multiple interfaces are connected to the same network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain a bit more about the scenario where/when this happens?
Even better if you could draw some kind of physical network diagram that shows what is connected to the switch ports that makes this happen :-)
My laptop has two network interfaces, both are connected to the same switch. This might be unusual, but I use it to play with different vlans without loosing internet connectivity when I screw up things on one port. I'm now trying to manage this switch (and later others as well) without the web interface. When I first tried your Ansible collection (and also the original smrt code it is based on) I figured that neither worked at all. The switch answered as expected but the software somehow didn't get the correct answers. After hours of debugging I found that the the debug logs showed the exact same response beeing parsed twice, but for different requests. I also found that wireshark captured two answer packets per request, when listening on the 'any' interface. This seems plausible as the switch answers to the broadcast address, which should obviously go to all ports. Having one machine connected to multiple ports at the same time triggers the issue. My first quick fix was to call rs.recvfrom() twice, discarding the first result. As this would break with just one or more than two connections to the switch, I tried to find a way to get around this issue. Another possibility could be to just read all remaining data from the socket before sending a new request or keep track of expected and received/processed answers to detect duplicates, but this seemed to be a simple and elegant solution. |
I now understand! And I like the solution :-) Can you also bind the sending socket to that interface? I think that would make it more consistent with the intent of "use the same interface to send/receive data despite the host network configuration". |
I think the sending interface is already bound to the correct interface, as I'm not sure if I already understood the overall picture, but maybe it would make even more sense to specify the interface in the inventory.yml and defer the IP from there, as the specified IP is just used to |
Ah indeed it is. Scrap what I've said :-) Since I assign multiple IPs to the same interface, I'd rather not use the interface to infer its IP address. How about if we binded the receiving socket to the IP instead of the broadcast address? I'm not really sure whether that socket would receive broadcast packets from other interfaces thou... but, if that works, the code would be even simpler. |
I tried binding to the IP, but could not make it work. Multiple IPs on the interface should'nt be a problem. The IP just shows up as the sender address but as far as I know, the switch does not care. So, just picking the first IPv4 should be fine, as long as the interface is correct. Others are doing so as well. I'd be more worried about breaking existing configurations. Thats why I didn't look into that yet. Also, because I just started with Ansible today and I still have no clue how things work 🙈 |
What does seem to work:
|
The communication with the switch uses UDP broadcast. Therefore, a specific IP is not required. Replace host MAC and IP configuration options with host interface. The MAC can be read from the interface, the IP is not required due to UDP broadcast communication.
New proposal: I tried to change the configuration to use the interface instead of MAC and IP. My tests where successful so far. |
Its looking good :-) What switch model are you testing this on? |
I own two TL-SG108. |
…to Network consstructor
I also changed switch_take_ownership_client.py to the changed constructor of Network. I think this should work now, but I still didn't test yet. I'll now change the PR to ready for review, as I think all necessary changes are in now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its looking good :-)
This makes sure the receiving socket only gets one answer from the switch,
even if multiple interfaces are connected to the same network.