I tried running the example in the README, and it doesn't even compile as the API has changed since it was written.
The following changes are required:
1. When calling `ci.Chains().Create(...)` use `ChainAttributes`.
2. `ri.Rules().Create(...)` does not accept a rule name, just a rule pointer.
3. `ri.Rules().Create(..)` returns the rule ID and error, not just error.
That being said - when applying the required changes, the result is a table with an empty chain and no set:
```
table ip ipv4table {
chain ipv4chain-1 {
type filter hook prerouting priority filter; policy accept;
}
}
```
Basically, set creation failed without error, which I assume caused the rule creation to fail as a consequence.
Using the following setup:
nftables (bcad476126f07691b7bc3657d1ade257d469e715)
libmnl (2a3e927ec79e3a52d8cea60ccdfb8699b8a0d56e)
libnftnl (e2514c0eff4da7e8e0aabd410f7b7d0b7564c880)
Kernel 5.13 (Ubuntu 20.04 LTS).
Go version 1.14.9.
I think I am running into something similar:
```
package main
import (
"fmt"
"log"
"net"
"github.com/google/nftables"
"github.com/sbezverk/nftableslib"
)
conn := nftableslib.InitConn()
ti := nftableslib.InitNFTables(conn)
conn.FlushRuleset()
ti.Tables().Create("nftableslibtable", nftables.TableFamilyIPv4)
if err := conn.Flush(); err != nil {
fmt.Fatalf("flush failed: %+v\n", err)
}
```
Trying to install this fails:
```
$ CGO_ENABLED=0 go install -v ./cmd/fwng-nftableslib/
github.com/sbezverk/nftableslib
# github.com/sbezverk/nftableslib
../go/pkg/mod/github.com/sbezverk/[email protected]/nfchains.go:115:25: invalid operation: attributes.Hook != ch.chain.Hooknum (mismatched types nftables.ChainHook and *nftables.ChainHook)
../go/pkg/mod/github.com/sbezverk/[email protected]/nfchains.go:117:27: invalid operation: attributes.Priority != ch.chain.Priority (mismatched types nftables.ChainPriority and *nftables.ChainPriority)
../go/pkg/mod/github.com/sbezverk/[email protected]/nfchains.go:154:14: cannot use attributes.Hook (variable of type nftables.ChainHook) as type *nftables.ChainHook in struct literal
../go/pkg/mod/github.com/sbezverk/[email protected]/nfchains.go:155:14: cannot use attributes.Priority (variable of type nftables.ChainPriority) as type *nftables.ChainPriority in struct literal
../go/pkg/mod/github.com/sbezverk/[email protected]/nfchains.go:251:45: cannot convert 0 (untyped int constant) to *nftables.ChainHook
```