/* This file is in the public domain. */ #include #include #include extern const char *__progname; #include "bpp.h" #include "errf.h" #include "msgs.h" #include "config.h" #include "pollloop.h" #include "channels.h" #include "keepalive.h" #ifndef AF_TIMER void start_ssh_keepalive(void) { int secs; secs = config_int("ssh-keepalive"); if (secs < 1) return; fprintf(errf,"%s: warning: ssh-level keepalives not supported in this build (no AF_TIMER)\n",__progname); } #else #include static int kafd; static void rd_ka(int id __attribute__((__unused__)), void *bv __attribute__((__unused__))) { LAYER *l; struct timersock_event e; unsigned char *opp; l = chan_layer(); if (read(kafd,&e,sizeof(e)) != sizeof(e)) return; opp = &l->b->opkt[0]; *opp++ = SSH_MSG_IGNORE; l->b->oplen = opp - &l->b->opkt[0]; below_opkt(l); } void start_ssh_keepalive(void) { int secs; struct itimerval itv; secs = config_int("ssh-keepalive"); if (secs < 1) return; kafd = socket(AF_TIMER,SOCK_STREAM,0); itv.it_value.tv_sec = secs; itv.it_value.tv_usec = 0; itv.it_interval = itv.it_value; write(kafd,&itv,sizeof(itv)); add_poll_fd(kafd,&rwtest_always,&rwtest_never,&rd_ka,0,0); } #endif