google / google/nftables

Set with key type nftables.TypeIFName not working

Open
#177 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
1.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

Creating a set with Type: nftables.TypeIFName seems to work, but the set acts strangely.

*Sample code for set:*
```go
conn.AddSet(&nftables.Set{
Table: table,
Name: "test_set",
KeyType: nftables.TypeIFName,
}, nil)
```

I also created a set called "manual_set" manually, and they both list:

*nftables pkg set and nft cli set*
```sh
% nft 'add set test_table manual_set { type ifname; }'
% nft list table test_table
table ip test_table {
set test_set {
type ifname
}

set manual_set {
type ifname
}
}
```

I then added an element into each set using nft cli and they both seem to succeed, however ***the set created by this package shows empty elements***.

*Added Elements*
```sh
% nft 'add element test_table test_set { "wg0" }'
% nft 'add element test_table manual_set { "wg0" }'
% nft list table test_table   ☸ kubernetes-admin@50w_k8s:argocd 
table ip test_table {
set test_set {
type ifname
elements = { "" }
}

set manual_set {
type ifname
elements = { "wg0" }
}
}
```

Additionally, trying to add an element through this package fails for either table, though I do wonder if I've missed something in my code:

*Attempt to add set element to both tables*
```go
// github.com/google/nftables set and manual set
testSet, _ := c.GetSetByName(table, "test_set")
manualSet, _ := c.GetSetByName(table, "manual_set")

// Second Element
elements := []nftables.SetElement{{Key: []byte("wg1")}}

c.SetAddElements(manualSet, elements)
c.SetAddElements(testSet, elements)

if err := c.Flush(); err != nil {
log.Panicf("Error: %s", err)
}
```

Running returns error: "conn.Receive: netlink receive: invalid argument"

I've tried a few different key types and have only had success with TypeFamilyIPv4.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.