Changeset 870 for trunk/Modules/NetworkConfigRouterOS/Generators/Common.php
- Timestamp:
- Apr 3, 2020, 12:30:49 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/Common.php
r790 r870 33 33 } 34 34 35 function InsertToAddressTree (&$Tree, $Address, $Name, $InterSubnets = false, $ForceMark = false)35 function InsertToAddressTreeIPv4(&$Tree, $Address, $Name, $InterSubnets = false, $ForceMark = false) 36 36 { 37 37 global $Config; … … 42 42 if($Node['Address']->Contain($Address)) 43 43 { 44 InsertToAddressTree ($Tree['Items'][$Index], $Address, $Name, true);44 InsertToAddressTreeIPv4($Tree['Items'][$Index], $Address, $Name, true); 45 45 $Found = true; 46 46 } … … 54 54 $NewAddress->Address = $Address->Address; 55 55 $NewAddress->ChangePrefix($Tree['Address']->Prefix + 1); 56 //echo('InsertToTree('.$NewAddress->AddressToString().'/'.$NewAddress->Prefix.')'."\n");57 56 $Tree['Items'][] = array('Address' => $NewAddress, 'Name' => $Name, 'Items' => array(), 'ForceMark' => false); 58 InsertToAddressTree ($Tree['Items'][count($Tree['Items']) - 1], $Address, $Name, true);57 InsertToAddressTreeIPv4($Tree['Items'][count($Tree['Items']) - 1], $Address, $Name, true); 59 58 } else 60 59 { 61 62 60 $NewNode = array('Address' => $Address, 'Name' => $Name, 'Items' => array(), 'ForceMark' => $ForceMark); 63 61 … … 69 67 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 70 68 71 //echo($Index.','); 69 if($Address->Contain($Node['Address'])) 70 { 71 $NewNode['Items'][] = $Node; 72 unset($Tree['Items'][$Index]); 73 } 74 } 75 if($Found == false) $Tree['Items'][] = $NewNode; 76 } 77 } 78 } 79 80 function InsertToAddressTreeIPv6(&$Tree, $Address, $Name, $InterSubnets = false, $ForceMark = false) 81 { 82 global $Config; 83 84 $Found = false; 85 foreach($Tree['Items'] as $Index => $Node) 86 { 87 if($Node['Address']->Contain($Address)) 88 { 89 InsertToAddressTreeIPv6($Tree['Items'][$Index], $Address, $Name, true); 90 $Found = true; 91 } 92 } 93 if($Found == false) 94 { 95 if($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and 96 ($Address->Prefix > ($Tree['Address']->Prefix + 1))) 97 { 98 $NewAddress = new NetworkAddressIPv6(); 99 $NewAddress->Address = $Address->Address; 100 $NewAddress->ChangePrefix($Tree['Address']->Prefix + 1); 101 $Tree['Items'][] = array('Address' => $NewAddress, 'Name' => $Name, 'Items' => array(), 'ForceMark' => false); 102 InsertToAddressTreeIPv6($Tree['Items'][count($Tree['Items']) - 1], $Address, $Name, true); 103 } else 104 { 105 $NewNode = array('Address' => $Address, 'Name' => $Name, 'Items' => array(), 'ForceMark' => $ForceMark); 106 107 // Should be existed items placed under new node? 108 $Found = false; 109 foreach($Tree['Items'] as $Index => $Node) 110 { 111 if(($Node['Address']->Address == $NewNode['Address']->Address) and 112 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 113 72 114 if($Address->Contain($Node['Address'])) 73 115 { … … 89 131 } 90 132 } 91 92 /*93 function Test()94 {95 $SubnetTree = array('Address' => new NetworkAddressIPv4(), 'Items' => array());96 97 $NewAddress = new NetworkAddressIPv4();98 $NewAddress->AddressFromString('10.145.64.0');99 $NewAddress->Prefix = 24;100 InsertToAddressTree($SubnetTree, $NewAddress);101 $NewAddress = new NetworkAddressIPv4();102 $NewAddress->AddressFromString('10.145.64.0');103 $NewAddress->Prefix = 29;104 InsertToAddressTree($SubnetTree, $NewAddress);105 $NewAddress = new NetworkAddressIPv4();106 $NewAddress->AddressFromString('10.145.65.0');107 $NewAddress->Prefix = 24;108 InsertToAddressTree($SubnetTree, $NewAddress);109 $NewAddress = new NetworkAddressIPv4();110 $NewAddress->AddressFromString('10.145.65.156');111 $NewAddress->Prefix = 32;112 InsertToAddressTree($SubnetTree, $NewAddress);113 $NewAddress = new NetworkAddressIPv4();114 $NewAddress->AddressFromString('10.145.64.0');115 $NewAddress->Prefix = 20;116 InsertToAddressTree($SubnetTree, $NewAddress);117 118 119 ShowSubnetNode($SubnetTree);120 die();121 }122 */
Note:
See TracChangeset
for help on using the changeset viewer.