Commit Graph

86 Commits

Author SHA1 Message Date
Michael Tremer
ce31144c62 firewall: Only check relevant bits for NAT fix rules
In order to use the highest two bits for surciata bypass, we will need
to make sure that whenever we compare any other marks, we do not care
about anything else.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2021-10-13 11:45:48 +00:00
Stefan Schantl
21b37391f9 Firewall: Proper allow to create REDIRECT rules.
This patch now proper allows to create rules for redirecting requests of a
given host, group or network(s) to a specified port or service to the
local IPFire system.

So it implements a very generic and easy to use feature to redirect
(for example all DNS, NTP, or whatever) requests to the a local running
instance and so to force usage of that local hosted service.

* The feature supports specifiying a single port and redirect the requests to another given one.
  ( For example requests to UDP 123 can be redirected to local UDP 1234
  if you run an NTP server on that port.)

* It also supports direct usage of services or even service groups.
  ( So you can create a service group for DNS and redirect them to the
  local recursor, or create a "redirected services" group which easily
  can be managed...)

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2021-08-16 06:18:00 +00:00
Peter Müller
2293e1de0b rules.pl: apply location filter to ppp0 if configured
In order to prevent collateral damage to internal traffic, commit
c69c820025 introduced applying location
block on red0 as a sanity check.

On systems configured to use PPPoE, however, traffic appears on the ppp0
interface instead. This patch checks if a system is configured to use
this connection method, and applies the location filter to this
interface. red0 is used otherwise.

Fixes: #12519

Cc: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2020-11-11 15:53:05 +00:00
Michael Tremer
c69c820025 firewall: Filter only on RED and exclude any private address space
Since libloc is built as a tree we cannot simply exclude any address
space in the middle of it. Therefore we create some firewall rules
which simply avoid checking non-globally routable address space.

Fixes: #12499
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2020-10-14 11:32:05 +01:00
Stefan Schantl
5730a5bcdf firewall/rules.pl: Rework code to use location-functions.pl
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2020-06-12 19:06:01 +02:00
Michael Tremer
0e6eca78b8 firewall: Rename GEOIPBLOCK table to LOCATIONBLOCK
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2020-06-12 16:00:34 +02:00
Stefan Schantl
4852f77e33 Revert "firewall/rules.pl: Add code to collect and export all required country"
This reverts commit ad47d2ae80.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2020-06-10 21:29:04 +02:00
Stefan Schantl
38a8d40142 Revert "firewall/rules.pl: Only try to export locations if needed."
This reverts commit 693b8513df.
2020-06-10 21:28:16 +02:00
Stefan Schantl
8b58dbf32a Merge branch 'switch-to-libloc' into next-switch-to-libloc 2020-05-25 19:58:54 +02:00
Michael Tremer
c22369a916 firewall: Log accepted connections even when NAT is active
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2020-05-09 12:21:16 +00:00
Stefan Schantl
c4b7692ad9 rules.pl: Fix SNAT over VPN.
This commit adds flags which will are applied if SNAT should be used on
the red address or any configured alias.

They prevent doing the SNAT when tranismitting packet through a VPN over the red interface.

Fixes #12162.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Tested-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2020-03-21 16:24:44 +00:00
Stefan Schantl
693b8513df firewall/rules.pl: Only try to export locations if needed.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2019-12-09 18:36:54 +01:00
Stefan Schantl
ad47d2ae80 firewall/rules.pl: Add code to collect and export all required country
codes.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2019-12-09 11:08:23 +01:00
Stefan Schantl
f5ad4246de firewall/rules.pl: Make geoipsettings hash and locations array
script-wide available.

This allows to re-use them.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2019-12-09 11:04:30 +01:00
peter.mueller@ipfire.org
a85a7a60fc firewall: raise log rate limit for user generated rules, too
Having raised the overall log rate limit to 10 packet per second
in Core Update 136, this did not affected rules generated by the
user. In order to stay consistent, this patch also raises log rate
limit for these.

