大网数据广告活动
服务器运维问答

Can I trust a TCP segment with a payload of 255 bytes will be delivered in a single Ethernet frame?

· 52CE 我爱测

I'm writing some server software that upgrades the firmware on an electronic device. It's a tricky task, because currently these devices don't have enough memory to hold a full firmware before installing it. As a result my server…

问题原文

原帖链接 · mal · CC BY-SA 3.0

I'm writing some server software that upgrades the firmware on an electronic device. It's a tricky task, because currently these devices don't have enough memory to hold a full firmware before installing it. As a result my server will switch the device into boot loader mode, and instruct the boot loader what to do, sending instructions and firmware data over the network. As you can imagine, there are some potentially massive downsides to this.

What I'm concerned with at the moment, is whether or not a single TCP segment that I send will be divided up across multiple Ethernet frames?

Due to the nature of the boot loader, the maximum size payload I can send in a TCP segment is 255 bytes.

From grabbing packets in Wireshark, it seems like the Frame size for a frame containing one of my TCP segments is 309 bytes (2,472 bits), well within the range allowed according to the Wikipedia page on Ethernet Frames :

I'm currently trying to handle what happens if the connection to the device is severed. As things are now I have no trouble reestablishing a connection with a device, but what I want to be sure of is what happens after a connection is reestablished.

If I can be sure that each instruction will always be contained in a single Ethernet frame, and as such, will either be delivered or won't be delivered then happy days! I can look at the last instruction sent and figure out what to do then.

However, if there's a possibility that the instruction can be split across two Ethernet frames then I have a much bigger problem. I don't think it should happen, but it sometimes looks like it does when I'm testing.

Say I have issued a write command, and the boot loader is waiting for data to write, I send my TCP segment with 255 bytes and it gets split across two Ethernet frames. The first frame gets delivered but the second one doesn't. Now when I reconnect I have to figure out exactly how many bytes the boot loader has already received, which means I need to push dummy data and listen for a response. I'd really like to avoid that if possible.

Reading from the comments in this thread, it seems that IP packets smaller than 576 bytes (4,608 bits) won't be split up. Am I safe in assuming that this is always the case?

Actually, If it is split up, then the WiFi module shouldn't deliver the TCP segment until it has been re-assembled, isn't that correct? And it will be discarded if the connection is lost.

已采纳解答

原帖链接 · Daniel Nachtrub · CC BY-SA 3.0

In general it's very hard to control wether a packet get's split or not. You would need to get very deep on the stack actually - things like offloading TCP to hardware may also get into the way and create packets that are optimised for transportation.

But you're talking about a TCP connection - so there shouldn't be any issue if your connection has a short interrupt. If a single TCP packet get's split into multiple ethernet packets and your connection drops (for a short moment) in between the transmission of a single frame, TCP will retry to transmit the packet (which is part of the protocol).

Having a longer / detected disconnect, a much bigger issue will be the fact, that you can't just continue sending without reestablishing a new connection (which would need your device to support this) - setting up a new socket and sending to the same remote host without TCP syn/ack is propably not supported by any default stack.

Regarding your desired goal (if possible) i would recommend to have a proper way to handle interruptions during the firmware upgrade (like dual boot).

If this is not possible and you're not implementing your own TCP/IP stack, i just can recommend to disable any hardware accelation on your server (to prevent hardware from reassembling your packets) and disable nagle's alogorithm on your socket connection.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。