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
3ca65169
Commit
3ca65169
authored
Feb 25, 2016
by
Ad Schellevis
Committed by
Franco Fichtner
Mar 09, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) spaces and curly braces in gwlb.inc
(cherry picked from commit
880980a7
)
parent
af021d13
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
997 additions
and
928 deletions
+997
-928
gwlb.inc
src/etc/inc/gwlb.inc
+997
-928
No files found.
src/etc/inc/gwlb.inc
View file @
3ca65169
...
...
@@ -260,36 +260,51 @@ EOD;
## How often the probe should be sent
if
(
!
empty
(
$gateway
[
'interval'
])
&&
is_numeric
(
$gateway
[
'interval'
]))
{
$interval
=
intval
(
$gateway
[
'interval'
]);
# Restrict to Integer
if
(
$interval
<
1
)
$interval
=
1
;
# Minimum
if
(
$interval
!=
$apinger_default
[
'interval'
])
# If not default value
$apingercfg
.=
" interval "
.
$interval
.
"s
\n
"
;
if
(
$interval
<
1
)
{
$interval
=
1
;
# Minimum
}
if
(
$interval
!=
$apinger_default
[
'interval'
])
{
$apingercfg
.=
" interval "
.
$interval
.
"s
\n
"
;
# If not default value
}
}
## How many replies should be used to compute average delay
## for controlling "delay" alarms
if
(
!
empty
(
$gateway
[
'avg_delay_samples'
])
&&
is_numeric
(
$gateway
[
'avg_delay_samples'
]))
{
$avg_delay_samples
=
intval
(
$gateway
[
'avg_delay_samples'
]);
# Restrict to Integer
if
(
$avg_delay_samples
<
1
)
$avg_delay_samples
=
1
;
# Minimum
if
(
$avg_delay_samples
!=
$apinger_default
[
'avg_delay_samples'
])
# If not default value
if
(
$avg_delay_samples
<
1
)
{
$avg_delay_samples
=
1
;
# Minimum
}
if
(
$avg_delay_samples
!=
$apinger_default
[
'avg_delay_samples'
])
{
# If not default value
$apingercfg
.=
" avg_delay_samples "
.
$avg_delay_samples
.
"
\n
"
;
}
}
## How many probes should be used to compute average loss
if
(
!
empty
(
$gateway
[
'avg_loss_samples'
])
&&
is_numeric
(
$gateway
[
'avg_loss_samples'
]))
{
$avg_loss_samples
=
intval
(
$gateway
[
'avg_loss_samples'
]);
# Restrict to Integer
if
(
$avg_loss_samples
<
1
)
$avg_loss_samples
=
1
;
# Minimum
if
(
$avg_loss_samples
!=
$apinger_default
[
'avg_loss_samples'
])
# If not default value
if
(
$avg_loss_samples
<
1
)
{
$avg_loss_samples
=
1
;
# Minimum
}
if
(
$avg_loss_samples
!=
$apinger_default
[
'avg_loss_samples'
])
{
# If not default value
$apingercfg
.=
" avg_loss_samples "
.
$avg_loss_samples
.
"
\n
"
;
}
}
## The delay (in samples) after which loss is computed
## without this delays larger than interval would be treated as loss
if
(
!
empty
(
$gateway
[
'avg_loss_delay_samples'
])
&&
is_numeric
(
$gateway
[
'avg_loss_delay_samples'
]))
{
$avg_loss_delay_samples
=
intval
(
$gateway
[
'avg_loss_delay_samples'
]);
# Restrict to Integer
if
(
$avg_loss_delay_samples
<
1
)
$avg_loss_delay_samples
=
1
;
# Minimum
if
(
$avg_loss_delay_samples
!=
$apinger_default
[
'avg_loss_delay_samples'
])
# If not default value
if
(
$avg_loss_delay_samples
<
1
)
{
$avg_loss_delay_samples
=
1
;
# Minimum
}
if
(
$avg_loss_delay_samples
!=
$apinger_default
[
'avg_loss_delay_samples'
])
{
# If not default value
$apingercfg
.=
" avg_loss_delay_samples "
.
$avg_loss_delay_samples
.
"
\n
"
;
}
}
$alarms
=
""
;
$alarmscfg
=
""
;
...
...
@@ -302,8 +317,9 @@ EOD;
$alarms
.=
"
\"
{
$name
}
loss
\"
"
;
$override
=
true
;
}
else
{
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$alarms
.=
","
;
}
$alarms
.=
"
\"
loss
\"
"
;
$override
=
true
;
}
...
...
@@ -312,13 +328,15 @@ EOD;
$alarmscfg
.=
"
\t
delay_low
{
$gateway
[
'latencylow'
]
}
ms
\n
"
;
$alarmscfg
.=
"
\t
delay_high
{
$gateway
[
'latencyhigh'
]
}
ms
\n
"
;
$alarmscfg
.=
"}
\n
"
;
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$alarms
.=
","
;
}
$alarms
.=
"
\"
{
$name
}
delay
\"
"
;
$override
=
true
;
}
else
{
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$alarms
.=
","
;
}
$alarms
.=
"
\"
delay
\"
"
;
$override
=
true
;
}
...
...
@@ -326,21 +344,25 @@ EOD;
$alarmscfg
.=
"alarm down
\"
{
$name
}
down
\"
{\n"
;
$alarmscfg
.=
"
\t
time
{
$gateway
[
'down'
]
}
s
\n
"
;
$alarmscfg
.=
"}
\n
"
;
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$alarms
.=
","
;
}
$alarms
.=
"
\"
{
$name
}
down
\"
"
;
$override
=
true
;
}
else
{
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$alarms
.=
","
;
}
$alarms
.=
"
\"
down
\"
"
;
$override
=
true
;
}
if
(
$override
==
true
)
if
(
$override
==
true
)
{
$apingercfg
.=
"
\t
alarms override
{
$alarms
}
;
\n
"
;
}
if
(
isset
(
$gateway
[
'force_down'
]))
if
(
isset
(
$gateway
[
'force_down'
]))
{
$apingercfg
.=
"
\t
force_down on
\n
"
;
}
$apingercfg
.=
" rrd file
\"
/var/db/rrd/
{
$gateway
[
'name'
]
}
-quality.rrd
\"\n
"
;
$apingercfg
.=
"}
\n
"
;
...
...
@@ -417,25 +439,28 @@ function return_gateways_status($byname = false)
* or are down, which could cause gateway groups to fail */
$gateways_arr
=
return_gateways_array
();
foreach
(
$gateways_arr
as
$gwitem
)
{
if
(
!
isset
(
$gwitem
[
'monitor_disable'
]))
if
(
!
isset
(
$gwitem
[
'monitor_disable'
]))
{
continue
;
if
(
!
isset
(
$gwitem
[
'monitorip'
])
||
!
is_ipaddr
(
$gwitem
[
'monitorip'
]))
{
}
if
(
!
isset
(
$gwitem
[
'monitorip'
])
||
!
is_ipaddr
(
$gwitem
[
'monitorip'
]))
{
$realif
=
$gwitem
[
'interface'
];
$tgtip
=
get_interface_gateway
(
$realif
);
if
(
!
is_ipaddr
(
$tgtip
))
if
(
!
is_ipaddr
(
$tgtip
))
{
$tgtip
=
"none"
;
}
$srcip
=
find_interface_ip
(
$realif
);
}
else
{
$tgtip
=
$gwitem
[
'monitorip'
];
$srcip
=
find_interface_ip
(
$realif
);
}
if
(
$byname
==
true
)
if
(
$byname
==
true
)
{
$target
=
$gwitem
[
'name'
];
else
}
else
{
$target
=
$tgtip
;
}
/* failsafe for down interfaces */
if
(
$target
==
"none"
)
{
if
(
$target
==
"none"
)
{
$target
=
$gwitem
[
'name'
];
$status
[
$target
][
'name'
]
=
$gwitem
[
'name'
];
$status
[
$target
][
'lastcheck'
]
=
date
(
'r'
);
...
...
@@ -477,16 +502,18 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
$i
++
;
if
(
empty
(
$config
[
'interfaces'
][
$gateway
[
'interface'
]]))
{
if
(
$inactive
===
false
)
if
(
$inactive
===
false
)
{
continue
;
else
}
else
{
$gateway
[
'inactive'
]
=
true
;
}
}
$wancfg
=
$config
[
'interfaces'
][
$gateway
[
'interface'
]];
/* skip disabled interfaces */
if
(
$disabled
===
false
&&
(
!
isset
(
$wancfg
[
'enable'
])
||
isset
(
$gateway
[
'disabled'
])))
if
(
$disabled
===
false
&&
(
!
isset
(
$wancfg
[
'enable'
])
||
isset
(
$gateway
[
'disabled'
])))
{
continue
;
}
/* if the gateway is dynamic and we can find the IPv4, Great! */
if
(
empty
(
$gateway
[
'gateway'
])
||
$gateway
[
'gateway'
]
==
"dynamic"
)
{
...
...
@@ -494,28 +521,29 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
/* we know which interfaces is dynamic, this should be made a function */
$gateway
[
'gateway'
]
=
get_interface_gateway
(
$gateway
[
'interface'
]);
/* no IP address found, set to dynamic */
if
(
!
is_ipaddrv4
(
$gateway
[
'gateway'
]))
if
(
!
is_ipaddrv4
(
$gateway
[
'gateway'
]))
{
$gateway
[
'gateway'
]
=
"dynamic"
;
$gateway
[
'dynamic'
]
=
true
;
}
$gateway
[
'dynamic'
]
=
true
;
}
elseif
(
$gateway
[
'ipprotocol'
]
==
"inet6"
)
{
/* if the gateway is dynamic and we can find the IPv6, Great! */
else
if
(
$gateway
[
'ipprotocol'
]
==
"inet6"
)
{
/* we know which interfaces is dynamic, this should be made a function, and for v6 too */
$gateway
[
'gateway'
]
=
get_interface_gateway_v6
(
$gateway
[
'interface'
]);
/* no IPv6 address found, set to dynamic */
if
(
!
is_ipaddrv6
(
$gateway
[
'gateway'
]))
if
(
!
is_ipaddrv6
(
$gateway
[
'gateway'
]))
{
$gateway
[
'gateway'
]
=
"dynamic"
;
}
$gateway
[
'dynamic'
]
=
true
;
}
}
else
{
/* getting this detection right is hard at this point because we still don't
* store the address family in the gateway item */
if
(
is_ipaddrv4
(
$gateway
[
'gateway'
]))
if
(
is_ipaddrv4
(
$gateway
[
'gateway'
]))
{
$gateway
[
'ipprotocol'
]
=
"inet"
;
else
if
(
is_ipaddrv6
(
$gateway
[
'gateway'
]))
}
elseif
(
is_ipaddrv6
(
$gateway
[
'gateway'
]))
{
$gateway
[
'ipprotocol'
]
=
"inet6"
;
}
}
if
(
isset
(
$gateway
[
'monitor_disable'
]))
{
$gateway
[
'monitor_disable'
]
=
true
;
...
...
@@ -553,28 +581,34 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
unset
(
$gateway
);
/* Loop through all interfaces with a gateway and add it to a array */
if
(
$disabled
==
false
)
if
(
$disabled
==
false
)
{
$iflist
=
get_configured_interface_with_descr
();
else
}
else
{
$iflist
=
get_configured_interface_with_descr
(
false
,
true
);
}
/* Process/add dynamic v4 gateways. */
foreach
(
$iflist
as
$ifname
=>
$friendly
)
{
if
(
!
interface_has_gateway
(
$ifname
))
if
(
!
interface_has_gateway
(
$ifname
))
{
continue
;
}
if
(
empty
(
$config
[
'interfaces'
][
$ifname
]))
if
(
empty
(
$config
[
'interfaces'
][
$ifname
]))
{
continue
;
}
$ifcfg
=
&
$config
[
'interfaces'
][
$ifname
];
if
(
!
isset
(
$ifcfg
[
'enable'
]))
if
(
!
isset
(
$ifcfg
[
'enable'
]))
{
continue
;
}
if
(
!
empty
(
$ifcfg
[
'ipaddr'
])
&&
is_ipaddrv4
(
$ifcfg
[
'ipaddr'
]))
if
(
!
empty
(
$ifcfg
[
'ipaddr'
])
&&
is_ipaddrv4
(
$ifcfg
[
'ipaddr'
]))
{
continue
;
}
if
(
isset
(
$interfaces_v4
[
$ifname
]))
if
(
isset
(
$interfaces_v4
[
$ifname
]))
{
continue
;
}
$ctype
=
""
;
switch
(
$ifcfg
[
'ipaddr'
])
{
...
...
@@ -587,8 +621,9 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
default
:
if
(
substr
(
$ifcfg
[
'if'
],
0
,
4
)
==
"ovpn"
)
{
// if current iface is an ovpn server endpoint then skip it
if
(
substr
(
$ifcfg
[
'if'
],
4
,
1
)
==
's'
)
if
(
substr
(
$ifcfg
[
'if'
],
4
,
1
)
==
's'
)
{
continue
2
;
}
$ctype
=
"VPNv4"
;
}
...
...
@@ -611,18 +646,21 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
$found_defaultv4
=
1
;
}
/* Loopback dummy for dynamic interfaces without a IP */
if
(
!
is_ipaddrv4
(
$gateway
[
'gateway'
])
&&
$gateway
[
'dynamic'
]
==
true
)
if
(
!
is_ipaddrv4
(
$gateway
[
'gateway'
])
&&
$gateway
[
'dynamic'
]
==
true
)
{
$gateway
[
'gateway'
]
=
"dynamic"
;
}
/* automatically skip known static and dynamic gateways we have a array entry for */
foreach
(
$gateways_arr
as
$gateway_item
)
{
if
(((
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$friendly
==
$gateway_item
[
'name'
])
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
||
(
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$gateway_item
[
'dynamic'
]
==
true
)
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
(
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$gateway_item
[
'dynamic'
]
==
true
)
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
{
continue
2
;
}
}
if
(
is_ipaddrv4
(
$gateway
[
'gateway'
]))
if
(
is_ipaddrv4
(
$gateway
[
'gateway'
]))
{
$gateway
[
'monitor'
]
=
$gateway
[
'gateway'
];
}
$gateway
[
'descr'
]
=
"Interface
{
$friendly
}{
$ctype
}
Gateway"
;
$gateway
[
'monitor_disable'
]
=
true
;
...
...
@@ -633,24 +671,30 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
/* Process/add dynamic v6 gateways. */
foreach
(
$iflist
as
$ifname
=>
$friendly
)
{
/* If the user has disabled IPv6, they probably don't want any IPv6 gateways. */
if
(
!
isset
(
$config
[
'system'
][
'ipv6allow'
]))
if
(
!
isset
(
$config
[
'system'
][
'ipv6allow'
]))
{
break
;
}
if
(
!
interface_has_gatewayv6
(
$ifname
))
if
(
!
interface_has_gatewayv6
(
$ifname
))
{
continue
;
}
if
(
empty
(
$config
[
'interfaces'
][
$ifname
]))
if
(
empty
(
$config
[
'interfaces'
][
$ifname
]))
{
continue
;
}
$ifcfg
=
&
$config
[
'interfaces'
][
$ifname
];
if
(
!
isset
(
$ifcfg
[
'enable'
]))
if
(
!
isset
(
$ifcfg
[
'enable'
]))
{
continue
;
}
if
(
!
empty
(
$ifcfg
[
'ipaddrv6'
])
&&
is_ipaddrv6
(
$ifcfg
[
'ipaddrv6'
]))
if
(
!
empty
(
$ifcfg
[
'ipaddrv6'
])
&&
is_ipaddrv6
(
$ifcfg
[
'ipaddrv6'
]))
{
continue
;
}
if
(
isset
(
$interfaces_v6
[
$ifname
]))
if
(
isset
(
$interfaces_v6
[
$ifname
]))
{
continue
;
}
$ctype
=
""
;
switch
(
$ifcfg
[
'ipaddrv6'
])
{
...
...
@@ -664,12 +708,14 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
$tunnelif
=
substr
(
$ifcfg
[
'if'
],
0
,
3
);
if
(
substr
(
$ifcfg
[
'if'
],
0
,
4
)
==
"ovpn"
)
{
// if current iface is an ovpn server endpoint then skip it
if
(
substr
(
$ifcfg
[
'if'
],
4
,
1
)
==
's'
)
if
(
substr
(
$ifcfg
[
'if'
],
4
,
1
)
==
's'
)
{
continue
2
;
}
$ctype
=
"VPNv6"
;
}
else
if
(
$tunnelif
==
"gif"
||
$tunnelif
==
"gre"
)
}
elseif
(
$tunnelif
==
"gif"
||
$tunnelif
==
"gre"
)
{
$ctype
=
"TUNNELv6"
;
}
break
;
}
$ctype
=
"_"
.
strtoupper
(
$ctype
);
...
...
@@ -696,18 +742,21 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
}
/* Loopback dummy for dynamic interfaces without a IP */
if
(
!
is_ipaddrv6
(
$gateway
[
'gateway'
])
&&
$gateway
[
'dynamic'
]
==
true
)
if
(
!
is_ipaddrv6
(
$gateway
[
'gateway'
])
&&
$gateway
[
'dynamic'
]
==
true
)
{
$gateway
[
'gateway'
]
=
"dynamic"
;
}
/* automatically skip known static and dynamic gateways we have a array entry for */
foreach
(
$gateways_arr
as
$gateway_item
)
{
if
(((
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$friendly
==
$gateway_item
[
'name'
])
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
||
(
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$gateway_item
[
'dynamic'
]
==
true
)
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
(
$ifname
==
$gateway_item
[
'friendlyiface'
]
&&
$gateway_item
[
'dynamic'
]
==
true
)
&&
(
$gateway
[
'ipprotocol'
]
==
$gateway_item
[
'ipprotocol'
]))
{
continue
2
;
}
}
if
(
is_ipaddrv6
(
$gateway
[
'gateway'
]))
if
(
is_ipaddrv6
(
$gateway
[
'gateway'
]))
{
$gateway
[
'monitor'
]
=
$gateway
[
'gateway'
];
}
$gateway
[
'descr'
]
=
"Interface
{
$friendly
}{
$ctype
}
Gateway"
;
$gateway
[
'monitor_disable'
]
=
true
;
...
...
@@ -736,7 +785,7 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
}
}
if
(
$localhost
===
true
)
{
if
(
$localhost
===
true
)
{
/* attach localhost for Null routes */
$gwlo4
=
array
();
$gwlo4
[
'name'
]
=
"Null4"
;
...
...
@@ -768,27 +817,32 @@ function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr)
if
((
$gwsttng
[
'ipprotocol'
]
==
$ipprotocol
)
&&
isset
(
$gwsttng
[
'defaultgw'
]))
{
$dfltgwfound
=
true
;
$dfltgwname
=
$gwname
;
if
(
!
isset
(
$gwsttng
[
'monitor_disable'
])
&&
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
if
(
!
isset
(
$gwsttng
[
'monitor_disable'
])
&&
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
{
$dfltgwdown
=
true
;
}
}
/* Keep a record of the last up gateway */
/* XXX: Blacklist lan for now since it might cause issues to those who have a gateway set for it */
if
(
empty
(
$upgw
)
&&
(
$gwsttng
[
'ipprotocol'
]
==
$ipprotocol
)
&&
(
isset
(
$gwsttng
[
'monitor_disable'
])
||
!
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
&&
$gwsttng
[
$gwname
][
'friendlyiface'
]
!=
"lan"
)
if
(
empty
(
$upgw
)
&&
(
$gwsttng
[
'ipprotocol'
]
==
$ipprotocol
)
&&
(
isset
(
$gwsttng
[
'monitor_disable'
])
||
!
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
&&
$gwsttng
[
$gwname
][
'friendlyiface'
]
!=
"lan"
)
{
$upgw
=
$gwname
;
if
(
$dfltgwdown
==
true
&&
!
empty
(
$upgw
))
}
if
(
$dfltgwdown
==
true
&&
!
empty
(
$upgw
))
{
break
;
}
}
if
(
$dfltgwfound
==
false
)
{
$gwname
=
convert_friendly_interface_to_friendly_descr
(
"wan"
);
if
(
!
empty
(
$gateways_status
[
$gwname
])
&&
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
if
(
!
empty
(
$gateways_status
[
$gwname
])
&&
stristr
(
$gateways_status
[
$gwname
][
'status'
],
"down"
))
{
$dfltgwdown
=
true
;
}
}
if
(
$dfltgwdown
==
true
&&
!
empty
(
$upgw
))
{
if
(
$gateways_arr
[
$upgw
][
'gateway'
]
==
"dynamic"
)
if
(
$gateways_arr
[
$upgw
][
'gateway'
]
==
"dynamic"
)
{
$gateways_arr
[
$upgw
][
'gateway'
]
=
get_interface_gateway
(
$gateways_arr
[
$upgw
][
'friendlyiface'
]);
}
if
(
is_ipaddr
(
$gateways_arr
[
$upgw
][
'gateway'
]))
{
log_error
(
"Default gateway down setting
{
$upgw
}
as default!"
);
if
(
is_ipaddrv6
(
$gateways_arr
[
$upgw
][
'gateway'
]))
{
if
(
is_ipaddrv6
(
$gateways_arr
[
$upgw
][
'gateway'
]))
{
$inetfamily
=
"-inet6"
;
}
else
{
$inetfamily
=
"-inet"
;
...
...
@@ -798,7 +852,7 @@ function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr)
}
}
else
{
$defaultgw
=
trim
(
exec
(
"/sbin/route -n get -
{
$ipprotocol
}
default | /usr/bin/awk '/gateway:/ {print $2}'"
),
"
\n
"
);
if
(
is_ipaddrv6
(
$gateways_arr
[
$dfltgwname
][
'gateway'
]))
{
if
(
is_ipaddrv6
(
$gateways_arr
[
$dfltgwname
][
'gateway'
]))
{
$inetfamily
=
"-inet6"
;
}
else
{
$inetfamily
=
"-inet"
;
...
...
@@ -838,14 +892,16 @@ function return_gateway_groups_array()
list
(
$gwname
,
$tier
,
$vipname
)
=
explode
(
"|"
,
$item
);
if
(
is_ipaddr
(
$carplist
[
$vipname
]))
{
if
(
!
is_array
(
$gwvip_arr
[
$group
[
'name'
]]))
if
(
!
is_array
(
$gwvip_arr
[
$group
[
'name'
]]))
{
$gwvip_arr
[
$group
[
'name'
]]
=
array
();
}
$gwvip_arr
[
$group
[
'name'
]][
$gwname
]
=
$vipname
;
}
/* Do it here rather than reiterating again the group in case no member is up. */
if
(
!
is_array
(
$backupplan
[
$tier
]))
if
(
!
is_array
(
$backupplan
[
$tier
]))
{
$backupplan
[
$tier
]
=
array
();
}
$backupplan
[
$tier
][]
=
$gwname
;
/* check if the gateway is available before adding it to the array */
...
...
@@ -870,8 +926,9 @@ function return_gateway_groups_array()
notify_via_smtp
(
$msg
);
}
else
{
/* Online add member */
if
(
!
is_array
(
$tiers
[
$tier
]))
if
(
!
is_array
(
$tiers
[
$tier
]))
{
$tiers
[
$tier
]
=
array
();
}
$tiers
[
$tier
][]
=
$gwname
;
}
}
elseif
(
isset
(
$gateways_arr
[
$gwname
][
'monitor_disable'
]))
{
...
...
@@ -901,10 +958,11 @@ function return_gateway_groups_array()
$gateway
=
$gateways_arr
[
$member
];
$int
=
$gateway
[
'interface'
];
$gatewayip
=
""
;
if
(
is_ipaddr
(
$gateway
[
'gateway'
]))
if
(
is_ipaddr
(
$gateway
[
'gateway'
]))
{
$gatewayip
=
$gateway
[
'gateway'
];
else
if
(
!
empty
(
$int
))
}
elseif
(
!
empty
(
$int
))
{
$gatewayip
=
get_interface_gateway
(
$gateway
[
'friendlyiface'
]);
}
if
(
!
empty
(
$int
))
{
$gateway_groups_array
[
$group
[
'name'
]][
'ipprotocol'
]
=
$gateway
[
'ipprotocol'
];
...
...
@@ -913,39 +971,42 @@ function return_gateway_groups_array()
$groupmember
[
'int'
]
=
$int
;
$groupmember
[
'gwip'
]
=
$gatewayip
;
$groupmember
[
'weight'
]
=
isset
(
$gateway
[
'weight'
])
?
$gateway
[
'weight'
]
:
1
;
if
(
is_array
(
$gwvip_arr
[
$group
[
'name'
]])
&&
!
empty
(
$gwvip_arr
[
$group
[
'name'
]][
$member
]))
if
(
is_array
(
$gwvip_arr
[
$group
[
'name'
]])
&&
!
empty
(
$gwvip_arr
[
$group
[
'name'
]][
$member
]))
{
$groupmember
[
'vip'
]
=
$gwvip_arr
[
$group
[
'name'
]][
$member
];
}
$gateway_groups_array
[
$group
[
'name'
]][]
=
$groupmember
;
}
}
}
}
/* we should have the 1st available tier now, exit stage left */
if
(
count
(
$gateway_groups_array
[
$group
[
'name'
]])
>
0
)
if
(
count
(
$gateway_groups_array
[
$group
[
'name'
]])
>
0
)
{
break
;
else
}
else
{
log_error
(
"GATEWAYS: Group
{
$group
[
'name'
]
}
did not have any gateways up on tier
{
$tieridx
}
!"
);
}
}
}
}
return
(
$gateway_groups_array
);
}
function
lookup_gateway_ip_by_name
(
$name
)
{
function
lookup_gateway_ip_by_name
(
$name
)
{
$gateways_arr
=
return_gateways_array
(
true
,
true
);
foreach
(
$gateways_arr
as
$gname
=>
$gw
)
{
if
(
$gw
[
'name'
]
===
$name
||
$gname
===
$name
)
if
(
$gw
[
'name'
]
===
$name
||
$gname
===
$name
)
{
return
$gw
[
'gateway'
];
}
}
return
false
;
}
function
lookup_gateway_interface_by_name
(
$name
)
{
function
lookup_gateway_interface_by_name
(
$name
)
{
$gateways_arr
=
return_gateways_array
(
false
,
true
);
if
(
!
empty
(
$gateways_arr
[
$name
]))
{
$interfacegw
=
$gateways_arr
[
$name
][
'friendlyiface'
];
...
...
@@ -965,7 +1026,7 @@ function get_interface_gateway($interface, &$dynamic = false)
$gwcfg
=
$config
[
'interfaces'
][
$interface
];
if
(
!
empty
(
$gwcfg
[
'gateway'
])
&&
isset
(
$config
[
'gateways'
][
'gateway_item'
]))
{
foreach
(
$config
[
'gateways'
][
'gateway_item'
]
as
$gateway
)
{
if
((
$gateway
[
'name'
]
==
$gwcfg
[
'gateway'
])
&&
(
is_ipaddrv4
(
$gateway
[
'gateway'
])))
{
if
((
$gateway
[
'name'
]
==
$gwcfg
[
'gateway'
])
&&
(
is_ipaddrv4
(
$gateway
[
'gateway'
])))
{
$gw
=
$gateway
[
'gateway'
];
break
;
}
...
...
@@ -997,7 +1058,7 @@ function get_interface_gateway_v6($interface, &$dynamic = false)
$gwcfg
=
$config
[
'interfaces'
][
$interface
];
if
(
!
empty
(
$gwcfg
[
'gatewayv6'
])
&&
isset
(
$config
[
'gateways'
][
'gateway_item'
]))
{
foreach
(
$config
[
'gateways'
][
'gateway_item'
]
as
$gateway
)
{
if
((
$gateway
[
'name'
]
==
$gwcfg
[
'gatewayv6'
])
&&
(
is_ipaddrv6
(
$gateway
[
'gateway'
])))
{
if
((
$gateway
[
'name'
]
==
$gwcfg
[
'gatewayv6'
])
&&
(
is_ipaddrv6
(
$gateway
[
'gateway'
])))
{
$gw
=
$gateway
[
'gateway'
];
break
;
}
...
...
@@ -1011,9 +1072,9 @@ function get_interface_gateway_v6($interface, &$dynamic = false)
$gw
=
trim
(
file_get_contents
(
"/tmp/
{
$realif
}
_routerv6"
),
"
\n
"
);
$dynamic
=
true
;
}
if
(
file_exists
(
"/tmp/
{
$realif
}
_defaultgwv6"
))
if
(
file_exists
(
"/tmp/
{
$realif
}
_defaultgwv6"
))
{
$dynamic
=
"default"
;
}
}
/* return gateway */
return
(
$gw
);
...
...
@@ -1021,34 +1082,43 @@ function get_interface_gateway_v6($interface, &$dynamic = false)
/* Check a IP address against a gateway IP or name
* to verify it's address family */
function
validate_address_family
(
$ipaddr
,
$gwname
)
{
function
validate_address_family
(
$ipaddr
,
$gwname
)
{
$v4ip
=
false
;
$v6ip
=
false
;
$v4gw
=
false
;
$v6gw
=
false
;
if
(
is_ipaddrv4
(
$ipaddr
))
if
(
is_ipaddrv4
(
$ipaddr
))
{
$v4ip
=
true
;
if
(
is_ipaddrv6
(
$ipaddr
))
}
if
(
is_ipaddrv6
(
$ipaddr
))
{
$v6ip
=
true
;
if
(
is_ipaddrv4
(
$gwname
))
}
if
(
is_ipaddrv4
(
$gwname
))
{
$v4gw
=
true
;
if
(
is_ipaddrv6
(
$gwname
))
}
if
(
is_ipaddrv6
(
$gwname
))
{
$v6gw
=
true
;
}
if
(
$v4ip
&&
$v4gw
)
if
(
$v4ip
&&
$v4gw
)
{
return
true
;
if
(
$v6ip
&&
$v6gw
)
}
if
(
$v6ip
&&
$v6gw
)
{
return
true
;
}
/* still no match, carry on, lookup gateways */
if
(
is_ipaddrv4
(
lookup_gateway_ip_by_name
(
$gwname
)))
if
(
is_ipaddrv4
(
lookup_gateway_ip_by_name
(
$gwname
)))
{
$v4gw
=
true
;
if
(
is_ipaddrv6
(
lookup_gateway_ip_by_name
(
$gwname
)))
}
if
(
is_ipaddrv6
(
lookup_gateway_ip_by_name
(
$gwname
)))
{
$v6gw
=
true
;
}
$gw_array
=
return_gateways_array
();
if
(
is_array
(
$gw_array
[
$gwname
]))
{
if
(
is_array
(
$gw_array
[
$gwname
]))
{
switch
(
$gw_array
[
$gwname
][
'ipprotocol'
])
{
case
"inet"
:
$v4gw
=
true
;
...
...
@@ -1059,13 +1129,12 @@ function validate_address_family($ipaddr, $gwname) {
}
}
if
(
$v4ip
&&
$v4gw
)
if
(
$v4ip
&&
$v4gw
)
{
return
true
;
if
(
$v6ip
&&
$v6gw
)
}
if
(
$v6ip
&&
$v6gw
)
{
return
true
;
}
return
false
;
}
?>
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