function dhcpc6setup($inf) { $hlp = "/var/servd/" . $inf . "-dhcp6c.sh"; $pid = "/var/servd/" . $inf . "-dhcp6c.pid"; $cfg = "/var/servd/" . $inf . "-dhcp6c.cfg"; /* DHCP over PPP session ? */ //$previnf = XNODE_get_var($inf."_PREVINF"); //XNODE_del_var($inf."_PREVINF"); $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0); $previnf = query($infp . "/infprevious"); $phyinf = query($infp . "/phyinf"); $inet = query($infp . "/inet"); $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0); $devnam = PHYINF_getifname($phyinf); /* dslite ? */ $nextinf = query($infp . "/infnext"); //if ($mode=="PPPDHCP" && $_GLOBALS["PREVINF"]!="") //msg("mode is ".$mode.", previnf is ".$previnf); startcmd('# dhcpc6setup(' . $inf . ',' . $inetp . ')'); startcmd("previnf is " . $previnf . ", nextinf is " . $nextinf); //if ($mode=="PPPDHCP" && $previnf!="") //{ // $pppdev = PHYINF_getruntimeifname($previnf); // if ($pppdev=="") return error("no PPP device."); //} /* Gererate DHCP-IAID from 32-bit of mac address*/ $mac = PHYINF_getphymac($inf); $mac1 = cut($mac, 3, ":"); $mac2 = cut($mac, 0, ":"); $mac3 = cut($mac, 1, ":"); $mac4 = cut($mac, 2, ":"); $iaidstr = $mac1 . $mac2 . $mac3 . $mac4; $iaid = strtoul($iaidstr, 16); /* Generate configuration file. */ $send = "\tinformation-only;\n"; $idas = ""; //if($mode=="PPPDHCP") $dname = $pppdev; //else $dname = $devnam; $dname = $devnam; $nextinfp = XNODE_getpathbytarget("", "inf", "uid", $nextinf, 0); $nextinet = query($nextinfp . "/inet"); $nextinetp = XNODE_getpathbytarget("inet", "entry", "uid", $nextinet, 0); $nextmode = query($nextinetp . "/ipv4/ipv4in6/mode"); if ($nextinf != "" && $nextmode == "dslite") { $rqstmsg = "\trequest aftr-server-domain-name;\n"; } else { $rqstmsg = ""; } fwrite(w, $cfg, "interface " . $dname . " {\n" . $send . $rqstmsg . "\tscript \"" . $hlp . "\";\n" . "};\n" . $idas); /* generate callback script */ fwrite(w, $hlp, "#!/bin/sh\n" . "phpsh /etc/services/INET/inet6_dhcpc_helper.php" . " INF=" . $inf . " MODE=INFOONLY" . " DEVNAM=" . $dname . " GATEWAY=" . "" . " DHCPOPT=" . "" . ' "NAMESERVERS=$new_domain_name_servers"' . ' "NEW_ADDR=$new_addr"' . ' "NEW_PD_PREFIX=$new_pd_prefix"' . ' "NEW_PD_PLEN=$new_pd_plen"' . ' "DNS=' . "" . '"' . ' "NEW_AFTR_NAME=$new_aftr_name"' . ' "NTPSERVER=$new_ntp_servers"' . "\n"); /* Start DHCP client */ startcmd("chmod +x " . $hlp); //if ($pppdev=="") startcmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL " . $devnam); //else startcmd("dhcp6c -c ".$cfg." -p ".$pid." -t LL -o ".$devnam." ".$pppdev); stopcmd("/etc/scripts/killpid.sh /var/servd/" . $inf . "-dhcp6c.pid"); }
function getphyinf($inf) { $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0); if ($infp == "") { return ""; } $phyinf = query($infp . "/phyinf"); return PHYINF_getifname($phyinf); }
function wandetectIPV4($inf) { $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0); $phyinf = query($infp . "/phyinf"); $phyinfp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0); $ifname = PHYINF_getifname($phyinf); $linkstatus = query($phyinfp . "/linkstatus"); if ($linkstatus == "") { return "ERROR"; } del("/runtime/wanispppoe"); del("/runtime/wanisdhcp"); addevent("detectpppoe", "xmldbc -s /runtime/wanispppoe \\`pppd pty_pppoe pppoe_discovery pppoe_device " . $ifname . "\\` &"); addevent("detectdhcp", "xmldbc -s /runtime/wanisdhcp \\`udhcpc -i " . $ifname . " -d -D 1 -R 3\\`&"); event("detectpppoe"); event("detectdhcp"); return "OK"; }
function starspeed($name) { /* Get the interface */ $infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0); if ($infp == "") { return; } $inet = query($infp . "/inet"); $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0); $phyinf = query($infp . "/phyinf"); $user = get("s", $inetp . "/ppp4/username"); $pass = get("s", $inetp . "/ppp4/password"); $ifname = PHYINF_getifname($phyinf); $enable = query($inetp . "/ppp4/pppoe/starspeed/enable"); $region = get("s", $inetp . "/ppp4/pppoe/starspeed/region"); if ($enable == 1) { fwrite("a", $_GLOBALS["START"], "/etc/scripts/starspeed.sh \"" . $user . "\" \"" . $pass . "\" \"" . $ifname . "\" \"" . $region . "\"\n"); } }
function wandetect($inf) { $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0); $phyinf = query($infp . "/phyinf"); $phyinfp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0); $ifname = PHYINF_getifname($phyinf); $linkstatus = query($phyinfp . "/linkstatus"); if ($linkstatus == "") { return "UNKNOWN"; } setattr("/runtime/detectpppoe", "get", "pppd pty_pppoe pppoe_discovery pppoe_device " . $ifname); $ret = query("/runtime/detectpppoe"); del("/runtime/detectpppoe"); if ($ret == "yes") { return "PPPOE"; } setattr("/runtime/detectdhcp", "get", "udhcpc -i " . $ifname . " -d -D 1 -R 2"); $ret = query("/runtime/detectdhcp"); del("/runtime/detectdhcp"); if ($ret == "yes") { return "DHCP"; } return "UNKNOWN"; }
<?php include "/htdocs/phplib/xnode.php"; include "/htdocs/phplib/phyinf.php"; $infp = XNODE_getpathbytarget("", "inf", "uid", $INF, 0); $phyinf = query($infp . "/phyinf"); $ifname = PHYINF_getifname($phyinf); echo 'noauth nodeflate nobsdcomp nodetach noccp\\n'; echo 'lcp-echo-failure 3\\n'; echo 'lcp-echo-interval 30\\n'; echo 'lcp-echo-failure-2 14\\n'; echo 'lcp-echo-interval-2 6\\n'; echo 'lcp-timeout-1 10\\n'; echo 'lcp-timeout-2 10\\n'; echo 'ipcp-accept-remote ipcp-accept-local\\n'; echo 'mtu 1454\\n'; echo 'linkname DISCOVER\\n'; echo 'ipparam DISCOVER\\n'; echo 'usepeerdns\\n'; echo 'defaultroute\\n'; echo 'user ""\\n'; echo 'password ""\\n'; echo 'noipdefault\\n'; echo 'kpppoe pppoe_device ' . $ifname . '\\n'; echo 'pppoe_hostuniq\\n';
function phyinf_setup($ifname) { $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $ifname, 0); if ($phyinf == "") { error("9"); return; } if (query($phyinf . "/active") != "1") { error("8"); return; } /* Set media */ $media = query($phyinf . "/media/linktype"); if ($media == "") { $media = "AUTO"; } phyinf_setmedia($mode, $ifname, $media); startcmd("# PHYINF." . $ifname . ": media=" . $media . ", VID=" . $vid); /* Set IPv6 */ if (isfile("/proc/net/if_inet6") == 1) { /* IPv6 is disabled by default (we modified the kernel code). * Enable IPv6 here. */ $dev = PHYINF_getifname($ifname); if ($dev != "") { startcmd("echo 0 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6"); stopcmd("echo 1 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6"); } } /* Set the MAC address */ $stsp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $ifname, 0); if ($stsp == "") { /* The LAYOUT service should be start before PHYINF.XXX. * We should never reach here !! */ fwrite("w", "/dev/console", "PHYINF: The LAYOUT service should be start before PHYINF !!!\n"); } else { $mac = query($phyinf . "/macaddr"); if ($mac == "") { $mac = XNODE_get_var("MACADDR_" . $ifname); } $mac = tolower($mac); $curr = tolower(query($stsp . "/macaddr")); startcmd("# MAC: currrent " . $curr . ", target " . $mac); if ($mac != $curr) { SHELL_info($_GLOBALS["START"], "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . "!!! Bad MAC address. Device may work abnormally. !!!\n" . "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); } } }
if ($ACT == "START") { echo 'echo RA detect in START... > /dev/console\\n'; /* generate callback script */ /* send RS */ $hlp = "/var/servd/" . $INF . "-test-rdisc6.sh"; fwrite(w, $hlp, "#!/bin/sh\n" . "echo [\$0]: [{$IFNAME}] [{$MFLAG}] [{$OFLAG}] > /dev/console\n" . "phpsh /etc/services/INET/inet6_rdisc6_helper.php" . ' "IFNAME=$IFNAME"' . ' "MFLAG=$MFLAG"' . ' "OFLAG=$OFLAG"' . ' "PREFIX=$PREFIX"' . ' "PFXLEN=$PFXLEN"' . ' "LLADDR=$LLADDR"' . ' "RDNSS=$RDNSS"' . "\n"); echo 'chmod +x ' . $hlp . '\\n'; echo 'rdisc6 -c ' . $hlp . ' -q -f ' . $devnam . ' &\\n'; // -f: wait RA forever. echo 'xmldbc -t autoconf.dis.guest:10:"sh /etc/events/WANV6_AUTOCONF_DETECT.sh ' . $INF . ' CHECK"\\n'; } else { if ($ACT == "CABLESTART") { echo 'echo RA detect ... > /dev/console\\n'; $infp = XNODE_getpathbytarget("", "inf", "uid", $INF, 0); $phyinf = query($infp . "/phyinf"); $devnam = PHYINF_getifname($phyinf); /* generate callback script */ $hlp = "/var/servd/" . $INF . "-test-rdisc6.sh"; fwrite(w, $hlp, "#!/bin/sh\n" . "echo [\$0]: [{$IFNAME}] [{$MFLAG}] [{$OFLAG}] > /dev/console\n" . "phpsh /etc/services/INET/inet6_rdisc6_helper.php" . ' "IFNAME=$IFNAME"' . ' "MFLAG=$MFLAG"' . ' "OFLAG=$OFLAG"' . ' "PREFIX=$PREFIX"' . ' "PFXLEN=$PFXLEN"' . ' "LLADDR=$LLADDR"' . ' "RDNSS=$RDNSS"' . "\n"); echo 'chmod +x ' . $hlp . '\\n'; //echo 'rdisc6 -c '.$hlp.' -q '.$devnam.' &\n'; echo 'rdisc6 -c ' . $hlp . ' -q -f ' . $devnam . ' &\\n'; // -f: wait RA forever. echo 'xmldbc -t autoconf.dis.guest:10:"sh /etc/events/WANV6_AUTOCONF_DETECT.sh ' . $INF . ' CABLECHECK"\\n'; } else { if ($ACT == "DHCP6START") { echo 'xmldbc -X /runtime/services/wandetect6\\n'; dhcp_client("STATEFUL", $INF, $devnam, "IA-PD", "", "", "0"); echo 'xmldbc -t autoconf.dis.guest:20:"sh /etc/events/WANV6_AUTOCONF_DETECT.sh ' . $INF . ' CHECK"\\n'; } else { if ($ACT == "DHCP6DSSTART") {
function ipv6_child($child) { /* Get the config */ $infp = XNODE_getpathbytarget("", "inf", "uid", $child, 0); if ($infp == "") { echo "# " . $child . " is not found !!!\n"; return; } $phyinf = query($infp . "/phyinf"); $defrt = query($infp . "/defaultroute"); /* Create the runtime nodes. */ $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $child, 1); set($stsp . "/phyinf", $phyinf); set($stsp . "/defaultroute", $defrt); /* Get the config. */ $ipaddr = XNODE_get_var($child . "_IPADDR"); $prefix = XNODE_get_var($child . "_PREFIX"); $devnam = PHYINF_getphyinf($child); $phyinfv = XNODE_get_var($child . "_PHYINF"); if ($phyinfv != "") { $phyinf = $phyinfv; $devnam = PHYINF_getifname($phyinf); set($stsp . "/phyinf", $phyinf); } /* Get dhcp-pd config. */ $pdnetwork = XNODE_get_var($child . "_PDNETWORK"); $pdprefix = XNODE_get_var($child . "_PDPREFIX"); //$enablepd = query($stsp."/dhcps6/pd/enable"); echo "# pdnetwork :" . $pdnetwork . "\n"; echo "# pdprefix :" . $pdprefix . "\n"; if ($pdnetwork != "" && $pdprefix != "") { set($stsp . "/dhcps6/pd/network", $pdnetwork); set($stsp . "/dhcps6/pd/prefix", $pdprefix); } $pdplft = XNODE_get_var($child . "_PDPLFT"); $pdvlft = XNODE_get_var($child . "_PDVLFT"); echo "# pdplft :" . $pdplft . "\n"; echo "# pdvlft :" . $pdvlft . "\n"; if ($pdplft != "") { set($stsp . "/dhcps6/pd/preferlft", $pdplft); } if ($pdvlft != "") { set($stsp . "/dhcps6/pd/validlft", $pdvlft); } /* Clear the variables. */ /* XNODE_del_var($child."_IPADDR"); XNODE_del_var($child."_PREFIX"); XNODE_del_var($child."_ADDRTYPE"); XNODE_del_var($child."_PHYINF"); XNODE_del_var($child."_PDNETWORK"); XNODE_del_var($child."_PDPREFIX"); XNODE_del_var($child."_PDPLFT"); XNODE_del_var($child."_PDVLFT"); */ /* enable IPv6 */ fwrite(w, "/proc/sys/net/ipv6/conf/" . $devnam . "/disable_ipv6", 0); $path_eth = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0); $val_eth = query($path_eth . "/ipv6/link/ipaddr"); if ($path_eth == "") { return; } else { if ($val_eth != "") { stopcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=DETACH INF=" . $child); startcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH INF=" . $child . " MODE=CHILD DEVNAM=" . $devnam . " IPADDR=" . $ipaddr . " PREFIX=" . $prefix); } else { return 0; } } /* Start/Stop scripts */ //stopcmd( "phpsh /etc/scripts/IPV6.INET.php ACTION=DETACH INF=".$child); //startcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH INF=".$child. // " MODE=CHILD DEVNAM=".$devnam." IPADDR=".$ipaddr." PREFIX=".$prefix); /* record */ stopcmd("rm -f /var/run/CHILD." . $child . ".UP"); startcmd("echo 1 > /var/run/CHILD." . $child . ".UP"); /* delay 2s to wait ipv6 address take effect before HTTP service */ //startcmd("sleep 2"); }
function phyinf_setup($ifname) { $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $ifname, 0); if ($phyinf == "") { error("9"); return; } if (query($phyinf . "/active") != "1") { error("8"); return; } /* Get layout mode */ $layout = query("/runtime/device/layout"); if ($layout == "bridge") { $mode = "1BRIDGE"; } else { if ($layout == "router") { $mode = query("/runtime/device/router/mode"); } else { error("10"); return; } } if ($mode == "") { $mode = "1W1L"; } /* Set media */ $media = query($phyinf . "/media/linktype"); if ($media == "") { $media = "AUTO"; } phyinf_setmedia($mode, $ifname, $media); startcmd("# PHYINF." . $ifname . ": media=" . $media . ", VID=" . $vid); /* Set IPv6 */ if (isfile("/proc/net/if_inet6") == 1) { if ($layout == "router") { /********************************************************************************** * only enable ipv6 function at br0(LAN) and eth1(WAN), other disable by default *********************************************************************************/ phyinf_setipv6($mode, $ifname); } else { $dev = PHYINF_getifname($ifname); if ($dev != "") { startcmd("echo 0 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6"); stopcmd("echo 1 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6"); } } } /* Set the MAC address */ $stsp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $ifname, 0); if ($stsp == "") { /* The LAYOUT service should be start before PHYINF.XXX. * We should never reach here !! */ fwrite("w", "/dev/console", "PHYINF: The LAYOUT service should be start before PHYINF !!!\n"); } else { $mac = query($phyinf . "/macaddr"); if ($mac == "") { $mac = XNODE_get_var("MACADDR_" . $ifname); } $mac = tolower($mac); $curr = tolower(query($stsp . "/macaddr")); startcmd("# MAC: currrent " . $curr . ", target " . $mac); if ($mac != $curr) { SHELL_info($_GLOBALS["START"], "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . "!!! Bad MAC address. Device may work abnormally. !!!\n" . "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); } } }