X-Git-Url: http://git.pjr.cc/?p=CBFWR.git;a=blobdiff_plain;f=libcbfwr%2Fconfig.php;h=70878f58a64e6987dd944ac1b7e59f1a7c9af9f1;hp=e0b4f37702f782d6fc883cef23ec4420677cfea2;hb=cb45585d92144a65ff25bc1109cde4cbf60913de;hpb=b571fcf2648a6d5a4893125cb97db4f3f73ee134 diff --git a/libcbfwr/config.php b/libcbfwr/config.php index e0b4f37..70878f5 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -41,6 +41,11 @@ class Config { $this->config = $config; } + function parseEthtool($interface) + { + // im not going to enjoy this, not one little bit + } + function findHardware() { @@ -63,10 +68,22 @@ class Config { } fclose($fp); } - if(file_exists("/sys/class/net/$fname/mtu")) $this->config["hardware"]["netdev"][$fname]["mtu"] = file_get_contents("/sys/class/net/$fname/mtu"); - if(file_exists("/sys/class/net/$fname/address")) $this->config["hardware"]["netdev"][$fname]["hwaddress"] = file_get_contents("/sys/class/net/$fname/address"); + + // find hardware + if(file_exists("/sys/class/net/$fname/mtu")) $this->config["hardware"]["netdev"][$fname]["mtu"] = trim(file_get_contents("/sys/class/net/$fname/mtu")); + if(file_exists("/sys/class/net/$fname/address")) $this->config["hardware"]["netdev"][$fname]["hwaddress"] = trim(file_get_contents("/sys/class/net/$fname/address")); if(file_exists("/sys/class/net/$fname/bonding")) $this->config["hardware"]["netdev"][$fname]["bonding"] = true; if(file_exists("/sys/class/net/$fname/bridge")) $this->config["hardware"]["netdev"][$fname]["bridge"] = true; + if(file_exists("/sys/class/net/$fname/duplex")) { + $myval = trim(file_get_contents("/sys/class/net/$fname/duplex")); + if($myval == null) $myval = "default"; + $this->config["hardware"]["netdev"][$fname]["duplex"] = $myval; + } + if(file_exists("/sys/class/net/$fname/speed")) { + $myval = trim(file_get_contents("/sys/class/net/$fname/speed")); + if($myval == null) $myval = "default"; + $this->config["hardware"]["netdev"][$fname]["speed"] = $myval; + } } } } @@ -112,6 +129,27 @@ class Config { } } + function resolveInterfaceName($name) + { + // $config only ever contains real interface names + if(isset($this->config["interface"]["dev"][$name])) return $name; + + if(isset($this->config["interface"])) { + foreach($this->config["interface"]["dev"] as $key => $var) { + if(isset($var["name"])) { + if($var["name"] == $name) { + return $key; + } + } + } + } else { + // have to assume its a hardware name and check /sys + if(file_exists("/sys/class/net/$name")) return $name; + } + + return null; + } + function addConfigLine($line, $lineno=0) { $line_n = trim($line); @@ -125,6 +163,7 @@ class Config { } echo "process command ".$expl[0]."\n"; + // TODO: when dealing with descriptions, we need to deal with a null description (i.e. delete the description) // find a description $description = null; $hasdescription = false; @@ -148,6 +187,12 @@ class Config { $expl = $expl_r; } + // this is a special case for debugging + if($expl[0] == "hold") { + error_log("command is $line"); + return 0; + } + $delete = false; // check for delete on the line if($expl[0] == "delete") { @@ -211,33 +256,40 @@ class Config { case "interface": switch($expl[1]) { case "dev": - $int = $expl[2]; - + $int = $this->resolveInterfaceName($expl[2]); + + if($int != $expl[2]) { + error_log("resolved int as $int from ".$expl[2]); + } + if($int == null) { + error_log("got config for interface ".$expl[2]." but i cannot find it, i will assume its hardware for now"); + $int = $expl[2]; + } if($hasdescription) { - $this->config["interface"][$int]["description"] = $description; + $this->config["interface"]["dev"][$int]["description"] = $description; } switch($expl[3]) { case "address4": - $this->config["interface"]["$int"]["address4"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["address4"] = $expl[4]; break; case "address6": - $this->config["interface"]["$int"]["address6"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["address6"] = $expl[4]; break; case "name": - $this->config["interface"]["$int"]["name"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["name"] = $expl[4]; break; case "status": - $this->config["interface"]["$int"]["status"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["status"] = $expl[4]; break; case "mtu": - $this->config["interface"]["$int"]["mtu"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["mtu"] = $expl[4]; break; case "zone": - $this->config["interface"]["$int"]["zone"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["zone"] = $expl[4]; break; case "speed": - $this->config["interface"]["$int"]["speed"] = $expl[4]; + $this->config["interface"]["dev"]["$int"]["speed"] = $expl[4]; break; case "duplex": $this->config["interface"]["$int"]["duplex"] = $expl[4];