-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,7 @@ struct net_tcp *net_tcp_alloc(struct net_context *context) | |
tcp_context[i].send_seq = tcp_init_isn(); | ||
tcp_context[i].recv_max_ack = tcp_context[i].send_seq + 1u; | ||
tcp_context[i].recv_wnd = min(NET_TCP_MAX_WIN, NET_TCP_BUF_MAX_LEN); | ||
tcp_context[i].send_mss = NET_TCP_DEFAULT_MSS; | ||
|
||
tcp_context[i].accept_cb = NULL; | ||
|
||
|
@@ -599,7 +600,7 @@ u16_t net_tcp_get_recv_mss(const struct net_tcp *tcp) | |
static void net_tcp_set_syn_opt(struct net_tcp *tcp, u8_t *options, | ||
u8_t *optionlen) | ||
{ | ||
u16_t recv_mss; | ||
u32_t recv_mss; | ||
|
||
*optionlen = 0; | ||
|
||
|
@@ -610,7 +611,8 @@ static void net_tcp_set_syn_opt(struct net_tcp *tcp, u8_t *options, | |
recv_mss = 0; | ||
} | ||
|
||
UNALIGNED_PUT(htonl((u32_t)recv_mss | NET_TCP_MSS_HEADER), | ||
recv_mss |= (NET_TCP_MSS_OPT << 24) | (NET_TCP_MSS_SIZE << 16); | ||
UNALIGNED_PUT(htonl(recv_mss), | ||
(u32_t *)(options + *optionlen)); | ||
|
||
*optionlen += NET_TCP_MSS_SIZE; | ||
|
@@ -1234,3 +1236,77 @@ struct net_buf *net_tcp_set_chksum(struct net_pkt *pkt, struct net_buf *frag) | |
|
||
return frag; | ||
} | ||
|
||
int net_tcp_parse_opts(struct net_pkt *pkt, int opt_totlen, | ||
struct net_tcp_options *opts) | ||
{ | ||
struct net_buf *frag = pkt->frags; | ||
u16_t pos = net_pkt_ip_hdr_len(pkt) | ||
+ net_pkt_ipv6_ext_len(pkt) | ||
+ sizeof(struct net_tcp_hdr); | ||
u8_t opt, optlen; | ||
|
||
/* TODO: this should be done for each TCP pkt, on reception */ | ||
if (pos + opt_totlen > net_pkt_get_len(pkt)) { | ||
NET_ERR("Truncated pkt len: %d, expected: %d", | ||
(int)net_pkt_get_len(pkt), pos + opt_totlen); | ||
return -EINVAL; | ||
} | ||
|
||
while (opt_totlen) { | ||
frag = net_frag_read(frag, pos, &pos, sizeof(opt), &opt); | ||
opt_totlen--; | ||
|
||
/* https://www.iana.org/assignments/tcp-parameters/tcp-parameters.xhtml#tcp-parameters-1 */ | ||
/* "Options 0 and 1 are exactly one octet which is their | ||
* kind field. All other options have their one octet | ||
* kind field, followed by a one octet length field, | ||
* followed by length-2 octets of option data." | ||
*/ | ||
if (opt == NET_TCP_END_OPT) { | ||
break; | ||
} else if (opt == NET_TCP_NOP_OPT) { | ||
continue; | ||
} | ||
|
||
if (!opt_totlen) { | ||
optlen = 0; | ||
goto error; | ||
} | ||
|
||
frag = net_frag_read(frag, pos, &pos, sizeof(optlen), &optlen); | ||
opt_totlen--; | ||
if (optlen < 2) { | ||
goto error; | ||
} | ||
|
||
/* Subtract opt/optlen size now to avoid doing this | ||
* repeatedly. | ||
*/ | ||
optlen -= 2; | ||
if (opt_totlen < optlen) { | ||
goto error; | ||
} | ||
|
||
switch (opt) { | ||
case NET_TCP_MSS_OPT: | ||
if (optlen != 2) { | ||
goto error; | ||
} | ||
frag = net_frag_read(frag, pos, &pos, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 *)&opts->mss); | ||
break; | ||
default: | ||
frag = net_frag_skip(frag, pos, &pos, optlen); | ||
break; | ||
} | ||
|
||
opt_totlen -= optlen; | ||
} | ||
|
||
return 0; | ||
|
||
error: | ||
NET_ERR("Invalid TCP opt: %d len: %d", opt, optlen); | ||
return -EINVAL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same here
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.
Along the discussion on IRC, I'm adding single check at the top of function.