Skip to content

Commit 678a209

Browse files
committed
gateways: ipv6 ll where appropriate
Normally, if we have an IPv6 link local monitor we use the link local address which is always available. If not a link local address, try to use a global address. If we don't have one, we can't reach the outside anyway. PR: https://forum.opnsense.org/index.php?topic=6028.0
1 parent 82a4249 commit 678a209

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/etc/inc/gwlb.inc

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,32 +196,17 @@ EOD;
196196
system_host_route($gateway['monitor'], $gateway['gateway'], false, true);
197197
}
198198
} elseif ($gateway['ipprotocol'] == "inet6") { // This is an IPv6 gateway...
199-
if ($gateway['monitor'] == $gateway['gateway']) {
200-
/* link locals really need a different src ip */
201-
if (is_linklocal($gateway['gateway'])) {
202-
$gwifip = find_interface_ipv6_ll($gateway['interface']);
203-
} else {
204-
$gwifip = find_interface_ipv6($gateway['interface']);
205-
}
199+
if (is_linklocal($gateway['monitor'])) {
200+
/* link local monitor needs a link local address for the "src" part */
201+
$gwifip = find_interface_ipv6_ll($gateway['interface']);
206202
} else {
207-
/* 'monitor' has been set, so makes sure it has precedence over
208-
* 'gateway' in defining the source IP. Otherwise if 'gateway'
209-
* is a local link and 'monitor' is global routable then the
210-
* ICMP6 response would not find its way back home...
211-
*/
203+
/* monitor is a routable address, so use a routable address for the "src" part */
212204
$gwifip = find_interface_ipv6($gateway['interface']);
213-
if (is_linklocal($gateway['monitor'])) {
214-
if (!strstr($gateway['monitor'], '%')) {
215-
$gateway['monitor'] .= "%{$gateway['interface']}";
216-
}
217-
} else {
218-
// Monitor is a routable address, so use a routable address for the "src" part
219-
$gwifip = find_interface_ipv6($gateway['interface']);
220-
}
221205
}
222206

223207
if (!is_ipaddrv6($gwifip)) {
224-
continue; //Skip this target
208+
/* skip this target */
209+
continue;
225210
}
226211

227212
/* flush the monitor unconditionally */
@@ -230,7 +215,7 @@ EOD;
230215
system_host_route($gateway['monitor'], $gateway['gateway'], true, false);
231216
}
232217

233-
/* Do not monitor if such was requested */
218+
/* do not monitor if such was requested */
234219
if (isset($gateway['disabled']) || isset($gateway['monitor_disable'])) {
235220
continue;
236221
}
@@ -245,6 +230,16 @@ EOD;
245230
log_error("Adding static route for monitor {$gateway['monitor']} via {$gateway['gateway']}");
246231
system_host_route($gateway['monitor'], $gateway['gateway'], false, true);
247232
}
233+
234+
/*
235+
* 'monitor' has been set, so makes sure it has precedence over
236+
* 'gateway' in defining the source IP. Otherwise if 'gateway'
237+
* is a local link and 'monitor' is global routable then the
238+
* ICMP6 response would not find its way back home...
239+
*/
240+
if (is_linklocal($gateway['monitor']) && !strstr($gateway['monitor'], '%')) {
241+
$gateway['monitor'] .= "%{$gateway['interface']}";
242+
}
248243
} else {
249244
continue;
250245
}

0 commit comments

Comments
 (0)