windows_kext/PacketFlow.md
An explanation on the complete path of the packet from entering to the exit of the kernel extension.
The packet entry point depends on the packet and the internal windows filter state:
Each defined ALE layer has a filter linked to it. This filter has a state.
When a decision is made to block or permit a connection it will be saved to the filter state.
The only way to update the decision in a filter is to clear the whole state and apply the decision for the next packet of each connection.
For outgoing connections this logic fallows:
For incoming connection this logic fallow:
If more packets arrive before Portmaster returns a decision, packet will be absorbed and another event will be sent. For Outgoing connection this will happen in ALE layer. For Incoming connection this will happen in Packet layer.
Connection cache will be updated and the packet will be injected. The next steps depend of the direction of the packet and the verdict
Permanent Verdict / Outgoing connection
Temporary Verdict / Outgoing connection
Permanent or Temporary Verdict / Incoming connection
There is no defined ALE layers for inbound connection. Inbound packets are handed compactly by the packet layer
Fallowing specifics apply to the ALE layer:
reauthorize == false are special. When the flag is false that means that a applications is calling a function connect() or accept() for a connection. This is a special case because we control the result of the function, telling the application that it's allowed or not allowed to continue with the connection. Since we are making request to Portmaster we need to take longer time. This is done with pending the packet. This allows the kernel extension to pause the event and continue when it has the verdict. See ale_callouts.rs -> save_packet() function.The logic for the packet is split in two:
The packet layer will not process packets that miss a cache entry:
For packets with a cache entry:
After portmaster returns the verdict for the packet. If its allowed it will be modified (if needed) and injected everything else will be dropped. The packet layer will permit all injected packets.
Does packets are treated as with temporary verdict. There will be no cache entry for them. Every packet will be send to Portmaster for a decision and re-injected if allowed.
It holds information for all TCP and UDP connections. Local and destination ip addresses and ports, verdict, protocol, process id It also holds last active time and end time.
Cache entry is removed automatically 1 minute after an end state has been set or after 10 minutes of inactivity.
End stat is set by Endpoint layers or Resource release layers.