backwards compatibility with 4.2
[nodeconfig.git] / PlanetLabConf / sysctl.php
index edd8e86..a17d80c 100755 (executable)
@@ -15,16 +15,31 @@ global $adm;
 $ip_forward = 0;
 
 // Look up the node
-$nodenetworks = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
-if (!empty($nodenetworks)) {
-  $nodes = $adm->GetNodes(array($nodenetworks[0]['node_id']));
+// backwards compatibility with the old 4.2 API
+global $__PLC_API_VERSION;
+if ( ! method_exists ($adm,"GetInterfaces"))
+  $__PLC_API_VERSION = 4.2;
+else
+  $__PLC_API_VERSION = 4.3;
+
+if ($__PLC_API_VERSION==4.2)
+  $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
+else
+  $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
+
+if (!empty($interfaces)) {
+  $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
   if (!empty($nodes)) {
     $node = $nodes[0];
-    $nodenetworks = $adm->GetNodeNetworks($node['nodenetwork_ids']);
-    foreach ($nodenetworks as $nodenetwork) {
+    if ($__PLC_API_VERSION==4.2)
+      $interfaces = $adm->GetInterfaces($node['nodenetwork_ids']);
+    else
+      $interfaces = $adm->GetInterfaces($node['interface_ids']);
+
+    foreach ($interfaces as $interface) {
       // Nodes with proxy socket interfaces need to be able to forward
       // between the fake proxy0 interface and the real interface.
-      if ($nodenetwork['method'] == 'proxy') {
+      if ($interface['method'] == 'proxy') {
        $ip_forward = 1;
        break;
       }