mirror of
https://github.com/safing/portmaster
synced 2025-09-04 11:39:29 +00:00
Reset connection handling channel when firewall handler is stopped
This commit is contained in:
parent
2388c1b036
commit
e562e196c9
1 changed files with 13 additions and 2 deletions
|
@ -579,9 +579,10 @@ func (conn *Connection) delete() {
|
||||||
|
|
||||||
// SetFirewallHandler sets the firewall handler for this link, and starts a
|
// SetFirewallHandler sets the firewall handler for this link, and starts a
|
||||||
// worker to handle the packets.
|
// worker to handle the packets.
|
||||||
|
// The caller needs to hold a lock on the connection.
|
||||||
func (conn *Connection) SetFirewallHandler(handler FirewallHandler) {
|
func (conn *Connection) SetFirewallHandler(handler FirewallHandler) {
|
||||||
if conn.firewallHandler == nil {
|
if conn.firewallHandler == nil {
|
||||||
conn.pktQueue = make(chan packet.Packet, 1000)
|
conn.pktQueue = make(chan packet.Packet, 100)
|
||||||
|
|
||||||
// start handling
|
// start handling
|
||||||
module.StartWorker("packet handler", conn.packetHandlerWorker)
|
module.StartWorker("packet handler", conn.packetHandlerWorker)
|
||||||
|
@ -590,9 +591,15 @@ func (conn *Connection) SetFirewallHandler(handler FirewallHandler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopFirewallHandler unsets the firewall handler and stops the handler worker.
|
// StopFirewallHandler unsets the firewall handler and stops the handler worker.
|
||||||
|
// The caller needs to hold a lock on the connection.
|
||||||
func (conn *Connection) StopFirewallHandler() {
|
func (conn *Connection) StopFirewallHandler() {
|
||||||
conn.firewallHandler = nil
|
conn.firewallHandler = nil
|
||||||
|
|
||||||
|
// Signal the packet handler worker that it can stop.
|
||||||
conn.pktQueue <- nil
|
conn.pktQueue <- nil
|
||||||
|
|
||||||
|
// Unset the packet queue so that it can be freed.
|
||||||
|
conn.pktQueue = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandlePacket queues packet of Link for handling.
|
// HandlePacket queues packet of Link for handling.
|
||||||
|
@ -611,9 +618,13 @@ func (conn *Connection) HandlePacket(pkt packet.Packet) {
|
||||||
|
|
||||||
// packetHandlerWorker sequentially handles queued packets.
|
// packetHandlerWorker sequentially handles queued packets.
|
||||||
func (conn *Connection) packetHandlerWorker(ctx context.Context) error {
|
func (conn *Connection) packetHandlerWorker(ctx context.Context) error {
|
||||||
|
// Copy packet queue, so we can remove the reference from the connection
|
||||||
|
// when we stop the firewall handler.
|
||||||
|
pktQueue := conn.pktQueue
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case pkt := <-conn.pktQueue:
|
case pkt := <-pktQueue:
|
||||||
if pkt == nil {
|
if pkt == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue