]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/minconn.c
Makefile.am: Add explicit openssl directory to pppd include path
[ppp.git] / pppd / plugins / minconn.c
1 /*
2  * minconn.c - pppd plugin to implement a `minconnect' option.
3  *
4  * Copyright (c) 1999 Paul Mackerras. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name(s) of the authors of this software must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission.
21  *
22  * 4. Redistributions of any form whatsoever must retain the following
23  *    acknowledgment:
24  *    "This product includes software developed by Paul Mackerras
25  *     <paulus@ozlabs.org>".
26  *
27  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34  */
35
36 #include <stddef.h>
37 #include <time.h>
38 #include <stdint.h>
39 #include <stdbool.h>
40 #include <stdarg.h>
41 #include <sys/types.h>
42
43 #include <pppd/pppd.h>
44 #include <pppd/options.h>
45
46 #if !defined(SOL2)
47 #include <linux/ppp_defs.h>
48 #else
49 #include <net/ppp_defs.h>
50 #endif
51
52 char pppd_version[] = PPPD_VERSION;
53
54 static int minconnect = 0;
55
56 static struct option my_options[] = {
57         { "minconnect", o_int, &minconnect,
58           "Set minimum connect time before idle timeout applies" },
59         { NULL }
60 };
61
62 static int my_get_idle(struct ppp_idle *idle)
63 {
64         time_t t;
65
66         if (idle == NULL)
67                 return minconnect ? minconnect: ppp_get_max_idle_time();
68         t = idle->xmit_idle;
69         if (idle->recv_idle < t)
70                 t = idle->recv_idle;
71         return ppp_get_max_idle_time() - t;
72 }
73
74 void plugin_init(void)
75 {
76         info("plugin_init");
77         ppp_add_options(my_options);
78         idle_time_hook = my_get_idle;
79 }