xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.bin/pppd/plugins/minconn.c (revision 8b80e8cb6855118d46f605e91b5ed4ce83417395)
1 /*
2  * minconn.c - pppd plugin to implement a `minconnect' option.
3  *
4  * Copyright 1999 Paul Mackerras.
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version
9  *  2 of the License, or (at your option) any later version.
10  */
11 #include <stddef.h>
12 #include <time.h>
13 #include "pppd.h"
14 
15 static int minconnect = 0;
16 
17 static option_t my_options[] = {
18 	{ "minconnect", o_int, &minconnect,
19 	  "Set minimum connect time before idle timeout applies" },
20 	{ NULL }
21 };
22 
23 static int my_get_idle(struct ppp_idle *idle)
24 {
25 	time_t t;
26 
27 	if (idle == NULL)
28 		return minconnect? minconnect: idle_time_limit;
29 	t = idle->xmit_idle;
30 	if (idle->recv_idle < t)
31 		t = idle->recv_idle;
32 	return idle_time_limit - t;
33 }
34 
35 void plugin_init(void)
36 {
37 	info("plugin_init");
38 	add_options(my_options);
39 	idle_time_hook = my_get_idle;
40 }
41