3.71.31. StreamStateChangeHook Previous topic Parent topic Child topic Next topic

This optional parameter allows you to define a Perl function that will be called when a Stream connection state to a peer changes. RadSec, Diameter, TACACS+, HTTP and SIGTRAN clients and servers use Stream connections in Radiator. This is a low layer hook that runs before, for example, RadSec TLS handshake or Diameter Capabilities Exchange messages are exchanged. The following arguments are passed in the following order:
  • Reference to this Radius::Stream derived type. Examples of derived types are Radius::RadsecHost and Radius::DiameterConnection.
  • New stream state. One of integer constant values:
    • $Radius::Stream::STREAM_STATE::CONNECTED
    • $Radius::Stream::STREAM_STATE::DISCONNECTED
StreamStateChangeHook can be an arbitrarily complicated Perl function, that might run external processes, consult databases, change the contents of the current request or many other things. IP address and other specific information is not passed to the hook. Their format and type depends on the derived type. For example, SCTP streams may have multiple source and destination addresses. The following example shows how to log information from the hook no matter what the type of the stream object is.
StreamStateChangeHook sub { \
    my ($self, $new_state) = @_; \
    my $state = ($new_state == $Radius::Stream::STREAM_STATE::CONNECTED) ? \
                  'connected' : 'disconnected'; \
    main::log($main::LOG_INFO, "StreamStateChangeHook: State change to $state"); \
    return; }