more advanced Nginx settings in GUI
[tomato.git] / release / src-rt-6.x.4708 / router / rc / ppp.c
blobc2c0499234754c25d9e430e7329ed006da53cdb1
1 /*
3 Copyright 2003, CyberTAN Inc. All Rights Reserved
5 This is UNPUBLISHED PROPRIETARY SOURCE CODE of CyberTAN Inc.
6 the contents of this file may not be disclosed to third parties,
7 copied or duplicated in any form without the prior written
8 permission of CyberTAN Inc.
10 This software should be used as a reference only, and it not
11 intended for production use!
14 THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
15 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
16 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
17 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
21 Copyright 2005, Broadcom Corporation
22 All Rights Reserved.
24 THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
25 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
26 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
27 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
31 $Id: ppp.c,v 1.27 2005/03/29 02:00:06 honor Exp $
34 #include "rc.h"
36 #include <sys/ioctl.h>
39 int ipup_main(int argc, char **argv)
41 char *wan_ifname;
42 char *value;
43 char buf[256];
44 const char *p;
46 TRACE_PT("begin\n");
48 killall("listen", SIGKILL);
50 if (!wait_action_idle(10)) return -1;
52 wan_ifname = safe_getenv("IFNAME");
53 if ((!wan_ifname) || (!*wan_ifname)) return -1;
54 nvram_set("wan_iface", wan_ifname); // ppp#
56 // ipup receives six arguments:
57 // <interface name> <tty device> <speed> <local IP address> <remote IP address> <ipparam>
58 // ppp1 vlan1 0 71.135.98.32 151.164.184.87 0
60 f_write_string("/tmp/ppp/link", argv[1], 0, 0);
62 if ((p = getenv("IPREMOTE"))) {
63 nvram_set("wan_gateway_get", p);
64 TRACE_PT("IPREMOTE=%s\n", p);
67 if ((value = getenv("IPLOCAL"))) {
68 _dprintf("IPLOCAL=%s\n", value);
70 switch (get_wan_proto()) {
71 case WP_PPPOE:
72 case WP_PPP3G:
73 nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr")); // store last ip address
74 nvram_set("wan_ipaddr", value);
75 nvram_set("wan_netmask", "255.255.255.255");
76 break;
77 case WP_PPTP:
78 case WP_L2TP:
79 nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip"));
80 break;
83 if (!nvram_match("ppp_get_ip", value)) {
84 ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
85 nvram_set("ppp_get_ip", value);
88 _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", (p && (*p)) ? p : NULL);
91 buf[0] = 0;
92 if ((p = getenv("DNS1")) != NULL) strlcpy(buf, p, sizeof(buf));
93 if ((p = getenv("DNS2")) != NULL) {
94 if (buf[0]) strlcat(buf, " ", sizeof(buf));
95 strlcat(buf, p, sizeof(buf));
97 nvram_set("wan_get_dns", buf);
98 TRACE_PT("DNS=%s\n", buf);
100 if ((value = getenv("AC_NAME"))) nvram_set("ppp_get_ac", value);
101 if ((value = getenv("SRV_NAME"))) nvram_set("ppp_get_srv", value);
102 if ((value = getenv("MTU"))) nvram_set("wan_run_mtu", value);
104 start_wan_done(wan_ifname);
106 TRACE_PT("end\n");
107 return 0;
110 int ipdown_main(int argc, char **argv)
112 int proto;
114 TRACE_PT("begin\n");
116 if (!wait_action_idle(10)) return -1;
118 stop_ddns(); // avoid to trigger DOD
119 stop_ntpc();
121 unlink("/tmp/ppp/link");
123 proto = get_wan_proto();
124 if (proto == WP_L2TP || proto == WP_PPTP) {
125 /* clear dns from the resolv.conf */
126 nvram_set("wan_get_dns","");
127 dns_to_resolv();
129 if (proto == WP_L2TP) {
130 route_del(nvram_safe_get("wan_ifname"), 0, nvram_safe_get("l2tp_server_ip"),
131 nvram_safe_get("wan_gateway"), "255.255.255.255"); // fixed routing problem in Israel by kanki
134 // Restore the default gateway for WAN interface
135 nvram_set("wan_gateway_get", nvram_safe_get("wan_gateway"));
137 // Set default route to gateway if specified
138 route_del(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
139 route_add(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
142 if (nvram_get_int("ppp_demand")) {
143 killall("listen", SIGKILL);
144 eval("listen", nvram_safe_get("lan_ifname"));
147 TRACE_PT("end\n");
148 return 1;
151 #ifdef TCONFIG_IPV6
152 int ip6up_main(int argc, char **argv)
155 char *wan_ifname;
156 char *value;
158 TRACE_PT("begin\n");
159 if (!wait_action_idle(10)) return -1;
161 wan_ifname = safe_getenv("IFNAME");
162 if ((!wan_ifname) || (!*wan_ifname)) return -1;
164 value = getenv("LLREMOTE");
166 // ???
168 start_wan6_done(wan_ifname);
169 TRACE_PT("end\n");
171 return 0;
174 int ip6down_main(int argc, char **argv)
177 TRACE_PT("begin\n");
178 if (!wait_action_idle(10)) return -1;
180 // ???
182 TRACE_PT("end\n");
184 return 1;
186 #endif // IPV6
188 int pppevent_main(int argc, char **argv)
190 int i;
192 TRACE_PT("begin\n");
194 for (i = 1; i < argc; ++i) {
195 TRACE_PT("arg%d=%s\n", i, argv[i]);
196 if (strcmp(argv[i], "-t") == 0) {
197 if (++i >= argc) return 1;
198 if ((strcmp(argv[i], "PAP_AUTH_FAIL") == 0) || (strcmp(argv[i], "CHAP_AUTH_FAIL") == 0)) {
199 f_write_string("/tmp/ppp/log", argv[i], 0, 0);
200 notice_set("wan", "Authentication failed"); // !!!
201 return 0;
206 TRACE_PT("end\n");
207 return 1;
210 #if 0
211 int set_pppoepid_main(int argc, char **argv)
213 if (argc < 2) return 0;
215 TRACE_PT("num=%s\n", argv[1]);
217 if (atoi(argv[1]) != 0) return 0;
219 nvram_set("pppoe_pid0", getenv("PPPD_PID"));
220 nvram_set("pppoe_ifname0", getenv("IFNAME"));
221 nvram_set("wan_iface", getenv("IFNAME"));
223 TRACE_PT("IFNAME=%s DEVICE=%s\n", getenv("IFNAME"), getenv("DEVICE"));
224 return 0;
227 int pppoe_down_main(int argc, char **argv)
229 if (argc < 2) return 0;
231 TRACE_PT("num=%s\n", argv[1]);
233 if (atoi(argv[1]) != 0) return 0;
235 if ((nvram_get_int("ppp_demand")) && (nvram_match("action_service", ""))) {
236 stop_singe_pppoe(0);
237 start_pppoe(0);
239 stop_dnsmasq();
240 dns_to_resolv();
241 start_dnsmasq();
243 return 0;
245 #endif // 0