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