Commit graph

298 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
408150073a fix deadlock
closes #365
2021-03-04 12:10:53 +01:00
Gustavo Iñiguez Goia
c7d93d83a5 improved rules (re)loading
- Delete lists of domains if the rule about to change is of type Lists.
- Monitor the lists of domains, and reload them if they're modified.
- Delete rules from disk when the Duration changes from
  Always (saved on disk) to !Always (temporary).
- After the above operation a fsnotify Remove event is fired. Don't
  delete the rule from memory if it's temporary.
- Rules are only compiled if they're enabled, avoiding unnecessary
  allocations.
2021-03-01 12:41:35 +01:00
themighty1
616681e44d flush conntrack at start 2021-02-28 15:21:07 +03:00
Gustavo Iñiguez Goia
0b978c0c1f
Merge pull request #361 from themighty1/master
clean up the obsolete "drop marked"
2021-02-28 10:01:18 +01:00
themighty1
b5bf4edec7 clean up the obsolete "drop marked" 2021-02-28 11:30:26 +03:00
Gustavo Iñiguez Goia
1d277efd01 updated operator and loader tests 2021-02-27 01:56:49 +01:00
Gustavo Iñiguez Goia
44e8561e0c load/reload rules from disk one by one
Any rule changed on disk caused reloading of all rules, usually
up to three times. This caused some problems.

- Don't compile Operators if the rule is disabled.
- Empty lists of domains if the user disables the rule.
- Delete rule from disk if the duration is not Always anymore.
2021-02-27 01:39:04 +01:00
Gustavo Iñiguez Goia
4532c2513e delete loaded lists when needed
There're some situations where we need to delete loaded lists:
 - When an enabled rule of type Lists is disabled (after changed on
   disk, or when configured from the GUI).
 - When an enabled rule of type List with an Operator of type Lists is
   disabled.
2021-02-25 20:09:23 +01:00
Gustavo Iñiguez Goia
c9ba858fc5 add missing operator lists file
needed to load lists.
2021-02-25 13:51:36 +01:00
Gustavo Iñiguez Goia
26671ded24 added support for list of domains
Initial support to filter connections using lists of domains.

The lists must be in hosts format:
- 0.0.0.0 www.domain.com
- 127.0.0.1 www.domain.com

From the rules editor, create a new rule, and select
[x] To this lists of domains

Select a directory with files in hosts format, select [x] Priority rule,
select [x] Deny and click on Apply.

An example of a list in hosts format:
https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt

Note: you can also add a list of domains to allow, not only domains to
block.

TODOs:
- support for URLs besides directories (local lists).
- support for scheduled updates of the above URLs.

related #298
2021-02-25 13:38:48 +01:00
Gustavo Iñiguez Goia
484be33b08
Merge pull request #346 from themighty1/master
makefile:
2021-02-22 16:36:55 +01:00
Gustavo Iñiguez Goia
a325876641 improved connection parsing
Sometimes when querying the kernel for a given connection, the inode of
the connection is 0, i.e.: invalid (or not yet valid).

In these cases we search for the connection in /proc/net/. It turns out
that some connections are found in netstat but the inode is still 0, and
we were accepting them erronously.

As a result, when looking for the inode under /proc we didn't find it,
so an "Unknown process" dialog was shown to the user.

Discarding this type of connections avoids unknown process dialogs when
using Epiphany in particular. It retries to establish the connection
several times, and finally we're able to find the PID of the process.
2021-02-20 23:53:22 +01:00
themighty1
6f6e91ac41 wait for success when sending packet to chan, don't error out after first failed attempt.
When testing this patch under a heavy load of 300 new connections per second running for 12 hours, I saw a few timeouts.
This means that there are legitimate cases when sending the packet to the channel will not go through
no matter how long we wait.
However, compared to the old behavior, the amount of dropped packets decreased by a factor of 100x.

The value of timeout is chosen to be 1 millisecond, because it feels reasonable that if after so long the packet did
not go through, it is not due to a congested channel but due to some other error which will not go away even if we wait longer.
2021-02-19 09:01:01 +03:00
Gustavo Iñiguez Goia
b066b11c47 improved complex rules
Every rule has an entry point besides a constructor, which configures
all it needs to match connections, based on user defined criteria (ip,
regexp, etc).

