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; }
$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") { echo 'xmldbc -X /runtime/services/wandetect6\\n'; dhcp_client("STATEFUL", $INF, $devnam, "IA-PD", "", "", "1"); echo 'xmldbc -t autoconf.dis.guest:20:"sh /etc/events/WANV6_AUTOCONF_DETECT.sh ' . $INF . ' CHECK"\\n'; } else { if ($ACT == "CHECK") { $mode = query("/runtime/services/wandetect6/autoconf/" . $ACT); // write by rdisc6_helper.php. echo 'echo mode is ' . $mode . ' in CHECK > /dev/console\\n'; echo 'killall rdisc6\\n'; echo 'killall dhcp6c\\n'; if ($mode == "STATEFUL" || $mode == "STATELESS") { set("/runtime/services/wandetect6/wantype", $mode); set("/runtime/services/wandetect6/desc", "Normal"); } else { set("/runtime/services/wandetect6/wantype", "unknown"); set("/runtime/services/wandetect6/desc", "No Response"); /* if result is "unknown", restart INET.WAN-5 */