Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > dca483b59ba61f3fa092de932ddd570e > files > 221

nuface-2.0.14-2mdv2009.1.i586.rpm

<?php
# Copyright(C) 2004-2007 INL
# Written by Eric Leblond <regit@inl.fr>
#            Vincent Deffontaines <gryzor@inl.fr>
#            Jean Gillaux <jean@inl.fr>
#            Damien Boucard <damien.boucard AT inl.fr>
#
# $Id: bichain.php 17927 2009-02-16 13:16:09Z haypo $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
#  This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

function build_bichains($used_desc)
{
    global $nupyf_same_iface;

    // If desc lives with 3 networks defined,
    // we need to create 6 FWD bichains + 3 +3 (in/out) bichains
    $network = Array();
    foreach ($used_desc->networks->elts as $desc)
    {
        $network[$desc->datas['id']] = $desc->datas['name'];
    }

    $same_iface = $nupyf_same_iface;
    if (count($network) == 1) {
        $same_iface = true;
    }

    $bichains = Array();
    foreach ($network as $net1_id=>$net1_name)
    {
        foreach ($network as $net2_id=>$net2_name)
        {
            if (!$same_iface and $net1_id == $net2_id)
                continue;
            $bichains[] = Array (
                    'from' => $net1_id,
                    'to' => $net2_id,
                    'label' => $net1_name.'-'.$net2_name,
                    'max' => 0);
        }
    }
    return $bichains;
}

/**
 * Arguments: the bichain structure, and the concerned ACL
 * Return: 1 if acl is concerned, 0 otherwise
 */
function bichain_touches_acl($bichain,$acl)
{
    $descsort = $acl->get_descsort();
    if (!$descsort)
        return 0;
    foreach ($descsort->elts as $id=>$tab)
    {
        if (($tab->from == $bichain['from']) and ($tab->to == $bichain['to']))
            return 1;
        // deal with local rules
        if ($tab->from == 0 - $tab->to)
        {
            if (($tab->from == $bichain['from']) and
                    ($tab->to == $bichain['to'])){
                print $tab->from . " == ".$bichain['from']. " or ";
                print $tab->to . " == ".$bichain['to']."\n";

                return 1;
            }
        }
    }
    return 0;
}

function populate_bichains_max($bichains, $acls)
{
    $used_desc = getSession('used_desc', false);
    if (!isset($used_desc) or $used_desc == -1 or !is_array($acls->elts))
    {
        return $bichains;
    }
    foreach ($acls->elts as $id=>$acl)
    {
        if (isset($acl->descsorts->elts[$used_desc]) and (is_array($acl->descsorts->elts[$used_desc]->elts)))
        {
            foreach ($acl->descsorts->elts[$used_desc]->elts as $idorder=>$tab)
            {
                foreach ($bichains as $idbichain=>$bichain)
                {
                    if (($bichain['from']!= $tab->from) or
                            ($bichain['to']  != $tab->to))
                        continue;
                    if ($tab->order > $bichain['max'])
                    {
                        $bichain['max'] = $tab->order;
                        $bichains[$idbichain]=$bichain;
                    }
                }
            }
        }
    }
    return $bichains;
}

# in bichains, get the one which label is name
function get_bichain_by_name($bichains, $name){
    if (is_array($bichains))
    {
      foreach($bichains as $bichain){
          if ($bichain['label'] == $name){
              return $bichain;
          }
      }
    }
    return null;
}

?>