masque_udp_bind_payload (masque v0.7.0)
View SourceEncode/decode the inner Bound UDP Proxying Payload, the bytes that follow the HTTP Datagram Context ID. Per draft-ietf-masque-connect-udp-listen-11 sections 4 (uncompressed) and 5 (compressed):
- Compressed form: the payload is the UDP payload bytes only. The peer tuple is implicit in the receiver's compression-table entry for the Context ID the datagram arrived on.
- Uncompressed form:
IP Version (8) || IP Address (32 or 128) || UDP Port (16) || UDP Payload (..). Network byte order. IP Version is 4 or 6 (IP Version 0 is used inCOMPRESSION_ASSIGNto *register* the uncompressed channel, but the on-wire payloads on it carry a real 4 or 6 here).
This module never sees the Context ID; that is consumed by masque_datagram one layer above. The session is responsible for looking the Context ID up in its compression table and dispatching to the right shape (compressed vs uncompressed) based on the registered IP Version of the entry.
Pure module - no I/O, no state. Address-family gating is enforced on encode using the advertised public-address families.
Summary
Functions
Decode a compressed payload (just the UDP bytes). Trivial; provided for symmetry with decode_uncompressed/1.
Decode an uncompressed payload into the carried peer tuple and the inner UDP bytes.
Encode a payload onto a compressed Context ID. The IP-port tuple is implicit (the receiver looks it up in its table). Caller is expected to have verified the family is advertised via family_advertised/2 before invoking this.
Encode a payload onto an uncompressed Context ID. The peer tuple is carried inline. Address family must be in the advertised list.
Returns true iff the given IP version is in the advertised list. Both encode paths consult this, and the session uses it on incoming uncompressed payloads to drop those whose family is not advertised (e.g. a peer reaching us over an IPv4-only proxy with an IPv6 source somehow set).
Types
Functions
Decode a compressed payload (just the UDP bytes). Trivial; provided for symmetry with decode_uncompressed/1.
-spec decode_uncompressed(binary()) -> {ok, {4 | 6, inet:ip_address(), inet:port_number()}, binary()} | {error, decode_error()}.
Decode an uncompressed payload into the carried peer tuple and the inner UDP bytes.
Encode a payload onto a compressed Context ID. The IP-port tuple is implicit (the receiver looks it up in its table). Caller is expected to have verified the family is advertised via family_advertised/2 before invoking this.
-spec encode_uncompressed({4 | 6, inet:ip_address(), inet:port_number()}, binary(), families()) -> {ok, binary()} | {error, encode_error()}.
Encode a payload onto an uncompressed Context ID. The peer tuple is carried inline. Address family must be in the advertised list.
Returns true iff the given IP version is in the advertised list. Both encode paths consult this, and the session uses it on incoming uncompressed payloads to drop those whose family is not advertised (e.g. a peer reaching us over an IPv4-only proxy with an IPv6 source somehow set).