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()) {
72 nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr")); // store last ip address
73 nvram_set("wan_ipaddr", value
);
74 nvram_set("wan_netmask", "255.255.255.255");
78 nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip"));
82 if (!nvram_match("ppp_get_ip", value
)) {
83 ifconfig(wan_ifname
, IFUP
, "0.0.0.0", NULL
);
84 nvram_set("ppp_get_ip", value
);
87 _ifconfig(wan_ifname
, IFUP
, value
, "255.255.255.255", (p
&& (*p
)) ? p
: NULL
);
91 if ((p
= getenv("DNS1")) != NULL
) strlcpy(buf
, p
, sizeof(buf
));
92 if ((p
= getenv("DNS2")) != NULL
) {
93 if (buf
[0]) strlcat(buf
, " ", sizeof(buf
));
94 strlcat(buf
, p
, sizeof(buf
));
96 nvram_set("wan_get_dns", buf
);
97 TRACE_PT("DNS=%s\n", buf
);
99 if ((value
= getenv("AC_NAME"))) nvram_set("ppp_get_ac", value
);
100 if ((value
= getenv("SRV_NAME"))) nvram_set("ppp_get_srv", value
);
101 if ((value
= getenv("MTU"))) nvram_set("wan_run_mtu", value
);
103 start_wan_done(wan_ifname
);
109 int ipdown_main(int argc
, char **argv
)
115 if (!wait_action_idle(10)) return -1;
117 stop_ddns(); // avoid to trigger DOD
120 unlink("/tmp/ppp/link");
122 proto
= get_wan_proto();
123 if (proto
== WP_L2TP
|| proto
== WP_PPTP
) {
124 /* clear dns from the resolv.conf */
125 nvram_set("wan_get_dns","");
128 if (proto
== WP_L2TP
) {
129 route_del(nvram_safe_get("wan_ifname"), 0, nvram_safe_get("l2tp_server_ip"),
130 nvram_safe_get("wan_gateway"), "255.255.255.255"); // fixed routing problem in Israel by kanki
133 // Restore the default gateway for WAN interface
134 nvram_set("wan_gateway_get", nvram_safe_get("wan_gateway"));
136 // Set default route to gateway if specified
137 route_del(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
138 route_add(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
141 if (nvram_get_int("ppp_demand")) {
142 killall("listen", SIGKILL
);
143 eval("listen", nvram_safe_get("lan_ifname"));
151 int ip6up_main(int argc
, char **argv
)
158 if (!wait_action_idle(10)) return -1;
160 wan_ifname = safe_getenv("IFNAME");
161 if ((!wan_ifname) || (!*wan_ifname)) return -1;
163 value = getenv("LLREMOTE");
167 start_wan6_done(wan_ifname);
173 int ip6down_main(int argc
, char **argv
)
177 if (!wait_action_idle(10)) return -1;
187 int pppevent_main(int argc
, char **argv
)
193 for (i
= 1; i
< argc
; ++i
) {
194 TRACE_PT("arg%d=%s\n", i
, argv
[i
]);
195 if (strcmp(argv
[i
], "-t") == 0) {
196 if (++i
>= argc
) return 1;
197 if ((strcmp(argv
[i
], "PAP_AUTH_FAIL") == 0) || (strcmp(argv
[i
], "CHAP_AUTH_FAIL") == 0)) {
198 f_write_string("/tmp/ppp/log", argv
[i
], 0, 0);
199 notice_set("wan", "Authentication failed"); // !!!
210 int set_pppoepid_main(int argc
, char **argv
)
212 if (argc
< 2) return 0;
214 TRACE_PT("num=%s\n", argv
[1]);
216 if (atoi(argv
[1]) != 0) return 0;
218 nvram_set("pppoe_pid0", getenv("PPPD_PID"));
219 nvram_set("pppoe_ifname0", getenv("IFNAME"));
220 nvram_set("wan_iface", getenv("IFNAME"));
222 TRACE_PT("IFNAME=%s DEVICE=%s\n", getenv("IFNAME"), getenv("DEVICE"));
226 int pppoe_down_main(int argc
, char **argv
)
228 if (argc
< 2) return 0;
230 TRACE_PT("num=%s\n", argv
[1]);
232 if (atoi(argv
[1]) != 0) return 0;
234 if ((nvram_get_int("ppp_demand")) && (nvram_match("action_service", ""))) {