Operating System - HP-UX
1819804 Members
3162 Online
109607 Solutions
New Discussion юеВ

How to enable TCP Keepalive on a system?

 

How to enable TCP Keepalive on a system?

I would like to enable TCP keepalive ona system and not per application basis via programming technics (using setsockopt).
On Tru64 there is a system parameter named tcp_keepalives_default that enables (1) or disables (0) TCP keepalive for all sockets.
Do we have something similar on HP-UX?
5 REPLIES 5
Muthukumar_5
Honored Contributor

Re: How to enable TCP Keepalive on a system?

# ndd -h supported | grep keep
tcp_keepalive_detached_interval - Send keepalive probes for detached TCP
tcp_keepalive_interval - Interval for sending keepalive probes

It is the tunables regarding to keep alive setting with TCP.

hth.
Easy to suggest when don't know about the problem!

Re: How to enable TCP Keepalive on a system?

But these parameters do not allow me to enable the keepalive on the system I still have to use the setsockopt in my application.
Right?
Todd Whitcher
Esteemed Contributor

Re: How to enable TCP Keepalive on a system?

Keepalives are enabled by default on HPUX.

The default values set keepalives to probe every 2 hours.

You can modify these values, its suggested to never go below 10 minutes.

Use the ndd -h command to view the help options.

# ndd -h tcp_keepalive_interval

tcp_keepalive_interval:

Interval for sending keep-alive probes.

If any activity has occurred on the connection or if there is
any unacknowledged data when the time-out period expires, the
timer is simply restarted. If the remote system has crashed
and rebooted, it will presumably know nothing about this
connection, and it will issue an RST in response to the ACK.
Receipt of the RST will terminate the connection.

If the keepalive packet is not ACK'd by the remote TCP, the normal
retransmission time-out will eventually exceed threshold R2,
and the connection will be terminated.

With this keepalive behavior, a connection can time-out and
terminate without actually receiving an RST from the remote TCP.
[10000, 10*24*3600000] Default: 2 * 3600000 (2 hours)

#

Some useful ndd commands:

To see the supported tunables
# ndd -h supported

To view one particular variable

# ndd -h variable_name

To get a value:
ndd -get /dev/tcp tcp_keepalive_interval
7200000
#

To set tcp_keepalive_interval to 1 hour

# ndd -set /dev/tcp tcp_keepalive_interval 3600000

To make this setting permanent you have to edit the /etc/rc.config.d/nddconf file. There are examples in the header.

See the man page for ndd for more information.

Hope this helps
rick jones
Honored Contributor

Re: How to enable TCP Keepalive on a system?

I was under the impression that applications still had to make a setsockopt(SO_KEEPALIVE) call to enable TCP keepalives on a given TCP connection.

Now, if the application cannot be enhanced (FWIW, it is rather non-portable to count on the transport stack to have a setting...) directly to make the setsockopt() call, it may be possible to write a little LD_PRELOADable shim library that intercepts say calls to socket(), makes the call to the real socket() routine and then if the conditions are correct also makes a call to setsockopt(). If socket() the right one to intercept, then perhaps connect() and accept() (or listen())

Still, it would be best if the application could be enhanced to have a setting that tells _it_ to make a setsockopt() call
there is no rest for the wicked yet the virtuous have no pillows
rick jones
Honored Contributor

Re: How to enable TCP Keepalive on a system?

I should point-out that what _is_ automagic is the TCP stack sending keepalive probes after the application has called close() - this is to deal with things like FIN_WAIT_2 issues...
there is no rest for the wicked yet the virtuous have no pillows