In order to avoid side effects on firewalls with slow disks, it
was probably better touch these categories separately, so testing
users won't be DoSsed instantly. :-)

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2019-10-08 18:30:31 +00:00
Arne Fitzenreiter
5653e55107 perl-scripts: suppress smartmatch experimental warning
smartmatch was introduced with perl 5.10 and was marked
as experimental in 5.14

Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2019-08-16 12:21:26 +02:00
Michael Tremer
249839b0ca firewall: Fix source/destination interface settings
When a forwarding rule is being created, we sometimes create
INPUT/OUTPUT rules, too. Those were slightly invalid because
the source and destination interfaces where passed, too.

This could render some rules in certain circumstances useless.

This patch fixes this and only adds -i for INPUT and -o for
OUTPUT rules.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2019-04-30 10:56:05 +01:00
Michael Tremer
ae93dd3deb firewall: Add more rules to input/output when adding rules to forward
The special_input/output_targets array assumed that firewall access
will always be denied. However, rules also need to be created when
access is granted. Therefore the ACCEPT target needs to be included
in this list and rules must be created in INPUTFW/OUTGOINGFW too
when ACCEPT rules are created in FORWARDFW.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2019-04-30 10:45:34 +01:00
Michael Tremer
1f91201011 firewall: Suppress warning about uninitialized array in GeoIP code
Fixes #11597

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2018-01-22 13:20:04 +00:00
Alexander Marx
306098a498 BUG10994: SNAT rules are missing the outgoing interface
When creating SNAT rules, the outgoing interface is not set. As a side
effect, traffic that should be send unnatted to a vpn tunnel can be
natted which is a BUG.
With this patch the SNAT rules are getting a outgoing interface
according to the configuration. When selecting the RED Target network,
all SNAT rules will be configured with "-o red0". Otherwise if "all" is
selected, there is no interface in the rule, which matches all networks.

Signed-off-by: Alexander Marx <alexander.marx@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2015-12-15 13:53:03 +00:00
Arne Fitzenreiter
0505af9dc0 rules.pl: fix geoip initialisation. 2015-04-20 23:14:11 +02:00
Stefan Schantl
0bb4b135d1 rules.pl: Flush GEOIPBLOCK chain when the feature will be switched off.
Otherwise existing rules still remain in the chain and will be processed
even geoipblock has been disabled.
2015-03-15 11:40:46 +01:00
Stefan Schantl
93bfe63d55 Merge branch 'seventeen-geoip' into next-geoip 2015-03-15 11:38:45 +01:00
Alexander Marx
2d0c7a9f7b BUG10620: move reload of firewall.local to main() 2015-03-11 17:11:59 +01:00
Alexander Marx
b9ca2fa60f Add support for generating GeoIP-based firewall rules.
This commit adds support to the rules.pl and firewall-lib.pl to generate
correct iptables commands for inserting GeoIP-based firewall rules
into the kernel.
2015-02-17 18:00:52 +01:00
Stefan Schantl
bc9446c65f Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-2.x into seventeen-geoip
Conflicts:
	make.sh
2015-02-14 12:34:31 +01:00
Michael Tremer
1b34f6cd64 firewall: Fix SNAT rules that use a default network as source
In the POSTROUTING chain using -i intf0 does not work at all.
We now only use the -s parameter to figure out if the rule applied.
The filter chain still uses -i and -o to match patches not only
by the network address, but also by the incoming/outgoing interface.
2015-01-22 16:06:25 +01:00
Stefan Schantl
211694e588 firewall: Add support for geoipblock to rules.pl. 2015-01-04 01:05:45 +01:00
Michael Tremer
d840d02aee firewall: Fix off-by-one error in configuration parser
The configuration parser determines how many comma-separated
values there are in a line. If new values are added we need
to check first if those are set in every line to avoid any
undefined behaviour. A wrong comparison parameter was used
which caused that the limit feature was never enabled in
the rule generation.
2015-01-02 12:27:16 +01:00
Arne Fitzenreiter
24d36c80a6 p2pblock: fix flush rules if all p2p's are allowed. 2014-10-05 15:12:44 +02:00
Arne Fitzenreiter
2a5b19c56f p2pblock: ipp2p must run before CONNTRACK.
And can only used for blocking, not for accept conenections bacause connections must already established for detecting protocol types.
2014-10-04 17:39:51 +02:00
Michael Tremer
791c2b45d8 firewall: fix rules.pl for old rules without ratelimiting. 2014-10-04 13:52:15 +02:00
Michael Tremer
7e09a94a81 Merge remote-tracking branch 'amarx/BUG10620' into next 2014-09-26 13:03:22 +02:00
Michael Tremer
60bce6ba6a Merge remote-tracking branch 'amarx/BUG10615' into next 2014-09-26 13:02:28 +02:00
Michael Tremer
df6649b0fe Merge remote-tracking branch 'amarx/firewall-dnat' into next
Conflicts:
	config/firewall/rules.pl
