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: pkt: Compute TX payload data length #5038

Merged
merged 1 commit into from
Nov 24, 2017

Conversation

pfl
Copy link
Collaborator

@pfl pfl commented Nov 17, 2017

Compute the length of the TX payload that is transported in one IPv4 or IPv6 datagram taking into account UDP, ICMP or TCP headers in addition to any IPv6 extension headers added by RPL. The TCP implementation in Zephyr is known to currently carry at maximum 8 bytes of options. If the protocol is not known to the stack, assume that the application handles any protocol headers as well as the data. Also, if the net_pkt does not have a context associated, length check on the data is omitted when appending.

Although payload length is calculated also for TCP, the TCP MSS value is used as before.

Define IPv4 minimum MTU as 576 octets, See RFC 791, Sections 3.1. and 3.2.

Signed-off-by: Patrik Flykt patrik.flykt@intel.com

@pfl
Copy link
Collaborator Author

pfl commented Nov 17, 2017

This is definitely a Request For Comments patch, let's continue coding on monday when everybody is back. The IPv6 upper layer header should be stored in advance, i.e. when the extension header lengths are computed.

@nashif nashif added RFC Request For Comments: want input from the community and removed RFC Request For Comments: want input from the community labels Nov 18, 2017
@pfl
Copy link
Collaborator Author

pfl commented Nov 20, 2017

Need to compute header lengths already at packet allocation times, updated RFC patch accordingly.

Copy link
Collaborator

@tbursztyka tbursztyka left a comment

Choose a reason for hiding this comment

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

Maybe we should try to avoid adding another attribute to net_pkt

