Module _sctp.sctp_event

Functions

_sctp.sctp_event.parse_notification(notif)
Parameters:

notif (bytes)

Returns:

notif as a dictionary

Raises:

OSError TypeError

Let’s look at an example of how to use this function. First, you must subscribe to the desired notification, let’s say SCTP_SENDER_DRY_EVENT:

>>> sock = sctp_socket(AF_INET6, SOCK_SEQPACKET)
...
>>> event = sctp_event(se_assoc_id=3, se_type=SCTP_SENDER_DRY_EVENT, se_on=1)
>>> sock.setsockopt(IPPROTO_SCTP, SCTP_EVENT, event)

Then, when receiving data:

>>> data, addr, info, infotype, flags = sock.sctp_recvv(1024)
>>> if flags & MSG_NOTIFICATION: print(parse_notification(data))
{'sn_type': 32777, 'sender_dry_flags': 0, 'sender_dry_assoc_id': 3}

Note

If you have subscribed to multiple notifications, discrimination will be based on the 'sn_type' field, common to all notifications. In the example above, the field indicating the type is named 'sn_type' and not 'sender_dry_type'. The same applies to all other notifications:

>>> notif = parse_notification(data)
>>> if notif['sn_type'] == SCTP_SENDER_DRY_EVENT:
........ # do something
>>> elif notif['sn_type'] == SCTP_ASSOC_CHANGE:
........ # do something else

Constants

This module export the following constants:

_sctp.sctp_event.MSG_NOTIFICATION

SCTP Socket Options

SCTP_EVENT Option (see RFC 6458 – section-6.6.2):

_sctp.sctp_event.SCTP_EVENT

Notifications

SCTP_ASSOC_CHANGE (see RFC 6458 – section-6.1.1):

  • _sctp.sctp_event.SCTP_ASSOC_CHANGE

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'sac_flags', 'sac_state', 'sac_error', 'sac_outbound_streams', 'sac_inbound_streams', 'sac_assoc_id'.

    'sac_state':

    • _sctp.sctp_event.SCTP_COMM_UP
    • _sctp.sctp_event.SCTP_COMM_LOST
    • _sctp.sctp_event.SCTP_RESTART
    • _sctp.sctp_event.SCTP_SHUTDOWN_COMP
    • _sctp.sctp_event.SCTP_CANT_STR_ASSOC

    The 'sac_info' key may be present in the following two cases:

    1. If 'sac_state' is SCTP_COMM_LOST and an ABORT chunk was received for this association, 'sac_info' contains the complete ABORT chunk as a bytes object.

    2. If 'sac_state' is SCTP_COMM_UP or SCTP_RESTART, 'sac_info' is a tuple of integers in range [0-255] (uint8_t). These integers can have the following values:

      • _sctp.sctp_event.SCTP_ASSOC_SUPPORTS_PR
      • _sctp.sctp_event.SCTP_ASSOC_SUPPORTS_AUTH
      • _sctp.sctp_event.SCTP_ASSOC_SUPPORTS_ASCONF
      • _sctp.sctp_event.SCTP_ASSOC_SUPPORTS_MULTIBUF

      Warning

      Previous constants are only defined in FreeBSD not in Linux.

SCTP_PEER_ADDR_CHANGE (see RFC 6458 – section-6.1.2):

  • _sctp.sctp_event.SCTP_PEER_ADDR_CHANGE

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'spc_flags', 'spc_aaddr', 'spc_state', 'spc_error' and 'spc_assoc_id'.

    'spc_state':

    • _sctp.sctp_event.SCTP_ADDR_AVAILABLE
    • _sctp.sctp_event.SCTP_ADDR_UNREACHABLE
    • _sctp.sctp_event.SCTP_ADDR_REMOVED
    • _sctp.sctp_event.SCTP_ADDR_ADDED
    • _sctp.sctp_event.SCTP_ADDR_MADE_PRIM

SCTP_REMOTE_ERROR (see RFC 6458 – section-6.1.3):

  • _sctp.sctp_event.SCTP_REMOTE_ERROR

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'sre_flags', 'sre_error' and 'sre_assoc_id'.

    Note

    'sre_error' is in host byte order.

SCTP_SHUTDOWN_EVENT (see RFC 6458 – section-6.1.5):

  • _sctp.sctp_event.SCTP_SHUTDOWN_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'sse_flags' and 'sse_assoc_id'.

SCTP_ADAPTATION_INDICATION (see RFC 6458 – section-6.1.6):

  • _sctp.sctp_event.SCTP_ADAPTATION_INDICATION

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'sai_flags', 'sai_adaptation_ind' and 'sre_assoc_id'.

SCTP_PARTIAL_DELIVERY_EVENT (see RFC 6458 – section-6.1.7):

  • _sctp.sctp_event.SCTP_PARTIAL_DELIVERY_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'pdapi_flags', 'pdapi_indication', 'pdapi_stream', 'pdapi_seq' and 'pdapi_assoc_id'.

    'pdapi_indication':

    • _sctp.sctp_event.SCTP_PARTIAL_DELIVERY_ABORTED

SCTP_AUTHENTICATION_EVENT (see RFC 6458 – section-6.1.8):

  • _sctp.sctp_event.SCTP_AUTHENTICATION_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'auth_flags', 'auth_keynumber', 'auth_indication' and 'auth_assoc_id'.

    'auth_indication':

    • _sctp.sctp_event.SCTP_AUTH_NEW_KEY
    • _sctp.sctp_event.SCTP_AUTH_NO_AUTH
    • _sctp.sctp_event.SCTP_AUTH_FREE_KEY

SCTP_SENDER_DRY_EVENT (see RFC 6458 – section-6.1.9):

  • _sctp.sctp_event.SCTP_SENDER_DRY_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type', 'sender_dry_flags' and 'sender_dry_assoc_id'.

SCTP_NOTIFICATIONS_STOPPED_EVENT (see RFC 6458 – section-6.1.10):

  • _sctp.sctp_event.SCTP_NOTIFICATIONS_STOPPED_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type' and 'sn_flags'.

    Warning

    Unlike FreeBSD, Linux does not support this notification (e.g., SCTP_NOTIFICATIONS_STOPPED_EVENT is not defined).

SCTP_SEND_FAILED_EVENT (see RFC 6458 – section-6.1.11):

  • _sctp.sctp_event.SCTP_SEND_FAILED_EVENT

    The keys in the dictionary returned by the function parse_notification() are: 'sn_type' and 'ssfe_flags', 'ssfe_error', 'ssfe_info', 'ssfe_assoc_id' and 'ssfe_data'.

    'ssfe_flags':

    • _sctp.sctp_event.SCTP_DATA_UNSENT
    • _sctp.sctp_event.SCTP_DATA_SENT

    'ssfe_info' is a sctp_sndinfo object and 'ssfe_data' is a bytes object.