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
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 $
36 #include <sys/ioctl.h>
39 int ipup_main(int argc
, char **argv
)
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()) {
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");
79 nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip"));
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
);
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
);
110 int ipdown_main(int argc
, char **argv
)
116 if (!wait_action_idle(10)) return -1;
118 stop_ddns(); // avoid to trigger DOD
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","");
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"));
152 int ip6up_main(int argc
, char **argv
)
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");
168 start_wan6_done(wan_ifname);
174 int ip6down_main(int argc
, char **argv
)
178 if (!wait_action_idle(10)) return -1;
188 int pppevent_main(int argc
, char **argv
)
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"); // !!!
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"));
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", ""))) {