Commit df0b96eb authored by Franco Fichtner's avatar Franco Fichtner

firewall: merge interface groups into firewall

(cherry picked from commit c2190c1f)
(cherry picked from commit c7f46324)
parent 02a4a391
......@@ -42,9 +42,7 @@
/usr/local/etc/inc/openvpn_wizard.inc
/usr/local/etc/inc/plugins.inc
/usr/local/etc/inc/plugins.inc.d/dnsmasq.inc
/usr/local/etc/inc/plugins.inc.d/if_group.inc
/usr/local/etc/inc/plugins.inc.d/if_ipsec.inc
/usr/local/etc/inc/plugins.inc.d/if_legacy_opt.inc
/usr/local/etc/inc/plugins.inc.d/if_openvpn.inc
/usr/local/etc/inc/plugins.inc.d/ipfw.inc
/usr/local/etc/inc/plugins.inc.d/netflow.inc
......
<?php
/*
Copyright (C) 2016 Deciso B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
function if_group_interfaces()
{
global $config;
$interfaces = array();
/* add interface groups */
if (isset($config['ifgroups']['ifgroupentry'])) {
foreach($config['ifgroups']['ifgroupentry'] as $ifgen) {
$oc = array("enable" => true);
$oc['networks'] = array();
$oc['if'] = $ifgen['ifname'];
$oc['descr'] = $ifgen['ifname'];
$oc['virtual'] = true;
$oc['type'] = 'group';
$interfaces[$ifgen['ifname']] = $oc;
}
}
return $interfaces;
}
<?php
/*
Copyright (C) 2016 Deciso B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/**
* options we should probably remove from the system at some point, lets make them plugabble before removal
*/
function if_legacy_opt_firewall($fw)
{
global $config, $GatewaysList;
$defaults = array();
$defaults['pass'] = array("type" => "pass", "log" => !isset($config['syslog']['nologdefaultpass']));
/*
* pass traffic between statically routed subnets and the subnet on the
* interface in question to avoid problems with complicated routing
* topologies
*/
if (isset($config['filter']['bypassstaticroutes']) && isset($config['staticroutes']['route']) && count($config['staticroutes']['route'])) {
$FilterIflist = filter_generate_optcfg_array();
filter_generate_gateways(); // loads global $GatewaysList
foreach (get_staticroutes() as $route) {
$friendly = $GatewaysList[$route['gateway']]['friendlyiface'];
if (is_array($FilterIflist[$friendly])) {
$oc = $FilterIflist[$friendly];
$routeent = explode("/", $route['network']);
if (is_ipaddrv4($routeent[0]) && is_ipaddrv4($oc['ip'])) {
$sa = $oc['sa'];
$sn = $oc['sn'];
} elseif (is_ipaddrv6($routeent[0]) && is_ipaddrv6($oc['ipv6'])) {
$sa = $oc['sav6'];
$sn = $oc['snv6'];
} else {
continue;
}
$networks = array();
$networks[] = array('from' => "{$sa}/{$sn}", 'to' => $route['network']);
$networks[] = array('to' => "{$sa}/{$sn}", 'from' => $route['network']);
foreach ($networks as $network) {
$fw->registerFilterRule(10,
array('interface' => $friendly, 'statetype' => 'sloppy',
'protocol' => 'tcp','flags' => 'any', 'from' => $network['from'],
'to' => $network['to'], 'quick' => false,
'label' => "pass traffic between statically routed subnets"),
$defaults['pass']
);
$fw->registerFilterRule(10,
array('interface' => $friendly, 'statetype' => 'sloppy',
'from' => $network['from'],'to' => $network['to'], 'quick' => false,
'label' => "pass traffic between statically routed subnets"),
$defaults['pass']
);
}
}
}
}
}
<?php
/*
Copyright (C) 2016 Deciso B.V.
Copyright (C) 2016 Franco Fichtner <franco@opnsense.org>
All rights reserved.
......@@ -47,3 +48,82 @@ function pf_services()
return $services;
}
function pf_interfaces()
{
global $config;
$interfaces = array();
/* add interface groups */
if (isset($config['ifgroups']['ifgroupentry'])) {
foreach($config['ifgroups']['ifgroupentry'] as $ifgen) {
$oc = array("enable" => true);
$oc['networks'] = array();
$oc['if'] = $ifgen['ifname'];
$oc['descr'] = $ifgen['ifname'];
$oc['virtual'] = true;
$oc['type'] = 'group';
$interfaces[$ifgen['ifname']] = $oc;
}
}
return $interfaces;
}
/**
* options we should probably remove from the system at some point, lets make them plugabble before removal
*/
function pf_firewall($fw)
{
global $config, $GatewaysList;
$defaults = array();
$defaults['pass'] = array("type" => "pass", "log" => !isset($config['syslog']['nologdefaultpass']));
/*
* pass traffic between statically routed subnets and the subnet on the
* interface in question to avoid problems with complicated routing
* topologies
*/
if (isset($config['filter']['bypassstaticroutes']) && isset($config['staticroutes']['route']) && count($config['staticroutes']['route'])) {
$FilterIflist = filter_generate_optcfg_array();
filter_generate_gateways(); // loads global $GatewaysList
foreach (get_staticroutes() as $route) {
$friendly = $GatewaysList[$route['gateway']]['friendlyiface'];
if (is_array($FilterIflist[$friendly])) {
$oc = $FilterIflist[$friendly];
$routeent = explode("/", $route['network']);
if (is_ipaddrv4($routeent[0]) && is_ipaddrv4($oc['ip'])) {
$sa = $oc['sa'];
$sn = $oc['sn'];
} elseif (is_ipaddrv6($routeent[0]) && is_ipaddrv6($oc['ipv6'])) {
$sa = $oc['sav6'];
$sn = $oc['snv6'];
} else {
continue;
}
$networks = array();
$networks[] = array('from' => "{$sa}/{$sn}", 'to' => $route['network']);
$networks[] = array('to' => "{$sa}/{$sn}", 'from' => $route['network']);
foreach ($networks as $network) {
$fw->registerFilterRule(10,
array('interface' => $friendly, 'statetype' => 'sloppy',
'protocol' => 'tcp','flags' => 'any', 'from' => $network['from'],
'to' => $network['to'], 'quick' => false,
'label' => "pass traffic between statically routed subnets"),
$defaults['pass']
);
$fw->registerFilterRule(10,
array('interface' => $friendly, 'statetype' => 'sloppy',
'from' => $network['from'],'to' => $network['to'], 'quick' => false,
'label' => "pass traffic between statically routed subnets"),
$defaults['pass']
);
}
}
}
}
}
......@@ -120,9 +120,6 @@
<GRE url="/interfaces_gre.php">
<Edit url="/interfaces_gre_edit.php*" visibility="hidden"/>
</GRE>
<Group url="/interfaces_groups.php">
<Edit url="/interfaces_groups_edit.php*" visibility="hidden"/>
</Group>
<LAGG url="/interfaces_lagg.php">
<Edit url="/interfaces_lagg_edit.php*" visibility="hidden"/>
</LAGG>
......@@ -166,7 +163,10 @@
<Edit url="/firewall_nat_npt_edit.php*" visibility="hidden"/>
</NPT>
</NAT>
<VIP order="50" VisibleName="Virtual IPs" cssClass="fa fa-clone fa-fw">
<Groups order="50" url="/interfaces_groups.php" cssClass="fa fa-sitemap fa-fw">
<Edit url="/interfaces_groups_edit.php*" visibility="hidden"/>
</Groups>
<VIP order="60" VisibleName="Virtual IPs" cssClass="fa fa-clone fa-fw">
<Settings url="/firewall_virtual_ip.php">
<Edit url="/firewall_virtual_ip_edit.php*" visibility="hidden"/>
</Settings>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment