-
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: pkt: Compute TX payload data length #5038
Conversation
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. |
Need to compute header lengths already at packet allocation times, updated RFC patch accordingly. |
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.
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 */ |
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 could be avoided, see below
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.
+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; | ||
} | ||
|
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.
all the code block here is not that much time/performance consuming so (see below)
subsys/net/ip/net_pkt.c
Outdated
*/ | ||
max_len = 0x10000; | ||
max_len = pkt->data_len; |
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 could anyway be called here everytime and available space would be computed from that minus current total length.
no?
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.
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?
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.
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.
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.
But we know that: we can get the actual occupied length in the chain of net_buf.
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.
What variables would we need to look at?
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 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.
Briefly tested this with echo-server and http-server running in zephyr side. Seemed to work just fine. Will test more tomorrow. |
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) |
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.
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);".
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.
RPL has not yet set the ext header length when this function is called.
Inspired by @jukkar's comment at #5015 (comment) :
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). |
Commit message and its header updated, unnecessary setting variable value on initialization removed. |
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 have been testing this and everything has been working just fine so +1 from me.
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) |
More of commit message:
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
But don't let me go that rabbit hole, again, pretty good for the first iteration. |
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'd really appreciate the commit message changes as suggested above, to not create unneeded confusion. Thanks.
This patch relates to Zephyr's implementation of TCP, so that is an accurate statement to make, actually.
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. |
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. |
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>
Updated commit message. |
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.
Thanks!
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