mirror of
https://github.com/lucaspalomodevelop/opnsense-core.git
synced 2026-03-13 00:07:27 +00:00
mvc: implement getRealInterface() variant related to #6227
This commit is contained in:
parent
88e97fe7e1
commit
b13232391e
2
LICENSE
2
LICENSE
@ -10,7 +10,7 @@ Copyright (c) 2013 Dagorlad
|
||||
Copyright (c) 2006 Daniel S. Haischt
|
||||
Copyright (c) 2012 Darren Embry <dse@webonastick.com>
|
||||
Copyright (c) 2005-2012 David Zeller
|
||||
Copyright (c) 2014-2022 Deciso B.V.
|
||||
Copyright (c) 2014-2023 Deciso B.V.
|
||||
Copyright (c) 2014 Electric Sheep Fencing, LLC
|
||||
Copyright (c) 2010 Erik Fonnesbeck
|
||||
Copyright (c) 2009 Erik Kristensen <erik@erikkristensen.com>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2019-2022 Deciso B.V.
|
||||
* Copyright (C) 2019-2023 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -97,6 +97,65 @@ class Gateways
|
||||
return $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the device name present in the system for the specific configuration
|
||||
* @param string $ifname name of the interface
|
||||
* @param array $ifcfg configuration of interface
|
||||
* @param string $ipproto inet/inet6 type
|
||||
* @return string $realif target device name
|
||||
*/
|
||||
private function getRealInterface($definedIntf, $ifname, $ipproto = 'inet')
|
||||
{
|
||||
if (empty($definedIntf[$ifname])) {
|
||||
/* name already resolved or invalid */
|
||||
return $ifname;
|
||||
}
|
||||
|
||||
$ifcfg = $definedIntf[$ifname];
|
||||
$realif = $ifcfg['if'];
|
||||
|
||||
if (isset($ifcfg['wireless']) && !strstr($realif, '_wlan')) {
|
||||
$realif .= '_wlan0';
|
||||
}
|
||||
|
||||
if ($ipproto == 'inet6') {
|
||||
switch ($ifcfg['ipaddrv6'] ?? 'none') {
|
||||
case '6rd':
|
||||
case '6to4':
|
||||
$realif = "{$ifname}_stf";
|
||||
break;
|
||||
case 'dhcp6':
|
||||
case 'slaac':
|
||||
case 'staticv6':
|
||||
if (isset($cfg['dhcp6usev4iface'])) {
|
||||
break;
|
||||
}
|
||||
switch ($cfg['ipaddr'] ?? 'none') {
|
||||
case 'l2tp':
|
||||
case 'pppoe':
|
||||
case 'pptp':
|
||||
if (!empty($this->configHandle->ppps)) {
|
||||
foreach ($this->configHandle->ppps->children() as $ppp) {
|
||||
if ($realif == $ppp['if']) {
|
||||
$ports = explode(',', $ppp->ports);
|
||||
$realif = $this->getRealInterface($definedIntf, $ports[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $realif;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the type of the interface, for backwards compatibility
|
||||
* @param string $ipproto inet/inet6 type
|
||||
@ -195,11 +254,8 @@ class Gateways
|
||||
// default address family
|
||||
$gw_arr['ipprotocol'] = 'inet';
|
||||
}
|
||||
// Make sure to use the tunnel interface for 6rd and 6to4 setups.
|
||||
$ifname = $gw_arr["interface"];
|
||||
$ifcfg = $definedIntf[$ifname];
|
||||
$gw_arr["if"] = $gw_arr['ipprotocol'] == 'inet6' && in_array($ifcfg['ipaddrv6'] ?? null, ['6to4', '6rd']) ? "{$ifname}_stf" : $ifcfg['if'];
|
||||
$gw_arr["attribute"] = $i++;
|
||||
$gw_arr['if'] = $this->getRealInterface($definedIntf, $gw_arr['interface'], $gw_arr['ipprotocol']);
|
||||
$gw_arr['attribute'] = $i++;
|
||||
if (Util::isIpAddress($gateway->gateway)) {
|
||||
if (empty($gw_arr['monitor_disable']) && empty($gw_arr['monitor'])) {
|
||||
$gw_arr['monitor'] = $gw_arr['gateway'];
|
||||
@ -226,7 +282,7 @@ class Gateways
|
||||
foreach (["inet", "inet6"] as $ipproto) {
|
||||
// filename suffix and interface type as defined in the interface
|
||||
$descr = !empty($ifcfg['descr']) ? $ifcfg['descr'] : $ifname;
|
||||
$realif = $ipproto == 'inet6' && in_array($ifcfg['ipaddrv6'] ?? null, ['6to4', '6rd']) ? "{$ifname}_stf" : $ifcfg['if'];
|
||||
$realif = $this->getRealInterface($definedIntf, $ifname, $ipproto);
|
||||
$ctype = self::convertType($ipproto, $ifcfg);
|
||||
$ctype = $ctype != null ? $ctype : "GW";
|
||||
// default configuration, when not set in gateway_item
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user