Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions daemon/firewall/rules.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/evilsocket/opensnitch/daemon/core"
"github.com/evilsocket/opensnitch/daemon/log"
"github.com/fsnotify/fsnotify"
"github.com/vishvananda/netlink"
)

// Action is the modifier we apply to a rule.
@@ -90,8 +91,8 @@ func QueueDNSResponses(enable bool, logError bool, qNum int) (err4, err6 error)
// QueueConnections inserts the firewall rule which redirects connections to us.
// They are queued until the user denies/accept them, or reaches a timeout.
// OUTPUT -t mangle -m conntrack --ctstate NEW,RELATED -j NFQUEUE --queue-num 0 --queue-bypass
func QueueConnections(enable bool, logError bool, qNum int) (err4, err6 error) {
return RunRule(INSERT, enable, logError, []string{
func QueueConnections(enable bool, logError bool, qNum int) (error, error) {
err4, err6 := RunRule(INSERT, enable, logError, []string{
"OUTPUT",
"-t", "mangle",
"-m", "conntrack",
@@ -100,6 +101,12 @@ func QueueConnections(enable bool, logError bool, qNum int) (err4, err6 error) {
"--queue-num", fmt.Sprintf("%d", qNum),
"--queue-bypass",
})
// flush conntrack as soon as netfilter rule is set. This ensures that already-established
// connections will go to netfilter queue.
if err := netlink.ConntrackTableFlush(netlink.ConntrackTable); err != nil {
log.Error("error in ConntrackTableFlush %s", err)
}
return err4, err6
}

// CreateSystemRule create the custom firewall chains and adds them to system.

0 comments on commit 616681e

Please sign in to comment.