This only needs to be done the first time we load a rule, because the
fields of a rule are static. However for rules of type "lists" we were
iniatializing each rule of this type once per connection that it
matched.
2021-02-19 01:03:45 +01:00
themighty1
53bf4f7925 do not block connection processing when GUI popup is active. 2021-02-18 19:43:27 +03:00
themighty1
c9ae47fe01 fix logging when flag is passed on command line 2021-02-16 21:19:54 +03:00
Gustavo Iñiguez Goia
2599c784ac
Merge pull request #347 from themighty1/go_vet_fixes
minor fixes to prevent go vet from complaining
2021-02-13 18:09:50 +01:00
themighty1
1d23e73566
test for activepids.go (#345)
* test for activepids.go

* test file

Co-authored-by: themighty1 <you@example.com>
2021-02-13 18:07:51 +01:00
themighty1
41172b65e5 minor fixes to prevent go vet from complaining 2021-02-13 19:18:38 +03:00
themighty1
be0c051205 makefile:
rename, remove unused targets
    trigger targets only when relevant files actually are changed
git:
    do not track files which are generated during make
github actions fix to not rely on a pre-built ui.pb.go
2021-02-13 18:48:49 +03:00
Gustavo Iñiguez Goia
d33cf8b8ba Bump version to 1.3.6 2021-02-10 20:17:02 +01:00
Gustavo Iñiguez Goia
1e45a4c98b tests: fixed TestLookupPidInProc
We expect to find at least one process that its inode 1 points to
/dev/null. The returned pid shouldn't be -1.
2021-02-06 15:29:24 +01:00
themighty1
af9c17ceb8
maintain a cache of struct Process for currently active PIDs (#342)
* maintain a cache of struct Process for currently active PIDs
decreases PID lookup time from ~100usec to ~5usec

* Update activepids.go

remove import "os"

Co-authored-by: themighty1 <you@example.com>
2021-02-06 11:30:59 +01:00
themighty1
ff6ede0557 preserve nfmark when NF_ACCEPT'ing packets
Mullvad VPN uses an nfmark on packets when establishing a connection with their VPN servers.
If we don't preserve the nfmark, the connection will never be established.
2021-01-25 11:50:57 +03:00
Gustavo Iñiguez Goia
b4672830cd fixed regexp rules exceptions
- ui, ruleseditor: added missing operator when using a regular
  expression on the DstIP/Net field.
- daemon, rules: ensure that regular expressions are of type string
  before evaluating them.

reported here: #333
2021-01-17 16:45:28 +01:00
Gustavo Iñiguez Goia
bdafd7fb42 Bump version to 1.3.5 2021-01-11 23:01:23 +01:00
Gustavo Iñiguez Goia
f2c4b37d6e deleted output rule to drop marked packets
We had an OUTPUT rule to drop marked packets. Packets are marked with a
mark when a user defined rule denies a connection.

The thing is that we only intercept NEW connections, and when we deny a
connnection using NF_DROP, the packets doesn't flow to the next iptables
rule or chain. So it'd be rare to see a packet on the OUTPUT chain marked
with the DropMark.

Besides, nfq_set_verdict2() doesn't seem to place the mark on the
packets (libnetfilter-queue 1.0.5).

This OUTPUT rule had 0 hits on different systems and users.
2021-01-10 23:20:50 +01:00
freddii
9e4248e923
fixed german translation (#327)
* fixed german translation

* fixed typing mistake

Co-authored-by: freddii <https://freddii@github.com>
2021-01-05 11:53:12 +01:00
Gustavo Iñiguez Goia
3a3363cb9a rules: delete file from disk if Duration changes
If the user changed the Duration of a rule, from Always to !Always
(temporary), we were not deleting from disk the file of the old
rule.
2021-01-04 12:48:05 +01:00
themighty1
078faa9fda
unittest: test live reloading of rules (#317)
* unittest: test live reloading of rules

* data files for the previous commit

* tests: move files under /testdata; give better names to rules

Co-authored-by: themighty1 <themighty1>
2020-12-28 12:59:29 +01:00
luz paz
d15d3465a9 Fix random typos
Found via `codespell v2.1.dev0`  
`codespell -q 3 -L ans`
2020-12-23 13:24:59 -05:00
Gustavo Iñiguez Goia
85fc5396bf updated grpc protocol files 2020-12-22 22:14:53 +01:00
Gustavo Iñiguez Goia
1384db6a1b fw: clean system rules before insert new ones
If the daemon exits unexpectedly, fw rules are not deleted.
So on every start/reload, clean any possible rule before adding new
ones.
2020-12-22 22:06:37 +01:00
themighty1
3abb3e4c0d Use daemon's event timestamp in UI.
Use the timestamp instead of the event object when iterating over the last events. ~15x speed increase.
Increase event buffer to 100. On my machine I routinely hit the ceiling of 50 events under some multitasking workloads. Small buffer results in connection attempts not being logged.
Fix Makefile to rebuild when ui.proto changes
2020-12-22 22:50:18 +03:00
Gustavo Iñiguez Goia
9b035ca66e added unit tests for process parsing and rules 2020-12-19 19:31:09 +01:00
Gustavo Iñiguez Goia
e59133beb2 rules: skip checking not enabled rules 2020-12-18 16:42:34 +01:00
Gustavo Iñiguez Goia
438ceca57d Bump version to 1.3.0 2020-12-16 18:59:03 +01:00
Gustavo Iñiguez Goia
2f2363785e updated pkgs url paths 2020-12-16 18:14:37 +01:00
Gustavo Iñiguez Goia
4443673ed1 fixed how we check rules
- Rules are checked in alphabetical order.
- Deny and Priority rules must take precedence.
- If a rule matches and it's Allow-NoPriority, then return the rule.
- Otherwise we'll return nil.
2020-12-15 16:09:28 +01:00
Gustavo Iñiguez Goia
b6cbc6769e fixed rules Enabled check 2020-12-13 11:50:58 +01:00
Gustavo Iñiguez Goia
db31e5b71a fw: fixed 100% CPU spike, fixed cleaning rules
- Fixed 100% CPU spike when pausing interception from the GUI
gustavo-iniguez-goya/opensnitch/issues/104
- Fixed monitoring fw rules after re-enabling interception.
- Fixed cleaning up interception and system rules.
2020-12-12 18:16:59 +01:00
Gustavo Iñiguez Goia
f751dc13c6 removed sudo from Makefiles
Documentation must be updated to indicate when to use sudo.

closes #291
2020-12-11 23:42:47 +01:00
Gustavo Iñiguez Goia
719c906267 fixed regexp rules when using case-sensitive strings 2020-12-11 22:03:00 +01:00
Gustavo Iñiguez Goia
d47e75d76f fixed filtering by dst network, fixed regression
- Fixed complex rules.
- Fixed filtering by destination network.
2020-12-10 23:09:24 +01:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
ac9fc47d9a auditd: don't parse proctitle field, use cmdline instead
auditd proctitle field sems to be trunctated to 128 characters, which
causes in some situations to not obtain the complete command line.
2020-12-07 13:01:10 +01:00
Gustavo Iñiguez Goia
1f415a5799 added option to filter by destination network
Now you can filter by destination network, for example:
- 127.0.0.1/8
- 192.168.1.0/24

This will ease to solve the request #89 .

Some common network ranges have also been added so you can select them
from a combo box. More info #73.

Added process.id operator operand for future use, in order to filter by
PID.
2020-12-04 01:11:47 +01:00
Gustavo Iñiguez Goia
6619124db7 Bumped versions to 1.3.0rc2 2020-11-28 12:26:39 +01:00
Gustavo Iñiguez Goia
df952d974e fixed errors when IPv6 is not enabled in the system
If IPv6 was not enabled we failed to add IPv6 rules.

closes #96
2020-11-26 16:25:48 +01:00
Gustavo Iñiguez Goia
e8683e77be improved packets parsing
We were checking several times if a packet was IPv6.

Additionally we were itereating over all the layers of the packet, when
in reality we're only interested in network layer and transport layer.

This change brings down packets parsing from ~200µs to ~2µs.
2020-11-24 01:35:36 +01:00