178 Commits

Author SHA1 Message Date
Vincent Li
97e543817a firewall: Allow WG traffic when the firewall is in permissive mode
commit d6868ae94c63d0f708985e6bb6604a4bd40cf1a8
    Author: Michael Tremer <michael.tremer@ipfire.org>
    Date:   Fri Sep 6 18:20:46 2024 +0200

        firewall: Allow WG traffic when the firewall is in permissive mode

        Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>

Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>
2025-07-04 03:40:37 +00:00
Vincent Li
d270ada82c firewall: Add support for WireGuard peers to groups
commit 1de96a83d6d6cec5d4d3eda1792aa80bfbd8fafe
    Author: Michael Tremer <michael.tremer@ipfire.org>
    Date:   Wed Apr 23 12:35:52 2025 +0200

        firewall: Add support for WireGuard peers to groups

        Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>

Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>
2025-07-04 03:25:56 +00:00
Vincent Li
e48a29a3f1 Add XDP SYNPROXY rules in raw and filter table
XDP SYNPROXY requires setting up iptables rule
in raw table PREROUTING chain and filter table
INPUT chain.

Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>
2024-03-16 03:26:18 +00:00
Adolf Belka
f23555a1c6 rules.pl: Fixes bug12981 - Add in and out specific actions for drop hostile
- This changes the action from HOSTILE_DROP to HOSTILE_DROP_IN for icnoming traffic and
   HOSTILE_DROP_OUT for outgoing traffic enabling logging decisions to be taken on each
   independently.

Fixes: bug12981
Signed-off-by: Adolf Belka <adolf.belka@ipfire.org>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
Acked-by: Bernhard Bitsch <bbitsch@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-02-07 11:02:17 +00:00
Peter Müller
726c4b0f4a firewall: Reject outgoing TCP connections to port 25 by default
This will affect new IPFire installations only, implementing a
long-standing BCP for preemptively combating botnet spam. Reject is
chosen over drop to reduce the likelihood for confusion during network
troubleshooting.

Cc: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Tested-by: Peter Müller <peter.mueller@ipfire.org>
2023-11-21 19:04:44 +00:00
Stefan Schantl
b5784fbc33 firewall: Allow traffic from multicast networks
The multicast network segment 224.0.0.0/4 is used for a lot of
different services provided by the local ISP's. (IPTV etc.)

We have to allow traffic from this networks when using one of
the BOGON blocklists in order to get those ISP services still
accessable.

https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml

Fixes 13092.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2023-05-02 19:28:57 +00:00
Matthias Fischer
ab5b17a98e rules.pl: Proposed patch - Fix for missing bracket
Signed-off-by: Matthias Fischer <matthias.fischer@ipfire.org>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
2023-03-12 20:38:37 +00:00
Stefan Schantl
1b70ead36d firewall: Silence warnings if blocklist logging is not set.
Reference: #12979.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2023-03-11 16:27:31 +00:00
Michael Tremer
9c02f36e21 firewall: Avoid creating a rule that permits all traffic on invalid source
The firewall engine generated rules that did not have any traffic
selectors due to an improperly initialized variable in the source.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Acked-by: Peter Müller <peter.mueller@ipfire.org>
2023-01-18 23:27:19 +00:00
Michael Tremer
dc84e16d4d firewall: Fix missing whitespace for blocklist messages
Fixes: #12934
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2022-10-10 09:32:53 +00:00
Stefan Schantl
6f37368da6 rules.pl: Do not check private networks against ipblocklists.
In case some of these private networks are part of an used blocklist
this kind of traffic needs to be allowed. Otherwise some services may
not work properly.

For example:
In case one ore more IPSec N2N connections are configured no traffic can
be passed through it, if the used networks are part of an blocklist.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:27:14 +02:00
Stefan Schantl
adbd2bd6d4 rules.pl: Flush ipblocklist DROP chains.
Flush the DROP chains of the blocklist chains while reloading the
firewall. Otherwise the log rules will stay even if logging has been
disabled in the meantime.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:27:14 +02:00
Stefan Schantl
404b513794 ipblocklist: Add "v4" as extension to the ipset set names.
This easily allows us to swap the sets after updating, without
unloading them.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:27:14 +02:00
Stefan Schantl
aba4e1cd1e rules.pl: Refactor logic to handle the IP blocklist feature.
* Fixes that the same chain would be created each time a firewall
reload is performed.

* Also fixes multiple log and drop rules inside the the BLOCKLIST_DROP
  chains after doing a firewall reload.

* Orphaned BLOCKLIST_DROP chains now will be flushed and removed in case
  the blocklist gets disabled or the entire feature will be swithed off.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:14 +02:00
Stefan Schantl
960608c8b5 rules.pl: Add function to check if given firewall chain exists.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:14 +02:00
Stefan Schantl
36330f84fb rules.pl: Fix typo when creating blocklist drop chains.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:14 +02:00
Stefan Schantl
39eba7abab rules.pl: Check if the blocklist is part of the settings hash.
Otherwise there will pop up some ugly notices on the command line and
the logs.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:14 +02:00
Rob Brewer
bbbea6f9ba rules.pl: Add space at the end of the log prefix.
This improves the readabiliy when digging through the logs.

Signed-off-by: Rob Brewer <rob.brewer@ipfire.org>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:14 +02:00
Stefan Schantl
a7bf1d9666 rules.pl: Add code to deal with ipblocklists.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Stefan Schantl
8b97a537f5 rules.pl: Fix automatic ipset sets cleanup.
The array of used/loaded ipsets needs to be reloaded before
the cleanup can be started to also handle sets which are loaded during
runtime.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Acked-by: Peter Müller <peter.mueller@ipfire.org>
2022-04-29 19:47:43 +00:00
Stefan Schantl
abf148cebd rules.pl: Fix creating rules for location based groups.
The former used hash value only contains the country code when
a rule for a single country should be created.

In case a location group is used the hash value refers to the group name,
which does not work here.

The required country code is part of the processed string and can be omitted
from here. This works well for single codes and location groups, because those
are processed in a loop.

Fixes #12809.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Acked-by: Peter Müller <peter.mueller@ipfire.org>
2022-03-23 17:12:37 +00:00
Michael Tremer
e77d960bac firewall: Make blocking all traffic impossible on HOSTILE
The current setup can fail and block all traffic on RED if the RETURN
rules could not be created.

This can happen when the kernel fails to load the ipset module, as it is
the case after upgrading to a new kernel. Restarting the firewall will
cause that the system is being cut off the internet.

This design now changes that if those rules cannot be created, the
DROP_HOSTILE feature is just inactive, but it would not disrupt any
traffic.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Daniel Weismüller <daniel.weismueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2022-03-14 15:19:12 +00:00
Stefan Schantl
74659290e9 rules.pl: Do not create HOSTILE rules if no red dev is available.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2022-03-09 15:45:59 +00:00
Stefan Schantl
870c223e0f rules.pl: Adjust code to use sets generated by libloc 0.9.11
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2022-03-09 15:43:17 +00:00
Stefan Schantl
96e2e870aa firewall-lib.pl: Remove prefix when dealing with ipset sets.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-03-05 14:32:58 +00:00
Stefan Schantl
5841800969 rules.pl: Autodetect ipset db file to restore.
This commit allows the ipset_restore() function to auto-detect
which set file needs to be restored.

Currently it is limitated to country codes only, because we currently
does not support anything else.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-03-05 14:32:44 +00:00
Stefan Schantl
7b529f5417 firewall: Move dropping hostile networks to rules.pl.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-03-05 14:31:55 +00:00
Stefan Schantl
2801213dcc rules.pl: Allow dynamic destory of loaded but unused ipset sets.
Instead of stupidly destroying all ipsets, we now grab the already loaded sets
and compare them with the loaded sets during runtime of the script.

