Just out of curiosity, but is kamailio notified (some event in the config) that a socket died when using tcp keepalives on the OS level?
If the tcpops module is loaded, the tcp:closed event route will be called:
http://kamailio.org/docs/modules/devel/modules/tcpops.html#idp24759196