Skip to content

Set with key type nftables.TypeIFName not working #177

Open
@rdmcguire

Description

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

Sample code for set:

        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

% 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

% 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

        // 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions