/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname; char *value; char buf[256]; char tmp[100], prefix[WAN_PREFIX_SZ]; if (ppp_prefix(&wan_ifname, prefix) < 0) return -1; umask(022); /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); strcpy(buf, ""); if (getenv("DNS1")) sprintf(buf, "%s", getenv("DNS1")); if (getenv("DNS2")) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", getenv("DNS2")); nvram_set(strcat_r(prefix, "dns", tmp), buf); wan_up(wan_ifname); logmessage(nvram_safe_get("wan_proto_t"), "connected to ISP"); wanmessage(""); dprintf("done\n"); return 0; }
int ipup_main(int argc, char **argv) { char *wan_ifname; char *value; char buf[256]; const char *p; TRACE_PT("begin\n"); killall("listen", SIGKILL); if (!wait_action_idle(10)) return -1; wan_ifname = safe_getenv("IFNAME"); if ((!wan_ifname) || (!*wan_ifname)) return -1; nvram_set("wan_iface", wan_ifname); // ppp# // ipup receives six arguments: // <interface name> <tty device> <speed> <local IP address> <remote IP address> <ipparam> // ppp1 vlan1 0 71.135.98.32 151.164.184.87 0 f_write_string("/tmp/ppp/link", argv[1], 0, 0); if ((p = getenv("IPREMOTE"))) { nvram_set("wan_gateway_get", p); TRACE_PT("IPREMOTE=%s\n", p); } if ((value = getenv("IPLOCAL"))) { _dprintf("IPLOCAL=%s\n", value); switch (get_wan_proto()) { case WP_PPPOE: case WP_PPP3G: nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr")); // store last ip address nvram_set("wan_ipaddr", value); nvram_set("wan_netmask", "255.255.255.255"); break; case WP_PPTP: case WP_L2TP: nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip")); break; } if (!nvram_match("ppp_get_ip", value)) { ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); nvram_set("ppp_get_ip", value); } _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", (p && (*p)) ? p : NULL); } buf[0] = 0; if ((p = getenv("DNS1")) != NULL) strlcpy(buf, p, sizeof(buf)); if ((p = getenv("DNS2")) != NULL) { if (buf[0]) strlcat(buf, " ", sizeof(buf)); strlcat(buf, p, sizeof(buf)); } nvram_set("wan_get_dns", buf); TRACE_PT("DNS=%s\n", buf); if ((value = getenv("AC_NAME"))) nvram_set("ppp_get_ac", value); if ((value = getenv("SRV_NAME"))) nvram_set("ppp_get_srv", value); if ((value = getenv("MTU"))) nvram_set("wan_run_mtu", value); start_wan_done(wan_ifname); TRACE_PT("end\n"); return 0; }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname = safe_getenv("IFNAME"); char *wan_linkname = safe_getenv("LINKNAME"); char tmp[100], prefix[] = "wanXXXXXXXXXX_"; char buf[256], *value; int unit; _dprintf("%s():: %s\n", __FUNCTION__, argv[0]); /* Get unit from LINKNAME: ppp[UNIT] */ if ((unit = ppp_linkunit(wan_linkname)) < 0) return 0; _dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname); snprintf(prefix, sizeof(prefix), "wan%d_", unit); /* Stop triggering demand connection */ if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp))) nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1); #ifdef RTCONFIG_USB_MODEM // wanX_ifname is used for device for USB Modem if ((value = getenv("DEVICE")) && (isSerialNode(value) || isACMNode(value))) nvram_set(strcat_r(prefix, "ifname", tmp), value); #endif /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); strcpy(buf, ""); if ((value = getenv("DNS1"))) sprintf(buf, "%s", value); if ((value = getenv("DNS2"))) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value); /* empty DNS means they either were not requested or peer refused to send them. * lift up underlying xdns value instead, keeping "dns" filled */ if (strlen(buf) == 0) sprintf(buf, "%s", nvram_safe_get(strcat_r(prefix, "xdns", tmp))); nvram_set(strcat_r(prefix, "dns", tmp), buf); wan_up(wan_ifname); _dprintf("%s:: done\n", __FUNCTION__); return 0; }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname = safe_getenv("IFNAME"); char *wan_linkname = safe_getenv("LINKNAME"); char tmp[100], prefix[] = "wanXXXXXXXXXX_"; char buf[256], *value; int unit; _dprintf("%s():: %s\n", __FUNCTION__, argv[0]); /* Get unit from LINKNAME: ppp[UNIT] */ if ((unit = ppp_linkunit(wan_linkname)) < 0) return 0; _dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname); snprintf(prefix, sizeof(prefix), "wan%d_", unit); /* Stop triggering demand connection */ if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp))) nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1); #ifdef RTCONFIG_USB_MODEM // wanX_ifname is used for device for USB Modem if ((value = getenv("DEVICE")) && (isSerialNode(value) || isACMNode(value))) nvram_set(strcat_r(prefix, "ifname", tmp), value); #endif /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); #ifdef RTCONFIG_DSL /* Paul add 2013/1/23, only for Auto DNS and 3G/4G */ if (!nvram_match(strcat_r(prefix, "dnsenable_x", tmp), "0")) { #endif strcpy(buf, ""); if ((value = getenv("DNS1"))) sprintf(buf, "%s", value); if ((value = getenv("DNS2"))) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value); /* set PPP DNS, no DNS/usepeerdns forces update_resolvconf use xdns value */ nvram_set(strcat_r(prefix, "dns", tmp), buf); #ifdef RTCONFIG_DSL } #endif wan_up(wan_ifname); _dprintf("%s:: done\n", __FUNCTION__); return 0; }