Skip to content

Commit b0f25ae

Browse files
committed
[server] (Vlad Glagolev) Add client timeouts to command open/close cycle operations
1 parent 51de939 commit b0f25ae

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Vlad Glagolev
112112
suite.
113113
- Submitted an OpenBSD port for fwknop-2.0.3, and this has been checked in
114114
under extras/openbsd/.
115+
- Added client timeouts for open/close command cycles for fwknop-2.6.8.
115116

116117
Sean Greven
117118
- Created a port of fwknop for FreeBSD:

doc/fwknopd.man.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ directive starts a new stanza.
592592
a ``$'' character, and include ``$IP'' (the allow IP decrypted from the
593593
SPA payload), ``$SRC'' (synonym for ``$IP'') , ``$PKT_SRC'' (the source IP
594594
in the network layer header of the SPA packet), ``$DST'' (the destination
595-
IP), ``$PORT'' (the allow port), and ``$PROTO'' (the allow protocol).
595+
IP), ``$PORT'' (the allow port), and ``$PROTO'' (the allow protocol),
596+
``$TIMEOUT'' (set the client timeout if specified).
596597

597598
*CMD_CYCLE_CLOSE* '<command>'::
598599
Specify the close command that corresponds to the open command set by the

server/cmd_cycle.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ is_var(const char * const var, const char * const cmd_str)
5959
}
6060

6161
static int
62-
build_cmd(spa_data_t *spadat, const char * const cmd_cycle_str)
62+
build_cmd(spa_data_t *spadat, const char * const cmd_cycle_str, int timer)
6363
{
6464
char port_str[MAX_PORT_STR_LEN+1] = {0};
6565
char proto_str[MAX_PROTO_STR_LEN+1] = {0};
66+
char timestamp_str[20] = {0};
6667
acc_port_list_t *port_list = NULL;
6768
int i=0, buf_idx=0;
6869

@@ -137,6 +138,14 @@ build_cmd(spa_data_t *spadat, const char * const cmd_cycle_str)
137138
i += strlen("PROTO");
138139
buf_idx += strlen(proto_str);
139140
}
141+
else if (is_var("TIMEOUT", (cmd_cycle_str+i+1)))
142+
{
143+
snprintf(timestamp_str, sizeof(timestamp_str), "%lli", (long long)spadat->timestamp +
144+
(spadat->client_timeout == 0 ? timer : spadat->client_timeout));
145+
strlcat(cmd_buf, timestamp_str, CMD_CYCLE_BUFSIZE);
146+
i += strlen("TIMEOUT");
147+
buf_idx += strlen(timestamp_str);
148+
}
140149
continue;
141150
}
142151
if(cmd_cycle_str[i] != '\0')
@@ -159,7 +168,7 @@ cmd_open(fko_srv_options_t *opts, acc_stanza_t *acc,
159168
/* CMD_CYCLE_OPEN: Build the open command by taking care of variable
160169
* substitutions if necessary.
161170
*/
162-
if(build_cmd(spadat, acc->cmd_cycle_open))
171+
if(build_cmd(spadat, acc->cmd_cycle_open, acc->cmd_cycle_timer))
163172
{
164173
log_msg(LOG_INFO, "[%s] (stanza #%d) Running CMD_CYCLE_OPEN command: %s",
165174
spadat->pkt_source_ip, stanza_num, cmd_buf);
@@ -191,15 +200,15 @@ add_cmd_close(fko_srv_options_t *opts, acc_stanza_t *acc,
191200
/* CMD_CYCLE_CLOSE: Build the close command, but don't execute it until
192201
* the expiration timer has passed.
193202
*/
194-
if(build_cmd(spadat, acc->cmd_cycle_close))
203+
if(build_cmd(spadat, acc->cmd_cycle_close, acc->cmd_cycle_timer))
195204
{
196205
/* Now the corresponding close command is now in cmd_buf
197206
* for later execution when the timer expires.
198207
*/
199208
cmd_close_len = strnlen(cmd_buf, CMD_CYCLE_BUFSIZE-1)+1;
200209
log_msg(LOG_INFO,
201210
"[%s] (stanza #%d) Running CMD_CYCLE_CLOSE command in %d seconds: %s",
202-
spadat->pkt_source_ip, stanza_num, acc->cmd_cycle_timer, cmd_buf);
211+
spadat->pkt_source_ip, stanza_num, (spadat->client_timeout == 0 ? acc->cmd_cycle_timer : spadat->client_timeout), cmd_buf);
203212
}
204213
else
205214
{
@@ -244,7 +253,7 @@ add_cmd_close(fko_srv_options_t *opts, acc_stanza_t *acc,
244253
/* Set the expiration timer
245254
*/
246255
time(&now);
247-
new_clist->expire = now + acc->cmd_cycle_timer;
256+
new_clist->expire = now + (spadat->client_timeout == 0 ? acc->cmd_cycle_timer : spadat->client_timeout);
248257

249258
/* Set the close command
250259
*/

0 commit comments

Comments
 (0)