Quote:
Originally Posted by justjay
Thanks for the reply nx500.
The client currently uses the same port since there is really no way of know what the last port it used was.
|
Actually in general, you let linux choose the source port for you (probably what you do unless you really set it manually). Source port 0 means that the system has to choose one by itself.
I forgot that probably your system when it boots is predictable, which means that your application will always get the same source port IF linux takes 1024 then 1025.
In the last kernels, the source port is choosen randomly for security reasons.
See
https://www.linuxquestions.org/quest...25#post2360825
This would solve your problem. Maybe?
You could modify very carefully the kernel code to apply the same patch.
Depends on which kernel you're running..
Quote:
I could potentially store the last port used in eeprom and make sure it is different on the next connection, but eeprom has so many writes before it eventually fails. Yeah, it is about 100,000 times, but it eventually will fail.
|
No no no much too complicated and as you said not good for hardware.
Quote:
I guess I am looking more for a way to disable/minimize the time after I close a socket before it can be reopened with the same IP address and port. Maybe I'm there. I thought this had to do with connection tracking (which I modified), but it seems like there is something else lingering somewhere. I'm just not sure where to look.
|
If this timeout is there, it's because there is a reason:
IP packets can get re-ordered. You rst might "overtake" a real data. If the connection is closed, this real data will not be accepted while it should.
I think there is a way to stop quickly (setsockopt) a connection but in the case of a clean close. For a dirty close, the remote system thinks you're still alive.
Btw, how do you manage to send an rst when your board resets?
edit:
or in your application, if you can get a semi-random source, modify it and fix manually the source port.
s.addr=random(65535) <-- its for fixing idea, its not the real code