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: Parse and store send MSS #4657

Merged
merged 3 commits into from
Nov 8, 2017

Conversation

pfalcon
Copy link
Contributor

@pfalcon pfalcon commented Oct 31, 2017

MSS is Maximum Segment Size (data payload) of TCP. In SYN packets,
each side of the connection shares an MSS it wants to use (receive)
via the corresponding TCP option. If the option is not available,
the RFC mandates use of the value 536.

This patchset is a prerequisite for proper implementing #119

Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org

@pfalcon pfalcon changed the title WIP net: tcp: Handle storage of TCP send MSS net: tcp: Parse and store send MSS Nov 3, 2017
@pfalcon pfalcon requested a review from lpereira November 3, 2017 21:17
@pfalcon
Copy link
Contributor Author

pfalcon commented Nov 3, 2017

This now fully implements MSS parsing and storage for incoming connections. Required for #119 (which is required for #4243

@pfalcon pfalcon requested a review from askawu November 3, 2017 21:25
u8_t opt, optlen;

while (opt_totlen) {
frag = net_frag_read(frag, pos, &pos, sizeof(opt), &opt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check the return values here so that we now whether the packet is malformed or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the discussion on IRC, I'm adding single check at the top of function.

goto error;
}

frag = net_frag_read(frag, pos, &pos, sizeof(optlen), &optlen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the discussion on IRC, I'm adding single check at the top of function.

if (optlen != 2) {
goto error;
}
frag = net_frag_read(frag, pos, &pos,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the discussion on IRC, I'm adding single check at the top of function.

optlen, (u8_t *)mss);
break;
default:
frag = net_frag_skip(frag, pos, &pos, optlen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the discussion on IRC, I'm adding single check at the top of function.

@@ -1230,3 +1231,71 @@ struct net_buf *net_tcp_set_chksum(struct net_pkt *pkt, struct net_buf *frag)

return frag;
}

int tcp_parse_opts(struct net_pkt *pkt, int opt_totlen, u16_t *mss)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better would be to give also the option we are interested in like NET_TCP_MSS_OPT as a parameter, and then return the value according to wanted option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would scale or follow any realistic processing routine. Realistically, we will always parse options once, and get all the interesting options during this parse too. So, I had an idea to introduce struct tcp_options, but it would contain only MSS now. So, I considered that over-engineering and applied YAGNI - indeed, it doesn't make sense to remove unused things in one place (#4653 (comment)) and add unused stuff in another.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your "struct tcp_options" sounds like a good plan even if it would contain only MSS for now. Now the function is quite misleading as it only parses mss but you call it tcp_parse_opts(). I did not understand your last sentence, what we are removing and adding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand your last sentence, what we are removing and adding?

What I meant that in #4653, an used structure field being reported, and e.g. @lpereira's suggestion was "remove it". Then we could follow that idea and not add fields/structures unless really needed.

Anyway, if you find that introducing struct tcp_options would deconfuse this patch, let me just do it.

}

opt_totlen -= optlen;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra empty line can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

u16_t pos = net_pkt_ip_hdr_len(pkt)
+ net_pkt_ipv6_ext_len(pkt)
+ sizeof(struct net_tcp_hdr);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@pfalcon pfalcon force-pushed the net-tcp-send-mss branch 2 times, most recently from ba3584e to 635e6bc Compare November 6, 2017 16:44
MSS is Maximum Segment Size (data payload) of TCP. In SYN packets,
each side of the connection shares an MSS it wants to use (receive)
via the corresponding TCP option. If the option is not available,
the RFC mandates use of the value 536.

This patch handles storage of the send MSS (in the TCP structure,
in TCP backlog), with follow up patch handling actual parsing it
from the SYN TCP options.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Calculates full TCP header length (with options). Macro introduced
for reuse, to avoid "magic formula". (E.g., it would be needed to
parse TCP options).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Add a generic function for TCP option parsing. So far we're
interested only in MSS option value, so that's what it handles.
Use it to parse MSS value in net_context incoming SYN packet
handler.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
@pfalcon
Copy link
Contributor Author

pfalcon commented Nov 7, 2017

@jukkar : Updated to add struct net_tcp_options.

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.

LGTM

@jukkar jukkar merged commit cdea2bf into zephyrproject-rtos:master Nov 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants