SNTP4协议说明

简介

本文使用协议为SNTPv4.

SNTP(Simple Network Time Protocal简单网络时间协议),用于跨广域网或局域网同步时间的协议,具有较高的精确度(几十毫秒)。官方文档为RFC 4330,2006年的最新版本为SNTPv4,比前面的版本增加了对IPV6的支持,此外还新增了一个Kiss-o’-Death(KoD)报文。

SNTPv4是NTP(Network Time Protocol网络时间协议)的简化版,精度较低,安全机制较低,但是报文格式完全一致。

SNTPv4使用的是UDP 123端口,C/S模式,有单播,多播和广播三种报文发送方式。

报文结构

基本结构

SNTP4基于UDP网络,报文结构如下:

MACIPUDPNTP

其中NTP的报文结构如下:

                           1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9  0  1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |LI | VN  |Mode |    Stratum    |     Poll      |   Precision    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                          Root  Delay                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                       Root  Dispersion                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                     Reference Identifier                       |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                                |
      |                    Reference Timestamp (64)                    |
      |                                                                |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                                |
      |                    Originate Timestamp (64)                    |
      |                                                                |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                                |
      |                     Receive Timestamp (64)                     |
      |                                                                |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                                |
      |                     Transmit Timestamp (64)                    |
      |                                                                |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                 Key Identifier (optional) (32)                 |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                                |
      |                                                                |
      |                 Message Digest (optional) (128)                |
      |                                                                |
      |                                                                |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                        Figure 1.  NTP Packet Header

字段说明

字段含义长度说明
LI闰秒标志2比特见Figure 2
VN版本号3比特表示NTP的版本号,当前为4
Mode模式3比特见Figure 3,一般服务端发送的报文模式值为4
Stratum1字节unsigned char见Figure 4,对本地时钟级别的整体识别
Poll轮询间隔1字节无符号正数指示数据包的最大时间间隔,以秒为单位,作为2的指数方的指数部分,取值范围从4-17,即16秒到131,072秒
Precision精度1字节有符号正数指示系统时钟的精确性,以秒为单位,作为2的指数方的指数部分,取值范围从-6到-20
Root Delay往返延迟4字节浮点数指示与主时钟参考源的总共往返延迟,以秒为单位,小数部分在16位以后,取值范围从负几毫秒到正几百毫秒
Root Dispersion误差4字节浮点数指示与主时钟参考源的误差,以秒为单位,小数部分在16位以后,取值范围从零毫秒到正几百毫秒
Reference Identifier时钟参考源4字节ASCII字符串见Figure 5 ,对于二级服务器,在IPV4环境下,取值为一级服务器的IP地址,在IPV6环境下,是一级服务器的NSAP地址
Reference Timestamp校准时间8字节时间戳见Figure 6,指示系统时钟最后一次校准的时间,建议填充非重要的低阶位随机值,便于环路检测与回放检测
Originate Timestamp原始时间8字节时间戳指示客户向服务器发起请求的时间
Receive Timestamp接收时间8字节时间戳指服务器收到客户请求的时间
Transmit Timestamp传输时间8字节时间戳指示服务器向客户发时间戳的时间
Authenticator认证160字节可选当需要进行SNTP认证时,该字段包含密钥和信息加密码

Figure 2 LI

0:无警告1:最后一分钟是61秒;
2:最后一分钟是59秒;3:警告(时钟没有同步)

Figure 3 Mode

0:保留1:对称主动2:对称被动3:客户
4:服务器5:广播6:保留为NTP控制信息7:保留为用户定义

Figure 4 Stratum

Stratum值含义
0kiss-o’-death(比较重要,见2.4),表示故障信息
1一级服务器(由radio clock同步)
2-15二级服务器(由NTP和SNTP同步)
16-255保留

Figure 5 Reference Identifier Codes

