]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/minconn.c
config: Include some extra files in the tarball
[ppp.git] / pppd / plugins / minconn.c
1 /*
2  * minconn.c - pppd plugin to implement a `minconnect' option.
3  *
4  * Copyright (c) 1999-2024 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  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
19  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
21  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
23  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
24  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25  */
26
27 #include <stddef.h>
28 #include <time.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include <stdarg.h>
32 #include <sys/types.h>
33
34 #include <pppd/pppd.h>
35 #include <pppd/options.h>
36
37 #if !defined(SOL2)
38 #include <linux/ppp_defs.h>
39 #else
40 #include <net/ppp_defs.h>
41 #endif
42
43 char pppd_version[] = PPPD_VERSION;
44
45 static int minconnect = 0;
46
47 static struct option my_options[] = {
48         { "minconnect", o_int, &minconnect,
49           "Set minimum connect time before idle timeout applies" },
50         { NULL }
51 };
52
53 static int my_get_idle(struct ppp_idle *idle)
54 {
55         time_t t;
56
57         if (idle == NULL)
58                 return minconnect ? minconnect: ppp_get_max_idle_time();
59         t = idle->xmit_idle;
60         if (idle->recv_idle < t)
61                 t = idle->recv_idle;
62         return ppp_get_max_idle_time() - t;
63 }
64
65 void plugin_init(void)
66 {
67         info("plugin_init");
68         ppp_add_options(my_options);
69         idle_time_hook = my_get_idle;
70 }