Skip to content

Commit

Permalink
interfaces: convert GIF configuration to MVC/API , closes opnsense#7241
Browse files Browse the repository at this point in the history
cleanup _interfaces_gif_configure() a bit and mark the sections that should be removed in 24.7, the idea is to make sure routing is consistent between all interface types, which means the routing parts should go away. Existing configurations should stay functional, only when adding an aliasip no interface would be connected (which after final cleanup would be the default behavior anyway).

Ditch legacy pages and change menu registrations and acl's. This state should be safe for a minor release, so we can push the behavioral change in 24.7 by only removing the marked sections.
  • Loading branch information
AdSchellevis committed Apr 2, 2024
1 parent 12f6732 commit 0b29680
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 450 deletions.
2 changes: 0 additions & 2 deletions plist
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,6 @@
/usr/local/www/interfaces_assign.php
/usr/local/www/interfaces_bridge.php
/usr/local/www/interfaces_bridge_edit.php
/usr/local/www/interfaces_gif.php
/usr/local/www/interfaces_gif_edit.php
/usr/local/www/interfaces_gre.php
/usr/local/www/interfaces_gre_edit.php
/usr/local/www/interfaces_ppps.php
Expand Down
30 changes: 15 additions & 15 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -575,25 +575,25 @@ function _interfaces_gif_configure($gif)
legacy_interface_create($gif['gifif']);
}

$gateways = new \OPNsense\Routing\Gateways();
$interface = explode('_vip', $gif['if'])[0];
$interface = !empty($gif['if']) ? explode('_vip', $gif['if'])[0] : null;
$family = is_ipaddrv4($gif['remote-addr']) ? 'inet' : 'inet6';
/* XXX: remove routing part in 24.7 */
$remote_gw = null;
if (!empty($interface)) {
$remote_gw = (new \OPNsense\Routing\Gateways())->getInterfaceGateway($interface, $family);
if ($family == 'inet6' && is_linklocal($remote_gw) && strpos($remote_gw, '%') === false) {
$remote_gw .= '%' . get_real_interface($interface, 'inet6');
}
}

if (is_ipaddrv4($gif['remote-addr'])) {
if ($family == 'inet') {
$local_addr = get_interface_ip(!empty($gif['ipaddr']) ? $gif['ipaddr'] : $gif['if']);
$remote_gw = $gateways->getInterfaceGateway($interface, 'inet');
$family = 'inet';
} elseif (is_ipaddrv6($gif['remote-addr'])) {
} else {
if (is_linklocal($gif['remote-addr'])) {
$local_addr = get_interface_ipv6(!empty($gif['ipaddr']) ? $gif['ipaddr'] : $gif['if'], null, 'scoped');
$remote_gw = null;
} else {
$local_addr = get_interface_ipv6(!empty($gif['ipaddr']) ? $gif['ipaddr'] : $gif['if'], null, 'routed');
$remote_gw = $gateways->getInterfaceGateway($interface, 'inet6');
if (is_linklocal($remote_gw) && strpos($remote_gw, '%') === false) {
$remote_gw .= '%' . get_real_interface($interface, 'inet6');
}
}
$family = 'inet6';
}

/* ensured device is there, but do not configure unless system is ready */
Expand Down Expand Up @@ -634,12 +634,12 @@ function _interfaces_gif_configure($gif)
$flags = (empty($gif['link1']) ? "-" : "") . "link1 " . (empty($gif['link2']) ? "-" : "") . "link2";
legacy_interface_flags($gif['gifif'], $flags);

interfaces_bring_up($gif['gifif']);

/* XXX: remove below routing blocks in 24.7 */
if (!empty($remote_gw)) {
system_host_route($remote_addr, $remote_gw);
}

interfaces_bring_up($gif['gifif']);

mwexecf('/usr/local/sbin/ifctl -i %s -%s -rd -a %s', [
$gif['gifif'],
is_ipaddrv4($gif['tunnel-remote-addr']) ? '4' : '6',
Expand Down
9 changes: 2 additions & 7 deletions src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,10 @@
<page-interfaces-gif>
<name>Interfaces: GIF</name>
<patterns>
<pattern>interfaces_gif.php*</pattern>
<pattern>ui/interfaces/gif</pattern>
<pattern>ui/interfaces/gif_settings/*</pattern>
</patterns>
</page-interfaces-gif>
<page-interfaces-gif-edit>
<name>Interfaces: GIF: Edit</name>
<patterns>
<pattern>interfaces_gif_edit.php*</pattern>
</patterns>
</page-interfaces-gif-edit>
<page-interfaces-gre>
<name>Interfaces: GRE</name>
<patterns>
Expand Down
4 changes: 1 addition & 3 deletions src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@
<Bridge url="/interfaces_bridge.php">
<Edit url="/interfaces_bridge_edit.php*" visibility="hidden"/>
</Bridge>
<GIF url="/interfaces_gif.php">
<Edit url="/interfaces_gif_edit.php*" visibility="hidden"/>
</GIF>
<GIF url="/ui/interfaces/gif"/>
<GRE url="/interfaces_gre.php">
<Edit url="/interfaces_gre_edit.php*" visibility="hidden"/>
</GRE>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function __toString()
return (string)$parent->$fieldname;
}
}
return null;
return (string)$this->internalValue;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/opnsense/mvc/app/models/OPNsense/Interfaces/Gif.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<description>GIF interfaces</description>
<items>
<gif type="ArrayField">
<local-addr type=".\LinkAddressField" volatile="true"/>
<local-addr type=".\LinkAddressField" volatile="true">
<Required>Y</Required>
<Default>wan</Default>
</local-addr>
<!--
local address is either an interface, carp address or an ordinary address.
The LinkAddressField type dispatches into the fields below and validates the options available.
Expand Down Expand Up @@ -32,6 +35,7 @@
</tunnel-remote-addr>
<tunnel-remote-net type="IntegerField">
<Required>Y</Required>
<Default>32</Default>
<MinimumValue>1</MinimumValue>
<MaximumValue>128</MaximumValue>
</tunnel-remote-net>
Expand Down
1 change: 1 addition & 0 deletions src/opnsense/scripts/interfaces/reconfigure_gifs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
require_once 'config.inc';
require_once 'interfaces.inc';
require_once 'util.inc';
require_once 'system.inc';

/* gather all relevant gif interfaces*/
$gifs_todo = [];
Expand Down
138 changes: 0 additions & 138 deletions src/www/interfaces_gif.php

This file was deleted.

Loading

0 comments on commit 0b29680

Please sign in to comment.