Skip to content

Commit

Permalink
filter internal traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
myrrc committed Dec 5, 2024
1 parent f884f0f commit 1d1193a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions neonvm-runner/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,23 @@ func getNetworkBytesCounter(iptables *iptables.IPTables, chain string) (uint64,
if err != nil {
return cnt, err
}

// We need to measure only external traffic to/from vm, so we filter internal traffic
for _, rawStat := range rules {
stat, err := iptables.ParseStat(rawStat)
if err != nil {
return cnt, err
}
if stat.Protocol == "6" { // tcp
cnt += stat.Bytes
if stat.Protocol != "6" { // count tcp only
continue
}
src, dest := stat.Source.IP, stat.Destination.IP
if src.IsUnspecified() || dest.IsUnspecified() ||
src.IsLoopback() || dest.IsLoopback() ||
src.IsPrivate() || dest.IsPrivate() {
continue
}
cnt += stat.Bytes
}
return cnt, nil
}
Expand Down

0 comments on commit 1d1193a

Please sign in to comment.