Exemple #1
0
function phyinf_setup($ifname)
{
    $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $ifname, 0);
    if ($phyinf == "") {
        pifsetup_error("9");
        return;
    }
    if (query($phyinf . "/active") != "1") {
        pifsetup_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 {
            pifsetup_error("9");
            return;
        }
    }
    if ($mode == "") {
        $mode = "1W2L";
    }
    /* Set media */
    $media = query($phyinf . "/media/linktype");
    phyinf_setmedia($mode, $ifname, $media);
    /* Set IPv6 */
    if (isfile("/proc/net/if_inet6") == 1) {
        /**********************************************************************************
         * only enable ipv6 function at br0(LAN) and eth2.2(WAN), other disable by default
         *********************************************************************************/
        phyinf_setipv6($mode, $ifname);
    }
    /* 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 {
        if (query($stsp . "/bridge/port#") > 0) {
            /* DO NOT allow to change the bridge device's MAC address. */
            startcmd("# " . $ifname . " is a bridge device, skip MAC address setting.");
        } else {
            $mac = PHYINF_gettargetmacaddr($mode, $ifname);
            $curr = tolower(query($stsp . "/macaddr"));
            if ($mac != $curr) {
                fwrite("w", "/dev/console", "PHYINF." . $ifname . ": cfg[" . $mac . "] curr[" . $curr . "], restart the device !!!\n");
                //startcmd('xmldbc -t "restart:3:/etc/init0.d/rcS"');
                $if_name = query($stsp . "/name");
                startcmd('ifconfig ' . $if_name . ' down');
                startcmd('ifconfig ' . $if_name . ' hw ether ' . $mac);
                startcmd('ifconfig ' . $if_name . ' up');
            }
        }
    }
}
Exemple #2
0
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");
        }
    }
}