Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
a9c0cd37
Commit
a9c0cd37
authored
Jun 18, 2016
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
interfaces: function belongs here
parent
91f984a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
72 deletions
+72
-72
interfaces.inc
src/etc/inc/interfaces.inc
+72
-0
pfsense-utils.inc
src/etc/inc/pfsense-utils.inc
+0
-72
No files found.
src/etc/inc/interfaces.inc
View file @
a9c0cd37
...
@@ -5325,3 +5325,75 @@ function load_mac_manufacturer_table() {
...
@@ -5325,3 +5325,75 @@ function load_mac_manufacturer_table() {
return -1;
return -1;
}
}
}
}
/****f* legacy/is_ipaddr_configured
* NAME
* is_ipaddr_configured
* INPUTS
* IP Address to check.
* RESULT
* returns true if the IP Address is
* configured and present on this device.
*/
function is_ipaddr_configured(
$ipaddr
,
$ignore_if
= "",
$check_localip
= false,
$check_subnets
= false) {
global
$config
;
$isipv6
= is_ipaddrv6(
$ipaddr
);
if (
$check_subnets
) {
$iflist
= get_configured_interface_list();
foreach (
$iflist
as
$if
=>
$ifname
) {
if (
$ignore_if
==
$if
) {
continue;
}
if (
$isipv6
=== true) {
$bitmask
= get_interface_subnetv6(
$if
);
$subnet
= gen_subnetv6(get_interface_ipv6(
$if
),
$bitmask
);
} else {
$bitmask
= get_interface_subnet(
$if
);
$subnet
= gen_subnet(get_interface_ip(
$if
),
$bitmask
);
}
if (ip_in_subnet(
$ipaddr
,
$subnet
. '/' .
$bitmask
)) {
return true;
}
}
} else {
if (
$isipv6
=== true) {
$interface_list_ips
= get_configured_ipv6_addresses();
} else {
$interface_list_ips
= get_configured_ip_addresses();
}
foreach(
$interface_list_ips
as
$if
=>
$ilips
) {
/* Also ignore CARP interfaces, it'll be checked below */
if (
$ignore_if
==
$if
|| strstr(
$ignore_if
, "
_vip
")) {
continue;
}
if (strcasecmp(
$ipaddr
,
$ilips
) == 0) {
return true;
}
}
}
$interface_list_vips
= get_configured_vips_list(true);
foreach (
$interface_list_vips
as
$id
=>
$vip
) {
if (
$ignore_if
==
$vip['if']
) {
continue;
}
if (strcasecmp(
$ipaddr
,
$vip['ipaddr']
) == 0) {
return true;
}
}
if (
$check_localip
) {
if (is_array(
$config['pptpd']
) && !empty(
$config['pptpd']['localip']
) && (strcasecmp(
$ipaddr
,
$config['pptpd']['localip']
) == 0)) {
return true;
}
if (!is_array(
$config['l2tp']
) && !empty(
$config['l2tp']['localip']
) && (strcasecmp(
$ipaddr
,
$config['l2tp']['localip']
) == 0)) {
return true;
}
}
return false;
}
src/etc/inc/pfsense-utils.inc
View file @
a9c0cd37
...
@@ -374,78 +374,6 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
...
@@ -374,78 +374,6 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
return
(
$xml_array
);
return
(
$xml_array
);
}
}
/****f* legacy/is_ipaddr_configured
* NAME
* is_ipaddr_configured
* INPUTS
* IP Address to check.
* RESULT
* returns true if the IP Address is
* configured and present on this device.
*/
function
is_ipaddr_configured
(
$ipaddr
,
$ignore_if
=
""
,
$check_localip
=
false
,
$check_subnets
=
false
)
{
global
$config
;
$isipv6
=
is_ipaddrv6
(
$ipaddr
);
if
(
$check_subnets
)
{
$iflist
=
get_configured_interface_list
();
foreach
(
$iflist
as
$if
=>
$ifname
)
{
if
(
$ignore_if
==
$if
)
{
continue
;
}
if
(
$isipv6
===
true
)
{
$bitmask
=
get_interface_subnetv6
(
$if
);
$subnet
=
gen_subnetv6
(
get_interface_ipv6
(
$if
),
$bitmask
);
}
else
{
$bitmask
=
get_interface_subnet
(
$if
);
$subnet
=
gen_subnet
(
get_interface_ip
(
$if
),
$bitmask
);
}
if
(
ip_in_subnet
(
$ipaddr
,
$subnet
.
'/'
.
$bitmask
))
{
return
true
;
}
}
}
else
{
if
(
$isipv6
===
true
)
{
$interface_list_ips
=
get_configured_ipv6_addresses
();
}
else
{
$interface_list_ips
=
get_configured_ip_addresses
();
}
foreach
(
$interface_list_ips
as
$if
=>
$ilips
)
{
/* Also ignore CARP interfaces, it'll be checked below */
if
(
$ignore_if
==
$if
||
strstr
(
$ignore_if
,
"_vip"
))
{
continue
;
}
if
(
strcasecmp
(
$ipaddr
,
$ilips
)
==
0
)
{
return
true
;
}
}
}
$interface_list_vips
=
get_configured_vips_list
(
true
);
foreach
(
$interface_list_vips
as
$id
=>
$vip
)
{
if
(
$ignore_if
==
$vip
[
'if'
])
{
continue
;
}
if
(
strcasecmp
(
$ipaddr
,
$vip
[
'ipaddr'
])
==
0
)
{
return
true
;
}
}
if
(
$check_localip
)
{
if
(
is_array
(
$config
[
'pptpd'
])
&&
!
empty
(
$config
[
'pptpd'
][
'localip'
])
&&
(
strcasecmp
(
$ipaddr
,
$config
[
'pptpd'
][
'localip'
])
==
0
))
{
return
true
;
}
if
(
!
is_array
(
$config
[
'l2tp'
])
&&
!
empty
(
$config
[
'l2tp'
][
'localip'
])
&&
(
strcasecmp
(
$ipaddr
,
$config
[
'l2tp'
][
'localip'
])
==
0
))
{
return
true
;
}
}
return
false
;
}
/* Returns the calculated bit length of the prefix delegation from the WAN interface */
/* Returns the calculated bit length of the prefix delegation from the WAN interface */
/* DHCP-PD is variable, calculate from the prefix-len on the WAN interface */
/* DHCP-PD is variable, calculate from the prefix-len on the WAN interface */
/* 6rd is variable, calculate from 64 - (v6 prefixlen - (32 - v4 prefixlen)) */
/* 6rd is variable, calculate from 64 - (v6 prefixlen - (32 - v4 prefixlen)) */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment