Infer VPN packet traffic class

This commit is contained in:
2026-05-15 16:38:00 +03:00
parent 50db5e7a0d
commit af85f6e309
4 changed files with 96 additions and 3 deletions
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
"time"
)
@@ -119,3 +120,28 @@ func cleanProductionVPNPacketBatch(packets [][]byte) [][]byte {
}
return cleaned
}
func inferVPNPacketTrafficClass(explicit string, packets [][]byte) string {
explicit = strings.TrimSpace(strings.ToLower(explicit))
if explicit != "" && explicit != "bulk" {
return explicit
}
for _, packet := range packets {
if isVPNPacketTCPControl(packet) {
return "interactive"
}
}
return explicit
}
func isVPNPacketTCPControl(packet []byte) bool {
if len(packet) < 20 || packet[0]>>4 != 4 {
return false
}
ihl := int(packet[0]&0x0f) * 4
if ihl < 20 || len(packet) < ihl+20 || packet[9] != 6 {
return false
}
flags := packet[ihl+13]
return flags&0x17 != 0
}