So we are now able to determine which sets are not longer required and
safely can destroy (unload) at a later time.

This saves us from taking care about dropping/flushing rules which are
based on ipset before we can destroy them - because only unused sets are
affected.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Inspired-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-03-05 14:31:51 +00:00
Stefan Schantl
bae9b5dcca rules.pl: Adjust check against loading the same lists multiple times.
This check now has been moved to the ipset_restore() function, which
will help to keep the code clean and maintain-able.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
2022-02-17 19:32:42 +00:00
Stefan Schantl
31c64b9d0d configroot: Drop config file for p2protocols.
The support for creating P2P based rules has been removed from the
firewall. So this file is not longer needed.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Acked-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:13:12 +00:00
Stefan Schantl
b6e4ebe86f firewall: Drop support for blocking P2P protocols.
The main P2P (peer-to-peer) aera has passed for several year now, so
this kind of feature is realy out-dated.

The feature only supports a handfull of P2P protocols (mostly unencrypted)
for applications, which have been superseeded by various other
applications and protocols.

So, this fairly is not longer required and safely can be dropped.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Acked-by: Peter Müller <peter.mueller@ipfire.org>
Acked-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:12:59 +00:00
Stefan Schantl
0564b0c7c9 rules.pl: Add workaround to hide a warning about an only once used variable.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
2022-02-15 18:07:31 +00:00
Stefan Schantl
50e4305955 rules.pl: Check if an ipset db file exists before call to restore it.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:07:26 +00:00
Stefan Schantl
278289690d rules.pl: Do not try to restore the same ipset multiple times.
When an ipset list get restored, this now will be documented in a hash
and this hash also will be checked before restoring a list if this has
not be done previously.

This will prevent from restoring the same list multiple times.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
2022-02-15 18:07:22 +00:00
Stefan Schantl
07106467b8 rules.pl: Move to ipset based data for location based firewall rules.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:07:13 +00:00
Stefan Schantl
0df1d268ed rules.pl: Move to ipset based data for LOCATIONBLOCK feature.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:07:07 +00:00
Stefan Schantl
6babb404cc rules.pl: Add tiny ipset_restore function.
This helper function is used to load a previously exported list of
networks for a given country code into the ipset module, so it can be
used for any kind of firewall rules.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:07:03 +00:00
Stefan Schantl
3d88688075 rules.pl: Destroy all ipset lists on rule reload.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
2022-02-15 18:06:59 +00:00
Stefan Schantl
bbeb2a5067 rules.pl: Move flush of LOCATIONBLOCK into main flush() function.
It is required to get rid of all ipset based rules before all of
the loaded ipset lists can be destroyed.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
2022-02-15 18:06:54 +00:00
Alexander Marx
feef6aca68 BUG12301: Iptables “host/network ‘none’ not found”
Fixes: #12301

When using hosts with MAC-addresses in a hostgroup,
the rule won't be generated if those hosts are selected as target.
There is a hint but due to a wrong hashparameter the hint was not shown.

With this patch the hint is shown again.
Additionally the rule is skipped when rules.pl creates rules.

There are no bootmessages with failed target "none" anymore.
Acked-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-02-06 17:18:31 +00:00
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
Michael Tremer
053a582d3a ipsec-policy: Do no create DROP rules for on-demand mode
This is not necessary and gets in the way if users have SNAT rules or
other things that make the check be in the wrong place.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2021-06-11 16:15:37 +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
18c9fd2820 firewall-lib.pl: Fix typo.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2020-06-13 19:10:15 +02:00
Stefan Schantl
006e3c6c31 firewall-lib.pl: Rework code to use location-functions.pl
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2020-06-12 19:21:27 +02:00
Stefan Schantl
46269ee5fb Transform geoipblock into locationblock settings file.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2020-06-12 19:09:29 +02: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