Skip to content

Instantly share code, notes, and snippets.

@sbz
Created June 8, 2021 14:15
Show Gist options
  • Save sbz/c9873122f9bef25778901d95870187ea to your computer and use it in GitHub Desktop.
Save sbz/c9873122f9bef25778901d95870187ea to your computer and use it in GitHub Desktop.
Test go pf FreeBSD
module github.com/sbz/pf-test
go 1.16
require (
github.com/go-freebsd/kld v0.0.0-20170326221633-78f2bd4a5544 // indirect
github.com/go-freebsd/pf v0.0.0-20190318053615-719aae74de40
github.com/stretchr/testify v1.7.0 // indirect
)
package main
import (
"fmt"
"log"
"github.com/go-freebsd/pf"
)
func main() {
fmt.Println("Test Go-freebsd sbz")
pfDevice, err := pf.Open()
if err != nil {
log.Fatal(err)
}
defer pfDevice.Close()
rules, err := pfDevice.Rules()
if err != nil {
log.Fatal(err)
}
var stats pf.RuleStats
for i, rule := range rules {
rule.Stats(&stats)
fmt.Printf("Rule (%d): %s\t%d\t%d\t%d\t%d\t%d\n", i, rule,
stats.Evaluations,
stats.PacketIn,
stats.PacketOut,
stats.BytesIn,
stats.BytesOut)
}
fmt.Println("End Test Go-freebsd sbz")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment