跳到主要内容

2.0 UDP 编码: TACACS

本节描述刚刚所述请求的 UDP 编码.它也描述响应.这种 UDP 编码构成了历史上的 TACACS 协议的基础.

该协议使用端口 49.这一分配继续得到 IANA 在 Assigned Numbers RFC 中的确认.(我不能说它是由 IANA 分配的, 因为该分配早于该组织.)

基本报文格式如下所示.所有多字节值均采用网络字节序.除非另有说明, 所有给出的值都是十进制.未使用的字段应置零, 但接收方不应依赖于该设置.

如前所述, 存在简单形式和扩展形式, 其中简单形式是扩展形式的真子集.服务器应同时支持这两种形式.我将并行描述这两种形式.

简单形式

字段如下:

offset length field

      0    1       version
1 1 type
2 2 nonce value
4 1 username length (to server) / response (to client)
5 1 password length (to server) / reason (to client)

以通常的报文布局格式表示:

    0                   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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Version : Type : Nonce :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: User len/Resp : PW len/Reason : data... :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

扩展形式

字段如下:

offset length field

           0       1       version
1 1 type
2 2 nonce value
4 1 username length
5 1 password length
6 1 response
7 1 reason
8 4 result1
12 4 destination host, IP address
16 2 destination port
18 2 line
20 4 result2
24 2 result3
26 varies data: username + password

以通常的报文布局格式表示:

    0                   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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Version : Type : Nonce :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: User len : Password len : Response : Reason :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Result 1 :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Destination Address :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Dest Port : Line :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Result 2 :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: Result 3 : data... :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

2.1. 字段​

VERSION 字段指定版本号.简单形式中它必须为零, 扩展形式中为 128 (十六进制 80).

TYPE 字段对请求类型进行编码.取值如下:

           LOGIN           1
RESPONSE 2 (server to client only)
CHANGE 3
FOLLOW 4
CONNECT 5
SUPERUSER 6
LOGOUT 7
RELOAD 8
SLIPON 9
SLIPOFF 10
SLIPADDR 11

低于 128 的其他值保留供将来使用.从 128 到 255 的值保留供本地使用.

请注意, CHANGE,FOLLOW,RELOAD 请求的语义尚未确定.

NONCE 字段由客户端设置为任意值.其目的是使可能有多个未完成请求的客户端能够确定某个响应对应于哪个请求.服务器必须原样将该值复制到回复中.

USERNAME LENGTH 字段由客户端设置为用户名长度 (以字符计).合法值为 0 到 255 (含两端).服务器必须原样将该值复制到回复中.

PASSWORD LENGTH 由客户端设置为口令长度 (以字符计).合法值为 0 到 255 (含两端).服务器必须原样将该值复制到回复中.

RESPONSE 字段应由客户端置零.服务器将该值设置为以下之一:

value meaning

           1       accepted
2 rejected

低于 128 的其他值保留供将来使用.从 128 到 255 的值保留供本地使用.

REASON 字段应由客户端置零, 但 LOGOUT 和 SLIPOFF 请求除外, 它们可以使用 4,5 或 6.服务器将该值设置为以下之一:

value meaning notes

           0       none            used for ACCEPTED or if the server
is ornery
1 expiring
2 password
3 denied
4 quit user quit normally
5 idle idle timeout
6 drop carrier dropped
7 bad too many bad passwords

从 4 到 6 的值将仅用作 LOGOUT 或 SLIPOFF 请求的原因: 服务器不会返回这些值.低于 128 的其他值保留供将来使用.从 128 到 255 的值保留供本地使用.

RESULT1 字段应由客户端置零.对于 LOGIN 或 CONNECT 请求, 服务器按请求描述中的规定设置该字段.对于所有其他请求, 服务器应将其置零.

DESTINATION HOST 字段由客户端设置.在 CONNECT,SLIPON 和 SLIPOFF 请求中, 它指定一个 IP 地址.在所有其他请求中应将其置零.对于 SLIPON 和 SLIPOFF 请求, 该值应为分配给该线路的 IP 地址.对于 CONNECT 请求, 该值是用户试图连接的主机的 IP 地址.服务器将该值复制到回复中.

DESTINATION PORT 字段由客户端设置.在 CONNECT 请求中, 它指定用户试图连接的端口号.在所有其他请求中应将其置零.服务器将该值复制到回复中.

LINE 字段由客户端设置为该请求所针对的线路号.服务器将该值复制到回复中.

RESULT2 字段应由客户端置零.对于 LOGIN 或 CONNECT 请求, 服务器按请求描述中的规定设置该字段.对于所有其他请求, 服务器应将其置零.

RESULT3 字段应由客户端置零.对于 LOGIN 或 CONNECT 请求, 服务器按请求描述中的规定设置该字段.对于所有其他请求, 服务器应将其置零.

DATA 字段只包含用户名和口令的文本, 没有分隔符 (你要用 username length 和 password length 来区分它们).服务器不会将这些值复制到回复中.(不过, 服务器确实会将 username length 和 password length 字段复制到回复中.) 用户名数据可能是大写的: 比较时应不区分大小写.

2.2. 客户端做什么​

客户端必须格式化一个 UDP 请求并发送到端口 49.它按以下步骤构造请求:

           - set the version to 128
- set the type to that of the request
- set the nonce to a unique value that is different from all
outstanding requests
- set the username length
- set the password length
- set the response to zero
- set the reason to zero (except for LOGOUT and SLIPOFF)
- set the result1 to zero
- if CONNECT, SLIPON, or SLIPOFF, set the destination address
to the IP address, otherwise set it to zero
- if CONNECT, set the destination port to the port, otherwise
set it to zero
- set the line
- set the result2 to zero
- set the result3 to zero
- copy the username to the location just after result3
- copy the password to the location just after the end of the
username

发送请求.等待一段合理的时间 (并希望是可配置的).如果没有收到响应, 则重试合理的次数 (并希望是可配置的).合理的默认等待时间为 5 秒, 重试次数为 2.

如果收到了响应, 就用 nonce 值 (以及你喜欢的任意多个其他字段) 将其与某个未完成请求相匹配.如果没有匹配的未完成请求, 就采取适当的行动 (并希望是可配置的), 例如丢弃和/或记录该报文.

如果响应与某个未完成请求匹配, 就检查 response 和 reason 代码, 并采取你认为正确的任何行动.对于 LOGIN 和 CONNECT 请求的响应, 还要按你认为正确的方式纳入 result1,result2 和 result3 的值.

2.3. 服务器做什么​

收到 UDP 格式的请求后, 服务器检查请求报文中的数据并确定其响应.它按以下步骤构造回复:

           - set the version to 128
- set the type to RESPONSE (2)
- copy the nonce value
- copy the username length value
- copy the password length value
- set the response value to the desired response
- set the reason value to the desired reason
- if LOGIN or CONNECT, set the result1 else zero the result1
- copy the destination host value
- copy the destination port value
- copy the line value
- if LOGIN or CONNECT, set the result2 else zero the result2
- if LOGIN or CONNECT, set the result3 else zero the result3
- do NOT copy the username or password data

(一如既往, 对收到的内容要宽容, 对发送的内容要保守.) 发送响应.不要尝试重试, 因为你没有依据判断是否需要重试.是否重试完全由客户端决定.当然, 这意味着请求是幂等的.而它们当然不是幂等的, 因此在尝试将请求组装成连接时必须考虑重试.