@@ -72,6 +72,8 @@ struct net_pkt {
struct net_linkaddr lladdr_src;
struct net_linkaddr lladdr_dst;

u16_t data_len; /* amount of payload data that can be added */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could be avoided, see below

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 . From my comment #119 (comment) :

As far as I can tell, for TX packet, net_pkt->appdatalen isn't used until packet construction is finished and ready to be sent. So, it can be used to cache "remaining data size in the packet" (initialized in net_pkt_get_tx()).

if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) {
data_len -= NET_ICMPH_LEN;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

all the code block here is not that much time/performance consuming so (see below)

*/
max_len = 0x10000;
max_len = pkt->data_len;
Copy link
Collaborator

Choose a reason for hiding this comment

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

it could anyway be called here everytime and available space would be computed from that minus current total length.

no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to remember the amount of space remaining so that two consecutive calls to net_pkt_append() succeed, unless there is another application data counter somewhere in the struct already?

Copy link
Member

Choose a reason for hiding this comment

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

As @pfl mentioned, we need to support the case where multiple append/insert calls are done, so the amount of bytes needs to be remembered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we know that: we can get the actual occupied length in the chain of net_buf.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What variables would we need to look at?

Copy link
Collaborator

@tbursztyka tbursztyka Nov 21, 2017

Choose a reason for hiding this comment

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

I thought the whole length of fragment list, net_buf_frags_len(pkt->frags), could help. But as the ll reserve part is badly managed for now, it won't work.

@jukkar
Copy link
Member

jukkar commented Nov 20, 2017

Briefly tested this with echo-server and http-server running in zephyr side. Seemed to work just fine. Will test more tomorrow.

@pfl
Copy link
Collaborator Author

pfl commented Nov 21, 2017

Coap tests succeed with the latest update.

if (IS_ENABLED(CONFIG_NET_UDP) && proto == IPPROTO_UDP) {
data_len -= NET_UDPH_LEN;

#if defined(CONFIG_NET_RPL_INSERT_HBH_OPTION)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about considering net_pkt_set_ipv6_ext_len() in case ipv6 and move away RPL check here. RPL setting this value when insert is success "net_pkt_set_ipv6_ext_len(pkt, ext_len + NET_RPL_HOP_BY_HOP_LEN);".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RPL has not yet set the ext header length when this function is called.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 21, 2017

Inspired by @jukkar's comment at #5015 (comment) :

It looks like #5038 could replace this (#5015) one, also then we would not need to have #5034 either.

I definitely appreciate this patch, the questions is its scope: #5015/#5034 were proposed as safe (IMHO) and acceptable workarounds to get the 1.10 out. This patch is a bigger changes in itself, and based on the comments, there're various things which could be tweaked/improved. Up to @jukkar / @tbursztyka then whether this could fit into 1.10. (A possible compromise might be merge mostly as is as long as it works, and leave further refactors/optimizations until new merge window opens).

@pfl
Copy link
Collaborator Author

pfl commented Nov 21, 2017

Commit message and its header updated, unnecessary setting variable value on initialization removed.

@jukkar jukkar added this to the v1.10.0 milestone Nov 22, 2017
@pfl pfl changed the title RFC: Compute IP payload length net: pkt: Compute payload data length Nov 23, 2017
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 have been testing this and everything has been working just fine so +1 from me.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 23, 2017

Ok, if this is considered for merging, I'd like to ask to update the commit message to explicitly state that the change is for TX packets. E.g., the title can be (at the very least) net: pkt: Compute TX payload data length (better net: pkt: Compute payload data length for TX packets), and corresponding additions in the commit description body.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 23, 2017

More of commit message:

TCP is known to carry at maximum 8 bytes of options.

Well, that's to broad a statement to make. The TCP (RFC 793) definitely can carry more than 8 bytes of options. We have the NET_TCP_MAX_OPT_SIZE define with a random value, apparently inherited from FNET, removing of which (FNET cruft) is on my TODO.

So, suggestion: keep the code as is (as it's just first iteration of the matter, will be refactoring/optimizing it later based on all suggestions), but remove that sentence from the commit message.

I'd even ask why all that is at all relevant for the TCP case, if

TCP payload length is not changed, TCP MSS is used as before.

But don't let me go that rabbit hole, again, pretty good for the first iteration.

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

I'd really appreciate the commit message changes as suggested above, to not create unneeded confusion. Thanks.

@pfl
Copy link
Collaborator Author

pfl commented Nov 23, 2017

Well, that's to broad a statement to make. The TCP (RFC 793) definitely can carry more than 8 bytes of options.

This patch relates to Zephyr's implementation of TCP, so that is an accurate statement to make, actually.

I'd even ask why all that is at all relevant for the TCP case, if

It is relevant, since it computes lengths already for the TCP case, even though tcp->mss is still being used. That again is for another patch, but not for 1.10, since no release critical bugs are reported for TCP right now. TCP works fine, AFAIK by glancing at Jukka's screen where he's sending and receiving something continuosly.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 23, 2017

This patch relates to Zephyr's implementation of TCP, so that is an accurate statement to make, actually.

As an outside reader, I find the phrase "TCP is known to carry at maximum 8 bytes of options." to be highly ambiguous/confusing, that's why I ask that to be dealt with.

@jukkar jukkar removed the RFC Request For Comments: want input from the community label Nov 23, 2017
Compute the length of the TX payload that is transported in one
IPv4 or IPv6 datagram taking into account UDP, ICMP or TCP
headers in addition to any IPv6 extension headers added by RPL.
The TCP implementation in Zephyr is known to currently carry at
maximum 8 bytes of options. If the protocol is not known to the
stack, assume that the application handles any protocol headers
as well as the data. Also, if the net_pkt does not have a
context associated, length check on the data is omitted when
appending.

Although payload length is calculated also for TCP, the TCP MSS
value is used as before.

Define IPv4 minimum MTU as 576 octets, See RFC 791, Sections 3.1.
and 3.2.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
@pfl
Copy link
Collaborator Author

pfl commented Nov 23, 2017

Updated commit message.

@pfl pfl changed the title net: pkt: Compute payload data length net: pkt: Compute TX payload data length Nov 23, 2017
Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

Thanks!

@pfl
Copy link
Collaborator Author

pfl commented Nov 24, 2017

AFAIK, together with the already merged #5072, this PR fixes #4934, and obsoletes #5034, #4972 and #5015.

@nashif nashif merged commit 753daa6 into zephyrproject-rtos:master Nov 24, 2017
@pfalcon
Copy link
Contributor

pfalcon commented Nov 24, 2017

Thanks for merging.

AFAIK, together with the already merged #5072, this PR fixes #4934, and obsoletes #5034, #4972 and #5015.

@jukkar closed #4972, and I closed #5015 & #5034.

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.

6 participants