2014-09-26 12:55:55 +02:00
Alexander Marx
ca4259a758 BUG10620: reload firewall.local in rules.pl, no longer in initscript 2014-09-11 17:13:07 +02:00
Alexander Marx
d2793ea805 BUG10615 part3: adapt rules.pl to use connectionlimit and ratelimit 2014-09-11 15:06:26 +02:00
Michael Tremer
4e9a2b5732 general-functions.pl: Replace lots of broken network code.
The state of some code especially in general-functions.pl
is in such a bad shape and faulty.
This is a first step that replaces some of the network
functions with those who have been tested and work for
undefined inputs.

The old functions have been left in place as stubs
and must be removed at some time.
2014-07-27 22:46:20 +02:00
Alexander Marx
48f07c1957 Firewall: make DNAT only accessible from selected source network
We added RED to the standard networks and now portforwardings are only
useable from the selected source. If selected "all" the portforwarding
can be used from any internal network. Else the access is only grnated
from the selected source network.
2014-07-18 08:44:45 +02:00
Michael Tremer
ff7cb6d60f firewall: Fix accessing port forwardings from internal networks.
When a different "external port" was used, false rules have
been created in the mangle table.
2014-04-20 18:13:35 +02:00
Michael Tremer
766c2f601d rules.pl: Rewrite P2P protocol filter. 2014-04-12 15:40:14 +02:00
Michael Tremer
aa5f4b6568 firewall: Fix creation of automatic rules for the firewall.
If the firewall is part of a local network (e.g. GREEN),
we automatically add rules that grant/forbid access for the firewall,
too.

This has been broken for various default policies other than ALLOWED.
2014-04-12 15:16:08 +02:00
Michael Tremer
fcc68a4277 firewall: Fix rule generation for protocols without ports. 2014-04-09 14:06:32 +02:00
Michael Tremer
085a20ec8b firewall: Fix using aliases.
Fix coding errors, actually read aliases configuration
and fall back to default RED IP address if no suitable
alias was found.
2014-04-05 17:09:56 +02:00
Michael Tremer
025741919a firewall: Fix perl coding error.
Example:
	my @as = (1, 2, 3);
	foreach my $a (@as) {
		$a += 1;
		print "$a\n";
	}

$a will be a reference to the number in the array and not
copied. Therefore $a += 1 will change the numbers in the
array as well, so that after the loop the content of @as
would be (2, 3, 4).
To avoid that, the number needs to be copied into a new
variable like: my $b = $a; and we are fine.

This caused that the content of the @sources and @destinations
array has been altered for the second run of the loop and
incorrect (i.e. no) rules were created.
2014-03-31 13:16:26 +02:00
Michael Tremer
51cf3f8be5 firewall: rules.pl: Honour time constraints for NAT rules as well. 2014-03-21 13:39:03 +01:00
Michael Tremer
f98bb538e5 firewall: rules.pl: Catch invalid configurations. 2014-03-21 13:33:08 +01:00
Michael Tremer
c0ce920610 firewall: rules.pl: Allow REDIRECT rules. 2014-03-21 13:28:00 +01:00
Alexander Marx
4e54e3c6f5 Firewall: Move some functions from rules.pl to firewall-lib.pl 2014-03-21 12:51:04 +01:00
Michael Tremer
d7a14d01e1 firewall: rules.pl: Fix rules with other NAT port. 2014-03-21 12:40:55 +01:00