23.9 Heartbeating and
Address Failure
SCTP provides a heartbeat mechanism similar in
concept to TCP's keep-alive option. In the case of SCTP, however,
the option is enabled by default. The application can control the
heartbeat and set the error threshold for an address by using the
same socket option we saw in Section 23.8. The
error threshold is the number of missed heartbeats or
retransmission timeouts that must occur before a destination
address is considered unreachable. When the destination address
becomes reachable again, detected by heartbeats, the address
becomes active.
The application can disable heartbeats, but
without heartbeats, SCTP has no way to detect if a failed peer
address has become reachable again. Such addresses cannot come back
to an active state without user intervention.
The heartbeat parameter field of the
sctp_paddrparams structure is spp_hbinterval. If
an application sets the spp_hbinterval field to
SCTP_NO_HB (0), heartbeats are disabled. A value
of SCTP_ISSUE_HB (0xffffffff) requests an
on-demand (immediate) heartbeat. Any other value sets the heartbeat
delay in milliseconds. The heartbeat delay provides a set delay
between heartbeats. This value, added to the current retransmission
timer value plus a random jitter, will become the amount of time
between heartbeats. In Figure
23.14 we show a small function that will either set the
heartbeat delay, request an on-demand heartbeat, or disable the
heartbeat for the specified destination. Note that by leaving the
retransmissions parameter, the spp_pathmaxrxt field of the
sctp_paddrparams structure, set to 0, we leave the current
value unchanged.
Figure 23.14
Heartbeat control utility function.
sctp/sctp_modify_hb.c
1 #include "unp.h"
2 int
3 heartbeat_action(int sock_fd, struct sockaddr *sa, socklen_t salen,
4 u_int value)
5 {
6 struct sctp_paddrparams sp;
7 int siz;
8 bzero(&sp, sizeof(sp));
9 sp.spp_hbinterval = value;
10 memcpy((caddr_t) & sp.spp_address, sa, salen);
11 Setsockopt(sock_fd, IPPROTO_SCTP,
12 SCTP_PEER_ADDR_PARAMS, &sp, sizeof(sp));
13 return (0);
14 }
Zero sctp_paddrparams struct
and copy interval
8鈥? We
zero out struct sctp_paddrparams to ensure that we won't
change any parameters we don't want to. We then copy the user's
desired heartbeat value: SCTP_ISSUE_HB,
SCTP_NO_HB, or a heartbeat interval.
Set up address
10 The
function sets up the address and copies it into the
sctp_paddrparams structure so that the SCTP implementation
will know the address to which we wish to send a heartbeat.
Perform action
11鈥?2
Finally, the function issues the socket option call to cause the
action the user has requested.
|