more advanced Nginx settings in GUI
[tomato.git] / release / src-rt-6.x.4708 / router / rc / redial.c
blob7af9e7844a2b6e90f070cb4aad2801ce7c14c17a
1 /*
3 Copyright 2003, CyberTAN Inc. All Rights Reserved
5 THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
6 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
7 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
13 Copyright 2005, Broadcom Corporation
14 All Rights Reserved.
16 THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
17 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
18 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
19 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
23 #include "rc.h"
25 #include <sys/ioctl.h>
26 #include <wait.h>
29 // used in keepalive mode (ppp_demand=0)
32 int start_redial(void)
34 stop_redial();
36 xstart("redial");
37 return 0;
40 int stop_redial(void)
42 while (killall("redial", SIGKILL) == 0) {
43 sleep(1);
45 return 0;
48 int redial_main(int argc, char **argv)
50 int tm;
51 int count;
52 int proto;
54 proto = get_wan_proto();
55 if (proto == WP_PPPOE || proto == WP_PPP3G || proto == WP_PPTP || proto == WP_L2TP) {
56 if (nvram_get_int("ppp_demand") != 0) return 0;
59 tm = nvram_get_int("ppp_redialperiod") ? : 30;
60 if (tm < 5) tm = 5;
62 syslog(LOG_INFO, "Started. Time: %d", tm);
64 count = 0;
65 sleep(10);
67 while (1) {
68 while (1) {
69 sleep(tm);
70 if (!check_wanup()) break;
71 count = 0;
74 #if 0
75 long ut;
76 if ((count < 3) && (get_wan_proto() == WP_PPPOE) || (get_wan_proto() == WP_PPP3G)) {
77 if (f_read("/var/lib/misc/pppoe-disc", &ut, sizeof(ut)) == sizeof(ut)) {
78 ut = (get_uptime() - ut);
79 if (ut <= 15) {
80 syslog(LOG_INFO, "PPPoE reconnect in progress (%ld)", ut);
81 ++count;
82 continue;
86 #endif
88 if ((!wait_action_idle(10)) || (check_wanup())) continue;
90 if (!nvram_match("action_service", "wan-restart")) {
91 syslog(LOG_INFO, "WAN down. Reconnecting...");
92 xstart("service", "wan", "restart");
93 break;
95 else {
96 syslog(LOG_INFO, "WAN down. Reconnect is already in progress...");
100 return 0;