-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
net: tcp: When sending FIN, make sure it goes with ACK and proper seq #104
Conversation
This patch is for illustrative purposes for GH-3545 . It should not be merged until:
A stray printk() should help avoid premature merge. |
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.
remove Change-Id... you probably want to remove the hook from your git tree...
subsys/net/ip/tcp.c
Outdated
@@ -417,7 +417,9 @@ int net_tcp_prepare_segment(struct net_tcp *tcp, u8_t flags, | |||
|
|||
if (flags & NET_TCP_FIN) { | |||
tcp->flags |= NET_TCP_FINAL_SENT; | |||
seq++; | |||
printk("Making sure FIN goes with ACK; adjusting seq by 2; now fire up Wireshark and check that all's ok\n"); |
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.
that line looks off, align properly.
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.
It's on purpose, as mentioned in the comment:
A stray printk() should help avoid premature merge.
As https://jira.zephyrproject.org/browse/ZEP-2104 alone didn't catch attention, maybe this draft patch will.
What if we go back to gerrit tomorrow? ;-) |
Maybe @andyross will want to take a look as well. |
@lpereira : Thanks. Actually, this could use more detailed look from you, as you worked on FIN handling previously, e.g. 564d8cd . What caught my eye in that commit is part of its commit message:
So, this patch was also made using Wireshark (not RFC793, not looking thru thousands of lines of the code). I'm not much happy about this patch, but if nobody else have better idea, maybe we just merge it? ;-). Because it's done with a methodology already used before, so shouldn't be much worse than previous patches already pushed ;-). |
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.
Looks good but I suggest we add also a comment to the code why we are adding seq+2 there.
subsys/net/ip/tcp.c
Outdated
seq++; | ||
printk("Making sure FIN goes with ACK; adjusting seq by 2; now fire up Wireshark and check that all's ok\n"); | ||
flags |= NET_TCP_ACK; | ||
seq += 2; |
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.
This seq+=2 looks indeed weird. At least we could add a comment about why we do it like this. I agree with @pfalcon that it does not change much if we fix this according to wireshark output.
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.
Yes, likely the sequence should have been incremented in some other state, but it wasn't, that's why we need to increment it by 2 here. It would take me some good time to trace thru Z TCP state machine implementation (nor I know TCP state machine itself by heart and will need to refresh myself on it). So I just hope that folks who know more about Z stack can look at this patch and get an idea what may be the underlying cause. But I'm glad that we have in store an option to merge this, if no better fix surfaces ;-).
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.
That "magic extra byte" in sequence numbers for SYN and FIN packets is really annoying. But I agree with Jukka: it'd be better to implement this as an "increment because we received a FIN" and not a "+2" for clarity.
Also, a warning: I ran into a spot (I forget the precise details) where wireshark was lying to me about packet parsing. It was making assumptions based on the ethernet frame that happened to be wrong, or something. Use tcpdump to verify before making a change based solely on wireshark. :)
I'm off thru the end of week, so I polish this patch into being OK from codestyle point of view, while still having a FIXME comment. If this won't be merged until Friday, I assume it still would be usable as a fallback workaround for 1.8, just gives us a week or two to still try to investigate the underlying cause. |
Without change to add ACK to FIN, invalid TCP packet is generated, where ack sequence number is non-zero. Without adjusting sequence number as done, ACK which we send in response to peer's FIN/ACK is not recognized by peer, and peer keeps retransmitting its FIN/ACK. Jira: ZEP-2104 Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
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.
I think this is good enough for merging, especially if you can investigate the root cause for that seg+2 thing.
Without change to add ACK to FIN, invalid TCP packet is generated,
where ack sequence number is non-zero. Without adjusting sequence
number as done, ACK which we send in response to peer's FIN/ACK is
not recognized by peer, and peer keeps retransmitting its FIN/ACK.
Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org