webrtc_sctp_param (webrtc v0.1.0)

View Source

SCTP TLV codec: INIT / INIT ACK parameters (RFC 9260 §3.3.2.1, RFC 3758, RFC 4820, RFC 5061, RFC 9653), RE-CONFIG parameters (RFC 6525 §4) and error causes (RFC 9260 §3.3.10).

All three share the same layout: a 16-bit type (or cause code), a 16-bit length that covers the 4 byte header and the value but not the padding, the value, then zero padding to a multiple of 4 bytes.

Decoding is strict and never raises: every length must be at least 4 and fit in the remaining bytes, the padding after each TLV is skipped (its content is ignored), a missing padding is accepted only after the last TLV, and 1 to 3 leftover bytes are an error. Fixed-size TLVs with the wrong length are errors. Unknown types are kept as {unknown_param, Type, Value} or {unknown_cause, Code, Value}, and encode back to the original TLV, so the caller can report them.

Error reasons: {bad_param, Type} for a parameter (INIT or RE-CONFIG) with a bad length or value, {bad_cause, Code} for an error cause, and trailing_bytes for leftover bytes that do not form a TLV.

Encoders pad every TLV with zero bytes. Values that do not fit their field (a value over 65531 bytes, an integer out of range) are caller bugs and raise.

INIT parameters, param():

  • {ipv4_address, inet:ip4_address()} (5), {ipv6_address, inet:ip6_address()} (6), {state_cookie, binary()} (7)
  • {unrecognized_param, binary()} (8), the raw unrecognized TLV(s)
  • {cookie_preservative, Ms} (9), {host_name, binary()} (11), {supported_address_types, [Type]} (12)
  • ecn_capable (16#8000), {zero_checksum_acceptable, Edmid} (16#8001), {padding, NBytes} (16#8005), {supported_extensions, [ChunkType]} (16#8008), forward_tsn_supported (16#C000)
  • {unknown_param, Type, Value}

RE-CONFIG parameters, reconf_param(): {out_reset, ReqSeq, RespSeq, SendersLastTsn, [Sid]} (13), {in_reset, ReqSeq, [Sid]} (14), {tsn_reset, ReqSeq} (15), {reconf_response, RespSeq, Result, undefined | {SendersNextTsn, ReceiversNextTsn}} (16), {add_out_streams, ReqSeq, N} (17), {add_in_streams, ReqSeq, N} (18), {unknown_param, Type, Value}.

Error causes, cause(): see the type below (RFC 9260 §3.3.10).

Summary

Functions

Decode the error causes of an ABORT or ERROR chunk.

Decode a sequence of INIT / INIT ACK parameters.

Decode the parameters of a RE-CONFIG chunk.

Encode error causes, each one padded.

Encode one parameter as a padded TLV.

Encode parameters, each one padded to a multiple of 4 bytes.

Encode RE-CONFIG parameters, each one padded.

What to do with a parameter type this endpoint does not understand (RFC 9260 §3.2.1, the upper two bits of the type): 00 stop processing further parameters, 01 stop and report, 10 skip and continue, 11 skip, continue and report.

Types

cause/0

-type cause() ::
          {invalid_stream, Sid :: u16()} |
          {missing_param, [Type :: u16()]} |
          {stale_cookie, Usec :: u32()} |
          out_of_resource |
          {unresolvable_address, binary()} |
          {unrecognized_chunk, binary()} |
          invalid_mandatory_param |
          {unrecognized_params, binary()} |
          {no_user_data, Tsn :: u32()} |
          cookie_while_shutting_down |
          {restart_new_addresses, binary()} |
          {user_abort, binary()} |
          {protocol_violation, binary()} |
          {unknown_cause, Code :: u16(), Value :: binary()}.

error_reason/0

-type error_reason() :: {bad_param, u16()} | {bad_cause, u16()} | trailing_bytes.

param/0

-type param() ::
          {ipv4_address, inet:ip4_address()} |
          {ipv6_address, inet:ip6_address()} |
          {state_cookie, binary()} |
          {unrecognized_param, binary()} |
          {cookie_preservative, u32()} |
          {host_name, binary()} |
          {supported_address_types, [u16()]} |
          ecn_capable |
          {zero_checksum_acceptable, Edmid :: u32()} |
          {padding, NBytes :: non_neg_integer()} |
          {supported_extensions, [0..255]} |
          forward_tsn_supported |
          {unknown_param, Type :: u16(), Value :: binary()}.

reconf_param/0

-type reconf_param() ::
          {out_reset, ReqSeq :: u32(), RespSeq :: u32(), SendersLastTsn :: u32(), [u16()]} |
          {in_reset, ReqSeq :: u32(), [u16()]} |
          {tsn_reset, ReqSeq :: u32()} |
          {reconf_response,
           RespSeq :: u32(),
           reconf_result(),
           undefined | {SendersNextTsn :: u32(), ReceiversNextTsn :: u32()}} |
          {add_out_streams, ReqSeq :: u32(), N :: u16()} |
          {add_in_streams, ReqSeq :: u32(), N :: u16()} |
          {unknown_param, Type :: u16(), Value :: binary()}.

reconf_result/0

-type reconf_result() ::
          success_nothing_to_do | success_performed | denied | error_wrong_ssn |
          error_request_in_progress | error_bad_sequence_number | in_progress |
          u32().

u16/0

-type u16() :: 0..65535.

u32/0

-type u32() :: 0..4294967295.

Functions

decode_causes(Bin)

-spec decode_causes(binary()) -> {ok, [cause()]} | {error, error_reason()}.

Decode the error causes of an ABORT or ERROR chunk.

decode_params(Bin)

-spec decode_params(binary()) -> {ok, [param()]} | {error, error_reason()}.

Decode a sequence of INIT / INIT ACK parameters.

decode_reconf_params(Bin)

-spec decode_reconf_params(binary()) -> {ok, [reconf_param()]} | {error, error_reason()}.

Decode the parameters of a RE-CONFIG chunk.

encode_causes(Causes)

-spec encode_causes([cause()]) -> binary().

Encode error causes, each one padded.

encode_param(P)

-spec encode_param(param()) -> binary().

Encode one parameter as a padded TLV.

encode_params(Params)

-spec encode_params([param()]) -> binary().

Encode parameters, each one padded to a multiple of 4 bytes.

encode_reconf_params(Params)

-spec encode_reconf_params([reconf_param()]) -> binary().

Encode RE-CONFIG parameters, each one padded.

unrecognized_param_action(Type)

-spec unrecognized_param_action(u16()) -> {stop | skip, Report :: boolean()}.

What to do with a parameter type this endpoint does not understand (RFC 9260 §3.2.1, the upper two bits of the type): 00 stop processing further parameters, 01 stop and report, 10 skip and continue, 11 skip, continue and report.