[Share Experiences] Deepin下tftp客户端传送升级文件失败问题分析
Tofloor
poster avatar
wangxinyu
deepin
2022-02-26 20:29
Author

一, 安装过程

使用 sudo apt-get install tftpd-hpa 命令下载tftp服务端

使用 sudo apt-get install tftp-hpa 命令下载客户端

二,使用中的问题

开始通过tftp 客户端向服务器传送文件升级,发现设备升级不成功,分析为数据异常。

三,问题分析

于是进行了抓包分析

截图_选择区域_20220226093218.png

从图上可以看出,传输过程中,tftp client 为数据增加了00操作。即为0d后面多了一个00。

默认传输模式为netascii

tftp> mode

Using netascii mode to transfer files.

tftp>

修改为binary后,可以进学传输

tftp> binary

tftp> mode

Using octet mode to transfer files.

tftp>

| netascii | 文本传输模式,按照一个字节8位解析 | 文本模式 |
| octet | 二进制模式,数据无需解析 | 二进制模式 |
| mail | 已过时,不使用 | 已过时 |

tftp -m binary 192.168.1.6 -c put RTK0_MAGIC_upgradefile.bin

四,深入源码

windows下tftpd32程序,同样配置为netascii模式,但没有问题,那至到底实现上差异在哪里呢, 必须的深入源码

apt list tftp

正在列表... 完成

tftp/未知 0.17-22 amd64

tftp/未知 0.17-22 i386

参考源码 https://mirrors.edge.kernel.org/pub/software/network/tftp/

实现:(还是看代码直接且舒服) 原因是将OD(cr)转换为 cr 00 。

截图_选择区域_20220226110353.png

RFC参考

https://www.rfc-editor.org/rfc/rfc1350.txt

资料参考

https://oomake.com/question/1831481

A host which receives netascii mode data must translate the data to its own format.

例如,使用EBCDIC作为其本机编码的主机可能会将netascii转换为该编码,但会单独留下“八位字节”数据。 如果您在使用LF进行行结束的Unix(或其他)系统上实现TFTP服务器,则需要为netascii传输添加CR(以及将文件中的实际CR字符转换为CR / NUL)序列。

windows下tftpd32程序, 对于模式没有额外配置,表现为netascii模式,实际均为binary (octet),所以以前没有出过这样的问题

Reply Favorite View the author
All Replies
心平气和
deepin
2022-02-26 20:49
#1

好久在论坛没看到这种硬核的技术文章了,大赞!kissing_heart

Reply View the author
babyfengfjx
Super Moderator
CQA
2022-02-26 21:35
#2
  • 我去,我表示两手颤抖,双脚不稳;
  • 就看那个抓包已经大脑空白😂
Reply View the author
andktan
deepin
2022-02-26 23:36
#3

like

Reply View the author
kingskill
deepin
2022-09-29 07:50
#4

全网转了一圈,最后在这个硬核基础知识这里找到了答案。。。

Reply View the author