MagiTrickle/netfilter-helper/netfiler-helper.go

29 lines
501 B
Go
Raw Normal View History

2024-09-06 14:24:55 +03:00
package netfilterHelper
import (
"fmt"
"github.com/coreos/go-iptables/iptables"
)
type NetfilterHelper struct {
IPTables *iptables.IPTables
}
2024-09-14 15:16:50 +03:00
func New(isIPv6 bool) (*NetfilterHelper, error) {
var proto iptables.Protocol
if !isIPv6 {
proto = iptables.ProtocolIPv4
} else {
proto = iptables.ProtocolIPv6
}
ipt, err := iptables.New(iptables.IPFamily(proto))
2024-09-06 14:24:55 +03:00
if err != nil {
return nil, fmt.Errorf("iptables init fail: %w", err)
}
return &NetfilterHelper{
IPTables: ipt,
}, nil
}