Skip to content
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

Merged
merged 1 commit into from
May 18, 2017

Conversation

pfalcon
Copy link
Contributor

@pfalcon pfalcon commented May 5, 2017

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

@nashif nashif added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label May 5, 2017
@pfalcon
Copy link
Contributor Author

pfalcon commented May 5, 2017

This patch is for illustrative purposes for GH-3545 . It should not be merged until:

  1. We understand why "most" FINs are sent properly, while there's such path when it's sent improperly.
  2. We understand where seq+2 comes from (in this patch, it's just a result of applying "genetic search algorithm" to make Linux host happy, as watched by Wireshark).

A stray printk() should help avoid premature merge.

Copy link
Member

@nashif nashif left a 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...

@@ -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");
Copy link
Member

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.

Copy link
Contributor Author

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.

@pfalcon
Copy link
Contributor Author

pfalcon commented May 5, 2017

remove Change-Id... you probably want to remove the hook from your git tree...

What if we go back to gerrit tomorrow? ;-)

@pfalcon pfalcon changed the title net: tcp: When sending FIN, make sure it goes with ACK and proper seq [DRAFT] net: tcp: When sending FIN, make sure it goes with ACK and proper seq May 5, 2017
@lpereira
Copy link
Collaborator

lpereira commented May 9, 2017

Maybe @andyross will want to take a look as well.

@jukkar jukkar self-requested a review May 10, 2017 07:56
@pfalcon
Copy link
Contributor Author

pfalcon commented May 10, 2017

@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:

These changes makes Wireshark happy when the connection is closed.

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 ;-).

Copy link
Member

@jukkar jukkar left a 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.

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;
Copy link
Member

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.

Copy link
Contributor Author

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 ;-).

Copy link
Contributor

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. :)

@jukkar jukkar requested a review from andyross May 12, 2017 18:54
@jukkar jukkar added the net label May 12, 2017
@pfalcon pfalcon force-pushed the net-fin-ack-seq branch from f4135b1 to 08dafa1 Compare May 17, 2017 11:15
@pfalcon pfalcon changed the title [DRAFT] net: tcp: When sending FIN, make sure it goes with ACK and proper seq net: tcp: When sending FIN, make sure it goes with ACK and proper seq May 17, 2017
@pfalcon
Copy link
Contributor Author

pfalcon commented May 17, 2017

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>
@pfalcon pfalcon force-pushed the net-fin-ack-seq branch from 08dafa1 to 4433b77 Compare May 17, 2017 11:20
Copy link
Member

@jukkar jukkar left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants