Add windowskext integration, update related packages
This commit is contained in:
@@ -3,8 +3,12 @@ package interception
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Safing/portmaster/firewall/interception/windivert"
|
||||
"github.com/Safing/portbase/log"
|
||||
"github.com/Safing/portbase/notifications"
|
||||
"github.com/Safing/portbase/utils/osdetail"
|
||||
"github.com/Safing/portmaster/firewall/interception/windowskext"
|
||||
"github.com/Safing/portmaster/network/packet"
|
||||
"github.com/Safing/portmaster/updates"
|
||||
)
|
||||
|
||||
var Packets chan packet.Packet
|
||||
@@ -17,15 +21,73 @@ func init() {
|
||||
// Start starts the interception.
|
||||
func Start() error {
|
||||
|
||||
wd, err := windivert.New("/WinDivert.dll", "")
|
||||
dllFile, err := updates.GetPlatformFile("kext/portmaster-kext.dll")
|
||||
if err != nil {
|
||||
return fmt.Errorf("firewall/interception: could not init windivert: %s", err)
|
||||
return fmt.Errorf("interception: could not get kext dll: %s", err)
|
||||
}
|
||||
kextFile, err := updates.GetPlatformFile("kext/portmaster-kext.sys")
|
||||
if err != nil {
|
||||
return fmt.Errorf("interception: could not get kext sys: %s", err)
|
||||
}
|
||||
|
||||
return wd.Packets(Packets)
|
||||
err = windowskext.Init(dllFile.Path(), kextFile.Path())
|
||||
if err != nil {
|
||||
return fmt.Errorf("interception: could not init windows kext: %s", err)
|
||||
}
|
||||
|
||||
err = windowskext.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("interception: could not start windows kext: %s", err)
|
||||
}
|
||||
|
||||
go windowskext.Handler(Packets)
|
||||
go handleWindowsDNSCache()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop starts the interception.
|
||||
func Stop() error {
|
||||
return nil
|
||||
return windowskext.Stop()
|
||||
}
|
||||
|
||||
func handleWindowsDNSCache() {
|
||||
|
||||
err := osdetail.StopService("dnscache")
|
||||
if err != nil {
|
||||
// cannot stop dnscache, try disabling
|
||||
if err == osdetail.ErrServiceNotStoppable {
|
||||
err := osdetail.DisableDNSCache()
|
||||
if err != nil {
|
||||
log.Warningf("firewall/interception: failed to disable Windows Service \"DNS Client\" (dnscache) for better interception: %s", err)
|
||||
notifyDisableDNSCache()
|
||||
}
|
||||
notifyRebootRequired()
|
||||
return
|
||||
}
|
||||
|
||||
// error while stopping service
|
||||
log.Warningf("firewall/interception: failed to stop Windows Service \"DNS Client\" (dnscache) for better interception: %s", err)
|
||||
notifyDisableDNSCache()
|
||||
}
|
||||
|
||||
// log that service is stopped
|
||||
log.Info("firewall/interception: Windows Service \"DNS Client\" (dnscache) is stopped for better interception")
|
||||
|
||||
}
|
||||
|
||||
func notifyDisableDNSCache() {
|
||||
(¬ifications.Notification{
|
||||
ID: "windows-disable-dns-cache",
|
||||
Message: "The Portmaster needs the Windows Service \"DNS Client\" (dnscache) to be disabled for best effectiveness.",
|
||||
Type: notifications.Warning,
|
||||
}).Init().Save()
|
||||
}
|
||||
|
||||
func notifyRebootRequired() {
|
||||
(¬ifications.Notification{
|
||||
ID: "windows-dnscache-reboot-required",
|
||||
Message: "Please restart your system to complete Portmaster integration.",
|
||||
Type: notifications.Warning,
|
||||
}).Init().Save()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user