Routers and firewalls dropping tcp connection after a short period (eg five minutes) is a problem for applications that don't configurable keepalive options.
Fabio Busatto's intercept library libkeepalive works by intercepting function calls to socket(2) and setting the keepalive parameters using setsockopt(2).
The actual values of (SO_KEEPALIVE, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL) are passed to the process in environment variables.
My take on this was to only intercept connect(2) and accept(2) calls and retrieve the values from a configuration file. eg
# SSH to 126.96.36.199 env LD_PRELOAD=/intercept/libkeepalive.so /usr/bin/ssh firstname.lastname@example.org # Example configuration file (location is define at compile time.) # Connect entries #C destips/mask dest-portrange keepalive idle intvl count # Accept entries #A srcpip/mask local-portrange keepalive idle intvl count C 192.168.0.0/16 * N - - - C 188.8.131.52 22 Y 240 75 8In this example the ssh matches the second entry and the parameters are taken from the file.
Source in files/