CodeExternal Reference Source含义
LOCLuncalibrated local clock未校准的本地时钟
CESMcalibrated Cesium clock校准铯钟
RBDMcalibrated Rubidium clock校准铷钟
PPScalibrated quartz clock or other pulse-per-second source校准石英钟或其他脉冲每秒源
IRIGInter-Range Instrumentation Group跨系列仪表组
ACTSNIST telephone modem serviceNIST(美国国家标准)电话调制解调器服务
USNOUSNO telephone modem serviceUSNO(美国海军天文台)电话调制解调器服务
PTBPTB (Germany) telephone modem servicePTB(德国)电话调制解调器服务
TDFAllouis (France) Radio 164 kHzAllouis(法国)无线电 164 kHz
DCFMainflingen (Germany) Radio 77.5 kHzMainflingen(德国)无线电 77.5 kHz
MSFRugby (UK) Radio 60 kHzRugby(英国)无线电 60 kHz
WWVFt. Collins (US) Radio 2.5, 5, 10, 15, 20 MHzFt. Collins(美国)无线电 2.5、5、10、15、20 MHz
WWVBBoulder (US) Radio 60 kHz博尔德(美国)无线电 60 kHz
WWVHKauai Hawaii (US) Radio 2.5, 5, 10, 15 MHz夏威夷考艾岛(美国)无线电 2.5、5、10、15 MHz
CHUOttawa (Canada) Radio 3330, 7335, 14670 kHz渥太华(加拿大)无线电 3330、7335、14670 kHz
LORCLORAN-C radionavigation systemLORAN-C无线电导航系统
OMEGOMEGA radionavigation system欧米茄无线电导航系统
GPSGlobal Positioning Service全球定位服务
                           1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                           Seconds                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                  Seconds Fraction (0-padded)                  |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      
                     Figure 6  NTP Timestamp Format

request报文

上述字段中如果是客户端发的报文,那么绝大部分是0;如果是服务端发的报文,大部分字段才有意义。

LI,Stratum, Precision, Root Delay, Root Dispersion, Reference Identifier, Reference Timestamp 等都只在服务端有效。

下面是不同传输方式下的字段值示例

Field NameUnicast/ManycastBroadcast
RequestReply
LIignoreas neededas needed
VN1-4copied from request4
Mode345
Stratumignore11
Pollignorecopied from requestlog2 poll interval
Precisionignore-log2 server significant bits-log2 server significant bits
significantsignificant
Root Delayignore00
Root Dispersionignore00
Reference Identifierignoresource identsource ident
Reference Timestampignoretime of last source updatetime of last source update
Originate Timestampignorecopied from transmit timestamp0
Receive Timestampignoretime of day0
Transmit Timestamp(see text)time of daytime of day
Authenticatoroptionaloptionaloptional

Kiss-o’-Death

KoD是一种特殊的报文,用于组织客户端发送请求。当网络拥堵或者出现恶意攻击时需要产生该报文。该报文为SNTP版本4所特有。

一般情况下Stratum字段为1,表示以及服务器,后面的Reference Identifier表示时钟来源;KoD报文Stratum字段为0,后面的Reference Identifier成为kiss codes,表示终止原因。具体的code如下:

CodeMeaning说明
ACSTThe association belongs to a anycast server连接属于任意播服务器
AUTHServer authentication failed服务器认证失败
AUTOAutokey sequence failed自动键序列失败
BCSTThe association belongs to a broadcast server关联属于广播服务器
CRYPCryptographic authentication or identification failed密码验证或识别失败
DENYAccess denied by remote server远程服务器拒绝访问
DROPLost peer in symmetric mode在对称模式下丢失对等点
RSTRAccess denied due to local policy由于本地策略访问被拒绝
INITThe association has not yet synchronized for the first time第一次关联还没有同步
MCSTThe association belongs to a manycast server关联属于多播服务器
NKEYNo key found. Either the key was never installed or is not trusted未找到密钥。密钥从未安装或不可信
RATERate exceeded. The server has temporarily denied access because client exceeded the rate threshold速率过大。服务器暂时拒绝访问
RMOTSomebody is tinkering with the association from a remote host running ntpdc. Not to worry unless some rascal has stolen your keys有人在远程修改关联
STEPA step change in system time has occurred but the association has not yet resynchronized系统时间发生了阶跃变化,但关联尚未重新同步
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值