Boost.Socks Logo

PrevUpHomeNext

UDP Associate

A UDP ASSOCIATE request is used to create an association to handle UDP datagrams. Analogous to a CONNECT request, the DST.ADDR and DST.PORT fields in the request determine the application server the client expects to use to send UDP datagrams.

UDP Associate Request

The following UDP ASSOCIATE request should be encapsulated according to the authentication method with the following format:

+----+-----+-------+------+----------+----------+
|VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
+----+-----+-------+------+----------+----------+
  1     1    `0x00`    1     Variable      2

where:

  1. VER: 0x05 SOCKS protocol version number
  2. CMD: Command code 0x03 for BIND request
  3. RSV: RESERVED
  4. ATYP: Destination address type
  5. DST.ADDR: Destination address
  6. DST.PORT: Destination port

If the client is not in possession of DST.ADDR and DST.PORT at the time the UDP ASSOCIATE request is create, it MUST use a port number and address of all zeros.

[Note] Note

The UDP ASSOCIATE command is not available in the SOCKS Protocol Version 4.

UDP Associate Reply

A reply packet is sent to the client to inform about the connection status. Two replies are sent from the SOCKS server to the client when:

  1. The server creates and binds a new socket
  2. The incoming connection succeeds or fails
+----+-----+-------+------+----------+----------+
|VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
+----+-----+-------+------+----------+----------+
  1     1    `0x00`    1     Variable      2

where:

  1. VER: SOCKS Protocol Version: 0x05
  2. REP: Reply field
  3. RSV: RESERVED (0x00)
  4. ATYP: Address type
  5. BND.ADDR: Server bound address
  6. BND.PORT: Server bound port

The code REP might have one of the following values:

  1. 0x00: succeeded
  2. 0x01: general SOCKS server failure
  3. 0x02: connection not allowed by ruleset
  4. 0x03: Network unreachable
  5. 0x04: Host unreachable
  6. 0x05: Connection refused
  7. 0x06: TTL expired
  8. 0x07: Command not supported
  9. 0x08: Address type not supported
  10. 0x09 to 0xFF unassigned

When a reply from the SOCKS server indicates a failure, the SOCKS server MUST terminate the TCP connection immediately after sending the reply.

If the reply is successful, the UDP is valid for as long as the TCP connection on which the UDP ASSOCIATE request arrived.

UDP datagrams

The fields BND.ADDR and BND.PORT indicate the port number and address where the client MUST send UDP requests to the application server. If the selected authentication method provides encapsulation, the datagrams MUST be encapsulated using the method.

Each UDP datagram from the client or the server should carry a UDP request header in the following format:

+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
+----+------+------+----------+----------+----------+
  2     1      1     Variable      2       Variable

where:

  1. RSV: Reserved X'0000'
  2. FRAG: Current fragment number
  3. ATYP: Address type
  4. DST.ADDR: Desired destination address
  5. DST.PORT: Desired destination port
  6. DATA: User data

The field FRAG indicates whether this is one of a series of datagrams.

  1. The high-order bit indicates end-of-fragment sequence.
  2. The value 0x00 indicates the datagram is standalone
  3. Values between 1 and 127 indicate the fragment position in a sequence

A reassembly queue and timer of no less than 5 seconds should be associated with the fragments, and the queue should be reinitialized when:

  1. The reassembly timer expires, or
  2. A new FRAG field whose value is less than the highest FRAG in the queue

Fragmentation should be avoided whenever possible, and their implementation is optional. If fragmentation is not supported, the SOCKS server should drop any datagram whose FRAG is other than 0x00.

The SOCKS server relays UDP datagrams silently without notifications to the client. The server is also allowed to drop datagrams it cannot or will not relay. The server MUST drop datagrams from any source other than the client.


PrevUpHomeNext