コード例 #1
0
ファイル: dhcpc6.php プロジェクト: jhbsz/DIR-850L_A1
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");
}
コード例 #2
0
ファイル: RA-WAIT.php プロジェクト: jhbsz/DIR-850L_A1
function main_entry($inf, $phyinf, $devnam, $dhcpopt, $dns, $me)
{
    /* generate callback script */
    $pid = "/var/servd/" . $inf . "-rdisc6.pid";
    $hlp = "/var/servd/" . $inf . "-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"' . ' "DNSSL=$DNSSL"' . "\n");
    cmd("chmod +x " . $hlp);
    /* run rdisc */
    //cmd("killall rdisc6");
    //cmd("sleep 1");
    /* INF status path. */
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
    if ($stsp == "") {
        return error($inf . " has not runtime nodes !");
    }
    /* need infprev */
    $infprev = query($stsp . "/infprevious");
    if ($infprev != "") {
        $prevstsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
        $prevdevnam = query($prevstsp . "/devnam");
        $prevphyinf = query($prevstsp . "/phyinf");
    }
    /* check if interface if ppp */
    if (strstr($prevdevnam, "ppp") == "") {
        if (strstr($prevdevnam, "sit") == "") {
            cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q " . $devnam . " &");
        } else {
            msg("SIT-Autoconf mode");
            /* auto in sit mode */
            $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $prevphyinf, 0);
            if ($p != "") {
                $ipaddr = query($p . "/ipv6/link/ipaddr");
            } else {
                return error("SIT tunnel need exist!! ");
            }
            msg("ipaddr: " . $ipaddr . " and devnam: " . $prevdevnam);
            cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q -e " . $ipaddr . " " . $prevdevnam . " &");
        }
    } else {
        msg("PPP-Autoconf mode");
        /* need infprev */
        $infprev = query($stsp . "/infprevious");
        $prevstsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
        /* need infprev */
        $atype = query($prevstsp . "/inet/addrtype");
        if ($atype == "ipv6") {
            $ipaddr = query($prevstsp . "/inet/ipv6/ipaddr");
        } else {
            if ($atype == "ppp6") {
                $ipaddr = query($prevstsp . "/inet/ppp6/local");
            } else {
                return error($inf . " has wrong addrtype of infprevious");
            }
        }
        cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q -e " . $ipaddr . " " . $prevdevnam . " &");
    }
    cmd("sleep 5");
    /* Clear any old records. */
    del($stsp . "/stateless");
    /* Preparing & Get M flag */
    $child = query($stsp . "/child/uid");
    if (strstr($prevdevnam, "ppp") == "") {
        $conf = "/var/run/" . $devnam;
    } else {
        $conf = "/var/run/" . $prevdevnam;
    }
    $mflag = fread("e", $conf . ".ra_mflag");
    $oflag = fread("e", $conf . ".ra_oflag");
    $rdnss = fread("e", $conf . ".ra_rdnss");
    $dnssl = fread("e", $conf . ".ra_dnssl");
    /* need infnext */
    $infnext = query($stsp . "/infnext");
    if ($infnext != "") {
        XNODE_set_var($inf . "_NEXTINF", $infnext);
    }
    /* need dnssl info */
    if ($dnssl != "") {
        msg("DNSSL :" . $dnssl);
        XNODE_set_var($child . "_DOMAIN", $dnssl);
    }
    if (strstr($prevdevnam, "ppp") == "") {
        msg($inf . "/" . $devnam . ", M=[" . $mflag . "], O=[" . $oflag . "]");
    } else {
        msg($inf . "/" . $prevdevnam . ", M=[" . $mflag . "], O=[" . $oflag . "]");
    }
    /* according to TR-124 issue 2 */
    /* Ignore m and o flags, always start dhcp client */
    /* generate wait script */
    $ipwait = "/var/servd/INET." . $inf . "-ipwait.sh";
    fwrite(w, $ipwait, "#!/bin/sh\n" . "phpsh /etc/scripts/IP-WAIT.php" . " INF=" . $inf . " PHYINF=" . $phyinf . " DEVNAM=" . $devnam . ' "DNS=' . $dns . '"' . " ME=" . $ipwait . "\n");
    /* start script */
    cmd("chmod +x " . $ipwait);
    cmd('xmldbc -t "ra.iptest.' . $inf . ':10:' . $ipwait . '"');
    if ($child != "") {
        /* always need dhcp client */
        $dhcpopt = "IA-NA+IA-PD";
        if (strstr($prevdevnam, "ppp") == "") {
            dhcp_client("STATEFUL", $inf, $devnam, $dhcpopt, $router, $dns);
        } else {
            XNODE_set_var($inf . "_PREVINF", $infprev);
            dhcp_client("PPPDHCP", $inf, $devnam, $dhcpopt, $router, $dns);
        }
        return 0;
    } else {
        $dhcpopt = "IA-NA";
        if (strstr($prevdevnam, "ppp") == "") {
            dhcp_client("STATEFUL", $inf, $devnam, $dhcpopt, $router, $dns);
        } else {
            XNODE_set_var($inf . "_PREVINF", $infprev);
            dhcp_client("PPPDHCP", $inf, $devnam, $dhcpopt, $router, $dns);
        }
        return 0;
    }
    //not reach here
    if ($mflag == "1") {
        /* Stateful ... */
        if ($dhcpopt == "") {
            if ($child == "") {
                $dhcpopt = "IA-NA";
            } else {
                $dhcpopt = "IA-NA+IA-PD";
            }
        }
        //dhcp_client("STATEFUL", $inf, $devnam, $dhcpopt, $router, $dns);
        if (strstr($prevdevnam, "ppp") == "") {
            dhcp_client("STATEFUL", $inf, $devnam, $dhcpopt, $router, $dns);
        } else {
            XNODE_set_var($inf . "_PREVINF", $infprev);
            dhcp_client("PPPDHCP", $inf, $devnam, $dhcpopt, $router, $dns);
        }
        return 0;
    } else {
        if ($mflag == "0") {
            /* Stateless */
            $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0);
            if ($p == "") {
                return error($phyinf . " has not runtime nodes!");
            }
            /* Get self-configured IP address. */
            /*$ipaddr = query($p."/ipv6/global/ipaddr");*/
            /*$prefix = query($p."/ipv6/global/prefix");*/
            $mac = PHYINF_getphymac($inf);
            $hostid = ipv6eui64($mac);
            $ra_prefix = fread("e", $conf . ".ra_prefix");
            $prefix = fread("e", $conf . ".ra_prefix_len");
            $ipaddr = ipv6ip($ra_prefix, $prefix, $hostid, 0, 0);
            $router = fread("e", $conf . ".ra_saddr");
            if (strstr($prevdevnam, "ppp") != "") {
                $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $prevphyinf, 0);
                $llipaddr = query($p . "/ipv6/link/ipaddr");
                $hostid = ipv6hostid($llipaddr, 64);
                $ipaddr = ipv6ip($ra_prefix, $prefix, $hostid, 0, 0);
            }
            if ($ipaddr != "") {
                if ($oflag == "0" && $dns == "" && $rdnss != "") {
                    $dns = $rdnss;
                }
                msg("Stateless Self-Config IP: " . $ipaddr . "/" . $prefix);
                //$router	= fread("e", $conf."/ra_saddr");
                if ($child != "") {
                    set($stsp . "/stateless/ipaddr", $ipaddr);
                    set($stsp . "/stateless/prefix", $prefix);
                    //set($stsp."/stateless/gateway",	$router);
                    setattr($stsp . "/stateless/gateway", "get", "ip -6 route show default | scut -p via");
                    set($stsp . "/stateless/dns", $dns);
                    if ($dnssl != "") {
                        set($stsp . "/stateless/domain", $dnssl);
                    }
                    /* run dhcpc6 for the child interface, and attach at the callback of dhcpc. */
                    //dhcp_client("STATELESS", $inf, $devnam, "IA-PD", $router, $dns);
                    if (strstr($prevdevnam, "ppp") == "") {
                        dhcp_client("STATELESS", $inf, $devnam, "IA-PD", $router, $dns);
                    } else {
                        XNODE_set_var($inf . "_PREVINF", $infprev);
                        dhcp_client("PPPDHCP", $inf, $devnam, "IA-PD", $router, $dns);
                    }
                } else {
                    cmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH" . " MODE=STATELESS" . " INF=" . $inf . " DEVNAM=" . $devnam . " IPADDR=" . $ipaddr . " PREFIX=" . $prefix . " GATEWAY=" . $router . ' "DNS=' . $dns . '"');
                    if ($oflag == "1" && $dns == "") {
                        msg("STATELESS DHCP: information only.");
                        dhcp_client("INFOONLY", $inf, $devnam, "", "", "");
                    }
                }
                return 0;
            }
        }
    }
    //cmd("killall rdisc6");
    cmd("/etc/scripts/killpid.sh " . $pid);
    cmd("sleep 1");
    /* Not configured, try later. */
    cmd('xmldbc -t "ra.iptest.' . $inf . ':5:' . $me . '"');
    /* force to send RS */
    //$conf = "/proc/sys/net/ipv6/conf/".$_GLOBALS["DEVNAM"];
    //fwrite(w, $conf."/disable_ipv6",  "1");
    //fwrite(w, $conf."/disable_ipv6",  "0");
    return 0;
}
コード例 #3
0
ファイル: IP-WAIT.php プロジェクト: jhbsz/DIR-850L_A1
function main_entry($inf, $phyinf, $devnam, $dns, $me)
{
    /* INF status path. */
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
    if ($stsp == "") {
        return error($inf . " has not runtime nodes !");
    }
    $infprev = query($stsp . "/infprevious");
    if ($infprev != "") {
        $prevstsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
        $prevdevnam = query($prevstsp . "/devnam");
        $prevphyinf = query($prevstsp . "/phyinf");
    }
    /* Preparing & Get M flag */
    if (strstr($prevdevnam, "ppp") == "") {
        $conf = "/var/run/" . $devnam;
    } else {
        $conf = "/var/run/" . $prevdevnam;
    }
    $mflag = fread("e", $conf . ".ra_mflag");
    /* generate callback script */
    $hlp = "/var/servd/" . $inf . "-rdisc6.sh";
    $pid = "/var/servd/" . $inf . "-rdisc6.pid";
    $child = query($stsp . "/child/uid");
    if ($mflag == "") {
        //msg("mflag is null, kill rdisc6");
        /* kill daemon */
        cmd("/etc/scripts/killpid.sh " . $pid);
        /* check if interface if ppp */
        if (strstr($prevdevnam, "ppp") == "") {
            if (strstr($prevdevnam, "sit") == "") {
                cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q " . $devnam . " &");
            } else {
                //msg("SIT-Autoconf mode");
                /* auto in sit mode */
                $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $prevphyinf, 0);
                if ($p != "") {
                    $ipaddr = query($p . "/ipv6/link/ipaddr");
                } else {
                    return error("SIT tunnel need exist!! ");
                }
                msg("ipaddr: " . $ipaddr . " and devnam: " . $prevdevnam);
                cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q -e " . $ipaddr . " " . $prevdevnam . " &");
            }
        } else {
            //msg("PPP-Autoconf mode");
            /* need infprev */
            $infprev = query($stsp . "/infprevious");
            $prevstsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
            /* need infprev */
            $atype = query($prevstsp . "/inet/addrtype");
            if ($atype == "ipv6") {
                $ipaddr = query($prevstsp . "/inet/ipv6/ipaddr");
                /* share session with ipv4*/
            } else {
                if ($atype == "ppp6") {
                    $ipaddr = query($prevstsp . "/inet/ppp6/local");
                    /* only ipv6 session */
                } else {
                    return error($inf . " has wrong addrtype of infprevious");
                }
            }
            cmd("rdisc6 -c " . $hlp . " -p " . $pid . " -q -e " . $ipaddr . " " . $prevdevnam . " &");
        }
        //cmd("sleep 5");
        cmd('xmldbc -t "ra.iptest.' . $inf . ':10:' . $me . '"');
        return 0;
    }
    /* Preparing & Get M flag */
    $mflag = fread("e", $conf . ".ra_mflag");
    $oflag = fread("e", $conf . ".ra_oflag");
    $rdnss = fread("e", $conf . ".ra_rdnss");
    $dnssl = fread("e", $conf . ".ra_dnssl");
    /* need dnssl info */
    if ($dnssl != "") {
        msg("DNSSL :" . $dnssl);
        XNODE_set_var($child . "_DOMAIN", $dnssl);
    }
    if ($mflag != "") {
        if (strstr($prevdevnam, "ppp") == "") {
            msg($inf . "/" . $devnam . ", M=[" . $mflag . "], O=[" . $oflag . "]");
        } else {
            msg($inf . "/" . $prevdevnam . ", M=[" . $mflag . "], O=[" . $oflag . "]");
        }
    }
    $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0);
    if ($p == "") {
        return error($phyinf . " has not runtime nodes!");
    }
    if ($mflag != "") {
        /* we got ra */
        $mac = PHYINF_getphymac($inf);
        $hostid = ipv6eui64($mac);
        $ra_prefix = fread("e", $conf . ".ra_prefix");
        $prefix = fread("e", $conf . ".ra_prefix_len");
        $ra_saddr = fread("e", $conf . ".ra_saddr");
        $ipaddr = ipv6ip($ra_prefix, $prefix, $hostid, 0, 0);
        $router = fread("e", $conf . ".ra_saddr");
        if (strstr($prevdevnam, "ppp") != "") {
            $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $prevphyinf, 0);
            $llipaddr = query($p . "/ipv6/link/ipaddr");
            $hostid = ipv6hostid($llipaddr, 64);
            $ipaddr = ipv6ip($ra_prefix, $prefix, $hostid, 0, 0);
        }
        //if ($ipaddr!="")
        if ($ra_saddr != "") {
            if ($oflag == "0" && $dns == "" && $rdnss != "") {
                $dns = $rdnss;
            }
            $defrt = query($stsp . "/defaultroute");
            if ($defrt != "" && $defrt > 0 && $router != "") {
                if (isfile("/var/run/wan_ralft_zero") != 1) {
                    /* add default route and runtime node*/
                    $gateway = query($stsp . "/inet/ipv6/gateway");
                    if ($gateway != "") {
                        cmd("ip -6 route del default via " . $gateway . " dev " . $devnam . " metric " . $defrt);
                        del($stsp . "/inet/ipv6/gateway");
                    }
                    cmd("ip -6 route add default via " . $router . " dev " . $devnam . " metric " . $defrt);
                }
                //set($stsp."/inet/ipv6/gateway",$router);
                setattr($stsp . "/inet/ipv6/gateway", "get", "ip -6 route show default | scut -p via");
                /* Replace runtime dynamic route */
                /*
                $base = "/runtime/dynamic/route6";
                $cnt = query($base."/entry#");
                $i=1;
                $found=0;
                while($i<=$cnt)
                {
                	$dest  = query($base."/entry:".$i."/ipaddr");
                	$pfx   = query($base."/entry:".$i."/prefix");
                	$dname = query($base."/entry:".$i."/inf");
                	if($dest=="::" && $pfx=="0" && $dname==$inf)
                	{
                		set($base."/entry:".$i."/gateway", $router);
                		$found=1;
                		break;
                	}
                	$i++;
                }
                
                if($found=="0")
                {
                	set($base."/entry:".$i."/ipaddr", "::");
                	set($base."/entry:".$i."/prefix", "0");
                	set($base."/entry:".$i."/gateway", $router);
                	set($base."/entry:".$i."/metric", $defrt);
                	set($base."/entry:".$i."/inf", $inf);
                }
                */
                if ($child != "") {
                    set($stsp . "/stateless/ipaddr", $ipaddr);
                    set($stsp . "/stateless/prefix", $prefix);
                    //set($stsp."/stateless/gateway", $router);
                    setattr($stsp . "/stateless/gateway", "get", "ip -6 route show default | scut -p via");
                    set($stsp . "/stateless/dns", $dns);
                }
                if ($child == "" && isfile("/var/run/" . $inf . ".UP") != 1) {
                    cmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH" . " MODE=STATELESS" . " INF=" . $inf . " DEVNAM=" . $devnam . " IPADDR=" . $ipaddr . " PREFIX=" . $prefix . " GATEWAY=" . $router . ' "DNS=' . $dns . '"');
                }
            }
        }
        return 0;
    }
    /* Not configured, try later. */
    //cmd("killall rdisc6");
    //cmd("/etc/scripts/killpid.sh /var/servd/".$inf."-rdisc6.pid");
    //msg("mflag is null, kill rdisc6-part2");
    //cmd("/etc/scripts/killpid.sh ".$pid);
    //cmd("sleep 1");
    //cmd('xmldbc -t "ra.iptest.'.$inf.':5:'.$me.'"');
    //cmd('xmldbc -t "ra.iptest.'.$inf.':10:'.$me.'"');
    //return 0;
}
コード例 #4
0
function handle_stateless($inf, $prefix, $pfxlen)
{
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
    if ($stsp == "") {
        msg("STATLESS - no runtime for " . $inf);
        return;
    }
    if ($prefix == "" || $pfxlen == "") {
        msg("STATELESS - no prefix");
        return;
    }
    /* Prepare child. */
    msg("STATELESS - Got prefix " . $prefix . "/" . $pfxlen);
    $NEW_PD_PREFIX = $prefix;
    $NEW_PD_PLEN = $pfxlen;
    $child = query($stsp . "/child/uid");
    $mac = PHYINF_getphymac($child);
    $hostid = ipv6eui64($mac);
    if ($NEW_PD_PLEN < 64) {
        /* handle blackhole issue */
        //cmd("ip -6 route add blackhole ".$prefix."/".$pfxlen." dev lo");
        //set($stsp."/blackhole/prefix", $prefix);
        //set($stsp."/blackhole/plen", $pfxlen);
        $holecnt = query($stsp . "/blackhole/count");
        if ($holecnt == "") {
            $holecnt = 1;
            set($stsp . "/blackhole/entry:" . $holecnt . "/prefix", $prefix);
            set($stsp . "/blackhole/entry:" . $holecnt . "/plen", $pfxlen);
            set($stsp . "/blackhole/count", $holecnt);
            cmd("ip -6 route add blackhole " . $prefix . "/" . $pfxlen . " dev lo");
        }
        $slalen = 64 - $pfxlen;
        $ipaddr = ipv6ip($prefix, $pfxlen, $hostid, 1, $slalen);
        $pfxlen = 64;
    } else {
        $ipaddr = ipv6ip($prefix, $pfxlen, $hostid, 0, 0);
    }
    /* Check renew, do nothing if we got the same prefix and prefix len as previous ones */
    $oldip = query($stsp . "/child/ipaddr");
    $oldpfl = query($stsp . "/child/prefix");
    if ($oldip == $ipaddr && $oldpfl == $pfxlen) {
        msg("STATELESS - Renew but do nothing");
        return;
    }
    set($stsp . "/child/ipaddr", $ipaddr);
    set($stsp . "/child/prefix", $pfxlen);
    set($stsp . "/child/pdnetwork", strip($_GLOBALS["NEW_PD_PREFIX"]));
    set($stsp . "/child/pdprefix", strip($_GLOBALS["NEW_PD_PLEN"]));
    set($stsp . "/child/pdplft", strip($_GLOBALS["NEW_PD_PLTIME"]));
    set($stsp . "/child/pdvlft", strip($_GLOBALS["NEW_PD_VLTIME"]));
    $childgz = query($stsp . "/childgz/uid");
    if ($childgz != "") {
        $mac = PHYINF_getphymac($childgz);
        msg("Guest zone mac is " . $mac);
        $hostid = ipv6eui64($mac);
        if ($NEW_PD_PLEN < 64) {
            $cipaddr = ipv6ip($prefix, $pfxlen, $hostid, 0, 64 - $pfxlen);
            $cpfxlen = 64;
        } else {
            //If pd length is bigger than 63, don't set to guest zone
            $cipaddr = "";
            $cpfxlen = "";
        }
        if ($cipaddr != "") {
            set($stsp . "/childgz/ipaddr", $cipaddr);
            set($stsp . "/childgz/prefix", $cpfxlen);
            set($stsp . "/childgz/pdnetwork", strip($_GLOBALS["NEW_PD_PREFIX"]));
            set($stsp . "/childgz/pdprefix", strip($_GLOBALS["NEW_PD_PLEN"]));
            set($stsp . "/childgz/pdplft", strip($_GLOBALS["NEW_PD_PLTIME"]));
            set($stsp . "/childgz/pdvlft", strip($_GLOBALS["NEW_PD_VLTIME"]));
        }
    }
    $DOMAIN = strip($_GLOBALS["DOMAIN"]);
    if ($DOMAIN != "") {
        XNODE_set_var($child . "_DOMAIN", $DOMAIN);
    }
    XNODE_set_var($child . "_PDPLFT", strip($_GLOBALS["NEW_PD_PLTIME"]));
    XNODE_set_var($child . "_PDVLFT", strip($_GLOBALS["NEW_PD_VLTIME"]));
    msg("STATELESS - Child " . $ipaddr . "/" . $pfxlen);
    $DNS = strip($_GLOBALS["DNS"]);
    $NAMESERVERS = strip($_GLOBALS["NAMESERVERS"]);
    /* Combine the user config and DHCP server setting. */
    $dns = $DNS;
    /*
    if ($NAMESERVERS!="")
    {
    	if ($dns=="")	$dns = $NAMESERVERS;
    	else			$dns = $dns." ".$NAMESERVERS;
    }
    */
    $infprev = query($stsp . "/infprevious");
    if ($infprev != "") {
        $stsprevp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
        $pdevnam = query($stsprevp . "/devnam");
        $conf = "/var/run/" . $pdevnam;
    } else {
        $conf = "/var/run/" . query($stsp . "/devnam");
    }
    //$oflag = fread("e", $conf.".ra_oflag");
    //if($oflag=="1")
    //{
    if ($NAMESERVERS != "") {
        if ($dns == "") {
            $dns = $NAMESERVERS;
        } else {
            $dns = $dns . " " . $NAMESERVERS;
        }
    }
    //}
    /* DS-Lite info */
    $remote = strip($_GLOBALS["NEW_AFTR_NAME"]);
    if ($remote != "") {
        set($stsp . "/inet/ipv4/ipv4in6/remote", $remote);
    }
    anchor($stsp);
    cmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH" . " MODE=STATELESS" . " INF=" . $inf . " DEVNAM=" . query("devnam") . " IPADDR=" . query("stateless/ipaddr") . " PREFIX=" . query("stateless/prefix") . " GATEWAY=" . query("stateless/gateway") . ' "DNS=' . $dns . '"');
    /*del($stsp."/stateless");*/
    /*renew may cause wan ip be disappered*/
}
コード例 #5
0
ファイル: V6IN4-TUNNEL.php プロジェクト: jhbsz/DIR-850L_A1
function prepare_tsp_child($stsp, $child)
{
    $mac = PHYINF_getphymac($child);
    $hostid = ipv6eui64($mac);
    /* If the prefix is less than 64, the child can use 64 bits prefix length. */
    $prefix = $_GLOBALS["TSP_PREFIX"] . "::";
    $plen = $_GLOBALS["TSP_PREFIXLEN"];
    if ($plen < 64) {
        $plen = 64;
    }
    $ipaddr = ipv6ip($prefix, $plen, $hostid, 0, 0);
    TRACE_debug("INET: TSP Child [" . $child . "] use " . $ipaddr . "/" . $plen);
    set($stsp . "/child/uid", $child);
    set($stsp . "/child/ipaddr", $ipaddr);
    set($stsp . "/child/prefix", $plen);
}