Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phpipam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
phpipam
Commits
2595bb5a
Unverified
Commit
2595bb5a
authored
Apr 11, 2022
by
Gary Allan
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix: Overlap error for nested subnet when modifying the parent. Fixes #3546
parent
2fe6f9af
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
functions/classes/class.Subnets.php
+47
-35
47 additions, 35 deletions
functions/classes/class.Subnets.php
with
47 additions
and
35 deletions
functions/classes/class.Subnets.php
+
47
−
35
View file @
2595bb5a
...
...
@@ -2111,6 +2111,53 @@ class Subnets extends Common_functions {
return
false
;
}
/**
* Verifies VRF overlapping - globally
*
* @method verify_vrf_overlapping
* @param string $cidr
* @param int $vrfId
* @param int $subnetId (default: 0)
* @param int $masterSubnetId (default: 0)
* @return false|string
*/
public
function
verify_vrf_overlapping
(
$cidr
,
$vrfId
,
$subnetId
=
0
,
$masterSubnetId
=
0
)
{
// fix null vrfid
$vrfId
=
is_numeric
(
$vrfId
)
?
$vrfId
:
0
;
// fix null masterSubnetId
$masterSubnetId
=
is_numeric
(
$masterSubnetId
)
?
$masterSubnetId
:
0
;
// fetch all overlapping subnets in VRF globally
$overlaping
=
$this
->
fetch_overlapping_subnets
(
$cidr
,
'vrfId'
,
$vrfId
);
if
(
empty
(
$overlaping
))
return
false
;
if
(
$subnetId
>
0
)
{
$this
->
reset_subnet_slaves_recursive
();
$this
->
fetch_subnet_slaves_recursive
(
$subnetId
);
$excluded_ids
=
array_merge
(
$this
->
slaves
?:
[],
$this
->
fetch_parents_recursive
(
$subnetId
)
?:
[]);
}
else
{
$excluded_ids
=
$this
->
fetch_parents_recursive
(
$masterSubnetId
)
?:
[];
$excluded_ids
[]
=
$masterSubnetId
;
}
// Remove parents and children
foreach
(
$overlaping
as
$i
=>
$subnet
)
{
if
(
$subnet
->
isFolder
||
(
int
)
$subnet
->
vrfId
!=
$vrfId
||
in_array
(
$subnet
->
id
,
$excluded_ids
))
{
unset
(
$overlaping
[
$i
]);
}
}
// Re-index
$overlaping
=
array_values
(
array_filter
(
$overlaping
));
if
(
empty
(
$overlaping
))
return
false
;
$section
=
$this
->
fetch_object
(
'sections'
,
'id'
,
$overlaping
[
0
]
->
sectionId
);
return
_
(
"Subnet"
)
.
" "
.
$cidr
.
" "
.
_
(
"overlaps with"
)
.
' '
.
$this
->
transform_to_dotted
(
$overlaping
[
0
]
->
subnet
)
.
'/'
.
$overlaping
[
0
]
->
mask
.
" ("
.
$overlaping
[
0
]
->
description
.
") "
.
_
(
"in section"
)
.
" "
.
$section
->
name
;
}
/**
* Verifies overlapping between folders
*
...
...
@@ -2162,41 +2209,6 @@ class Subnets extends Common_functions {
return
false
;
}
/**
* Verifies VRF overlapping - globally
*
* @method verify_vrf_overlapping
* @param string $cidr
* @param int $vrfId
* @param int $subnetId (default: 0)
* @param int $masterSubnetId (default: 0)
* @return false|string
*/
public
function
verify_vrf_overlapping
(
$cidr
,
$vrfId
,
$subnetId
=
0
,
$masterSubnetId
=
0
)
{
# fetch all overlapping subnets in VRF globally
$all_subnets
=
$this
->
fetch_overlapping_subnets
(
$cidr
,
'vrfId'
,
$vrfId
);
# fetch all parents
$allParents
=
$subnetId
!=
0
?
$this
->
fetch_parents_recursive
(
$subnetId
)
:
$this
->
fetch_parents_recursive
(
$masterSubnetId
);
# add self
$allParents
[]
=
$masterSubnetId
;
if
(
$all_subnets
!==
false
&&
is_array
(
$all_subnets
))
{
foreach
(
$all_subnets
as
$existing_subnet
)
{
// ignore folders - precaution and ignore self for edits
if
(
$existing_subnet
->
isFolder
!=
1
&&
$existing_subnet
->
id
!==
$subnetId
&&
!
in_array
(
$existing_subnet
->
id
,
$allParents
))
{
# check overlapping globally if subnet is not nested
if
(
$this
->
verify_overlapping
(
$cidr
,
$this
->
transform_to_dotted
(
$existing_subnet
->
subnet
)
.
'/'
.
$existing_subnet
->
mask
)
!==
false
)
{
$Section
=
new
Sections
(
$this
->
Database
);
$section
=
$Section
->
fetch_section
(
'id'
,
$existing_subnet
->
sectionId
);
return
_
(
"Subnet"
)
.
" "
.
$cidr
.
" "
.
_
(
"overlaps with"
)
.
' '
.
$this
->
transform_to_dotted
(
$existing_subnet
->
subnet
)
.
'/'
.
$existing_subnet
->
mask
.
" ("
.
$existing_subnet
->
description
.
") "
.
_
(
"in section"
)
.
" "
.
$section
->
name
;
}
}
}
}
# default false - does not overlap
return
false
;
}
/**
* Verifies if resized subnet overlaps with any of existing subnets in that section and same or null VRF
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment