int ip6up_main(int argc, char **argv) { char *wan_ifname = safe_getenv("IFNAME"); char *llremote = safe_getenv("LLREMOTE"); if (!wan_ifname || strlen(wan_ifname) <= 0) return 0; nvram_set("ipv6_ll_remote", llremote); switch (get_ipv6_service()) { case IPV6_NATIVE: case IPV6_NATIVE_DHCP: wait_ppp_count = 10; while ((!is_intf_up(wan_ifname) || !getifaddr(wan_ifname, AF_INET6, 0)) && (wait_ppp_count-- > 0)) sleep(1); break; default: wait_ppp_count = 0; break; } if (wait_ppp_count != -2) { wan6_up(wan_ifname); start_firewall(0, 0); } return 0; }
static int bound(char *ifname) { _dprintf("%s: begin\n", __FUNCTION__); unlink(renewing); env2nv("ip", "wan_ipaddr"); env2nv("subnet", "wan_netmask"); env2nv_gateway("wan_gateway"); env2nv("dns", "wan_get_dns"); env2nv("domain", "wan_get_domain"); env2nv("lease", "wan_lease"); expires(atoi(safe_getenv("lease"))); _dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr")); _dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask")); _dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway")); _dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain")); _dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns")); _dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease")); ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); if (get_wan_proto() == WP_L2TP) { int i = 0; /* Delete all default routes */ while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) || (i++ < 10)); /* Set default route to gateway if specified */ route_add(ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0"); /* Backup the default gateway. It should be used if L2TP connection is broken */ nvram_set("wan_gateway_buf", nvram_get("wan_gateway")); /* clear dns from the resolv.conf */ nvram_set("wan_get_dns",""); dns_to_resolv(); start_firewall(); start_l2tp(); } else { start_wan_done(ifname); } _dprintf("%s: end\n", __FUNCTION__); return 0; }
static int bound(void) { nvram_unset("dhcpc_done"); char *wan_ifname = safe_getenv("interface"); char *value; static char temp_wan_ipaddr[16], temp_wan_netmask[16], temp_wan_gateway[16]; int changed = 0; static char *cidr; if (nvram_match("wan_proto", "iphone")) stop_process("ipheth-loop", "IPhone Pairing Daemon"); cidr = getenv("cidrroute"); if (cidr && wan_ifname) { char *callbuffer = malloc(strlen(cidr) + 128); sprintf(callbuffer, "export cidrroute=\"%s\";export interface=\"%s\";/etc/cidrroute.sh", cidr, wan_ifname); system(callbuffer); free(callbuffer); } if ((value = getenv("ip"))) { chomp(value); if (nvram_match("wan_proto", "pptp") && nvram_match("pptp_use_dhcp", "1")) strcpy(temp_wan_ipaddr, value); else { if (nvram_invmatch("wan_ipaddr", value)) changed = 1; } nvram_set("wan_ipaddr", value); } if ((value = getenv("subnet"))) { chomp(value); if (nvram_match("wan_proto", "pptp") && nvram_match("pptp_use_dhcp", "1")) strcpy(temp_wan_netmask, value); else { if (nvram_invmatch("wan_netmask", value)) changed = 1; nvram_set("wan_netmask", value); } } if ((value = getenv("router"))) { chomp(value); if (nvram_invmatch("wan_gateway", value)) changed = 1; nvram_set("wan_gateway", value); } if ((value = getenv("dns"))) { chomp(value); // if (nvram_invmatch("wan_get_dns",value)) // changed=1; nvram_set("wan_get_dns", value); } /* * Don't care for linksys spec if ((value = getenv("wins"))) * nvram_set("wan_wins", value); if ((value = getenv("hostname"))) * sethostname(value, strlen(value) + 1); */ if ((value = getenv("domain"))) { chomp(value); if (nvram_invmatch("wan_get_domain", value)) changed = 1; nvram_set("wan_get_domain", value); // HeartBeat need to use } if ((value = getenv("lease"))) { chomp(value); nvram_set("wan_lease", value); expires(atoi(value)); } if (!changed) { cprintf("interface hasnt changed, do nothing\n"); return 0; } stop_firewall(); cprintf("configure to IF[%s] , IP[%s], MASK[%s]\n", wan_ifname, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); if (nvram_match("wan_proto", "pptp") && nvram_match("pptp_use_dhcp", "1")) eval("ifconfig", wan_ifname, temp_wan_ipaddr, "netmask", temp_wan_netmask, "up"); else eval("ifconfig", wan_ifname, nvram_safe_get("wan_ipaddr"), "netmask", nvram_safe_get("wan_netmask"), "up"); /* * We only want to exec bellow functions after dhcp get ip if the * wan_proto is heartbeat */ #ifdef HAVE_HEARTBEAT if (nvram_match("wan_proto", "heartbeat")) { int i = 0; /* * Delete all default routes */ while (route_del(wan_ifname, 0, NULL, NULL, NULL) == 0 || i++ < 10) ; /* * Set default route to gateway if specified */ route_add(wan_ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0"); /* * save dns to resolv.conf */ dns_to_resolv(); stop_udhcpd(); start_udhcpd(); start_firewall(); stop_wland(); start_wshaper(); start_wland(); start_heartbeat_boot(); } #else if (0) { // nothing } #endif #ifdef HAVE_PPTP else if (nvram_match("wan_proto", "pptp") && nvram_match("pptp_use_dhcp", "1")) { char pptpip[64]; struct dns_lists *dns_list = NULL; dns_to_resolv(); dns_list = get_dns_list(); int i = 0; if (dns_list) { for (i = 0; i < dns_list->num_servers; i++) route_add(wan_ifname, 0, dns_list->dns_server[i], nvram_safe_get("wan_gateway"), "255.255.255.255"); free(dns_list); } route_add(wan_ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0"); nvram_set("wan_gateway_buf", nvram_get("wan_gateway")); getIPFromName(nvram_safe_get("pptp_server_name"), pptpip); nvram_set("pptp_server_ip", pptpip); // Add the route to the PPTP server on the wan interface for pptp // client to reach it if (nvram_match("wan_gateway", "0.0.0.0") || nvram_match("wan_netmask", "0.0.0.0")) route_add(wan_ifname, 0, nvram_safe_get("pptp_server_ip"), nvram_safe_get("wan_gateway"), "255.255.255.255"); else route_add(wan_ifname, 0, nvram_safe_get("pptp_server_ip"), nvram_safe_get("wan_gateway"), nvram_safe_get("wan_netmask")); } #endif #ifdef HAVE_L2TP else if (nvram_match("wan_proto", "l2tp")) { char l2tpip[64]; struct dns_lists *dns_list = NULL; dns_to_resolv(); dns_list = get_dns_list(); int i = 0; if (dns_list) { for (i = 0; i < dns_list->num_servers; i++) route_add(wan_ifname, 0, dns_list->dns_server[i], nvram_safe_get("wan_gateway"), "255.255.255.255"); free(dns_list); } /* * Backup the default gateway. It should be used if L2TP connection * is broken */ nvram_set("wan_gateway_buf", nvram_get("wan_gateway")); getIPFromName(nvram_safe_get("l2tp_server_name"), l2tpip); nvram_set("l2tp_server_ip", l2tpip); route_add(wan_ifname, 0, nvram_safe_get("l2tp_server_ip"), nvram_safe_get("wan_gateway"), "255.255.255.255"); start_firewall(); start_l2tp_boot(); } #endif else { cprintf("start wan done\n"); start_wan_done(wan_ifname); } nvram_set("dhcpc_done", "1"); cprintf("done\n"); return 0; }
// used for various testing static int rctest_main(int argc, char *argv[]) { int on; if (argc < 2) { _dprintf("test what?\n"); } else if (strcmp(argv[1], "rc_service")==0) { notify_rc(argv[2]); } else if(strcmp(argv[1], "get_phy_status")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_status %x\n", get_phy_status(mask)); } else if(strcmp(argv[1], "get_phy_speed")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask)); } else if(strcmp(argv[1], "set_phy_ctrl")==0) { int mask, ctrl; mask = atoi(argv[2]); ctrl = atoi(argv[3]); TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl)); } else if(strcmp(argv[1], "handle_notifications")==0) { handle_notifications(); } else if(strcmp(argv[1], "check_action")==0) { _dprintf("check: %d\n", check_action()); } else if(strcmp(argv[1], "nvramhex")==0) { int i; char *nv; nv = nvram_safe_get(argv[2]); _dprintf("nvram %s(%d): ", nv, strlen(nv)); for(i=0;i<strlen(nv);i++) { _dprintf(" %x", (unsigned char)*(nv+i)); } _dprintf("\n"); } else { on = atoi(argv[2]); _dprintf("%s %d\n", argv[1], on); if (strcmp(argv[1], "vlan") == 0) { if(on) start_vlan(); else stop_vlan(); } else if (strcmp(argv[1], "lan") == 0) { if(on) start_lan(); else stop_lan(); } else if (strcmp(argv[1], "wl") == 0) { if(on) { start_wl(); lanaccess_wl(); } } else if (strcmp(argv[1], "wan") == 0) { if(on) start_wan(); else stop_wan(); } else if (strcmp(argv[1], "wan_port") == 0) { if(on) start_wan_port(); else stop_wan_port(); } else if (strcmp(argv[1], "firewall") == 0) { //if(on) start_firewall(); //else stop_firewall(); } else if (strcmp(argv[1], "watchdog") == 0) { if(on) start_watchdog(); else stop_watchdog(); } #if ! (defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK)) else if (strcmp(argv[1], "watchdog02") == 0) { if(on) start_watchdog02(); else stop_watchdog02(); } #endif /* ! (RTCONFIG_QCA || RTCONFIG_RALINK) */ else if (strcmp(argv[1], "sw_devled") == 0) { if(on) start_sw_devled(); else stop_sw_devled(); } #ifdef RTCONFIG_FANCTRL else if (strcmp(argv[1], "phy_tempsense") == 0) { if(on) start_phy_tempsense(); else stop_phy_tempsense(); } #endif #ifdef RTCONFIG_BCMWL6 #ifdef RTCONFIG_PROXYSTA else if (strcmp(argv[1], "psta_monitor") == 0) { if(on) start_psta_monitor(); else stop_psta_monitor(); } #endif #endif #ifdef RTCONFIG_IPERF else if (strcmp(argv[1], "monitor") == 0) { if(on) start_monitor(); else stop_monitor(); } #endif else if (strcmp(argv[1], "qos") == 0) {//qos test if(on){ #ifdef RTCONFIG_RALINK if (module_loaded("hw_nat")) { modprobe_r("hw_nat"); sleep(1); #if 0 f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "0", 0, 0); f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "0", 0, 0); #endif } #endif add_iQosRules(get_wan_ifname(wan_primary_ifunit())); #ifdef RTCONFIG_BWDPI if(nvram_get_int("qos_type") == 1) { start_dpi_engine_service(); // force to rebuild firewall to avoid some loopback issue if (nvram_match("fw_nat_loopback", "2")) start_firewall(wan_primary_ifunit(), 0); } else #endif start_iQos(); } else { #ifdef RTCONFIG_RALINK if (nvram_get_int("hwnat") && /* TODO: consider RTCONFIG_DUALWAN case */ // !nvram_match("wan0_proto", "l2tp") && // !nvram_match("wan0_proto", "pptp") && // !(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") && // (nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) && // (nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) && !module_loaded("hw_nat")) { #if 0 f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "2", 0, 0); f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "2", 0, 0); #endif #if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN300) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTAC54U) || defined(RTN56UB2) if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", ""))) #endif { modprobe("hw_nat"); sleep(1); } } #endif #ifdef RTCONFIG_BWDPI if(nvram_get_int("qos_type") == 1){ stop_dpi_engine_service(1); } else #endif stop_iQos(); del_iQosRules(); } } #ifdef RTCONFIG_WEBDAV else if (strcmp(argv[1], "webdav") == 0) { if(on) start_webdav(); } #endif #ifdef RTCONFIG_TUNNEL else if (strcmp(argv[1], "mastiff") == 0) { if(on) start_mastiff(); } #endif else if (strcmp(argv[1], "gpiow") == 0) { if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "gpior") == 0) { printf("%d\n", get_gpio(atoi(argv[2]))); } else if (strcmp(argv[1], "gpiod") == 0) { if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "init_switch") == 0) { init_switch(); } else if (strcmp(argv[1], "set_action") == 0) { set_action(on); } else if (strcmp(argv[1], "pwr_usb") == 0) { set_pwr_usb(atoi(argv[2])); _dprintf("done.\n"); } else if (strcmp(argv[1], "enc_chk") == 0) { unsigned char enc_buf[ENC_WORDS_LEN]; unsigned char dec_buf[DATA_WORDS_LEN + 1]; _dprintf("get enc str:[%s]\n", enc_str(argv[2], (char *) enc_buf)); _dprintf("get dec str:[%s]\n", dec_str((char *) enc_buf, (char *) dec_buf)); _dprintf("done(%d)\n", strcmp(argv[2], (const char *) dec_buf)); } #ifdef RTCONFIG_BCMFA else if (strcmp(argv[1], "fa_rev") == 0) { _dprintf("(%d) done.\n", get_fa_rev()); } else if (strcmp(argv[1], "fa_dump") == 0) { _dprintf("(%d) done.\n", get_fa_dump()); } #endif else { printf("what?\n"); } } return 0; }