LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2022, 02:48 PM   #1
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Syntax for nft list sets ... ?


I have named set in nftables:

Code:
# nft get element inet filter myset { 159.203.2.200 }
table inet filter {
        set myset {
                type ipv4_addr
                flags interval
                auto-merge
                elements = { 159.203.2.200 }
        }
}
What is the generic way to list all the elements in the set?

I've tried the following but neither are accepted?

Code:
nft list sets ip filter myset

nft list sets inet myset
What is the correct syntax, given the set described above?
 
Old 07-30-2022, 09:05 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557
Quote:
Originally Posted by Turbocapitalist View Post
What is the generic way to list all the elements in the set?
Dunno, but in the absence of responses I looked at SETS in man nft, and from the convoluted syntax description, I think the relevant accepted list syntax would seem to be:
Code:
list set [family] table set
list sets [family]
So the commands you typed (which appear to include both family and table set) should use the singular "nft list set ..." to be valid?

And, based on the description of "list" below the syntax - maybe to get all elements back might just be "nft list sets" and/or "nft list sets inet" ?


Last edited by boughtonp; 07-30-2022 at 09:07 AM.
 
Old 07-30-2022, 09:47 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359

Original Poster
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Thanks. The former doesn't seem to be accepted by nft and the latter only lists the structure of the blacklist set:

Code:
# nft list sets inet
table inet filter {
        set myset {
                type ipv4_addr
                flags interval
                auto-merge
        }
}
I'm trying to get the full list of addresses and networks which have been stored in the set.
 
Old 07-30-2022, 03:11 PM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557

What version of nftables?

Debian Buster has nftables 0.9.0-2 which supports "nft export json" - so a hacky workaround might be to do that and filter with jq.

Debian Bullseye has nftables 0.9.8-3.1 where "export" command has been removed; not sure if equivalent is "nft --json list ruleset" or something else.

 
Old 07-31-2022, 03:10 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359

Original Poster
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Alpine seems to have nftables-1.0.4

The new syntax for JSON seems to be nft -j list ruleset so jq can work like this:

Code:
nft -j list ruleset \
| jq '.nftables[2].set | select(.name=="myset")| .elem'
Unfortunately, the CIDR networks in the blacklist are written out like this:

Code:
...
  {
    "prefix": {
      "addr": "31.13.24.0",
      "len": 21
    }
  },
  {
    "range": [
      "31.13.103.6",
      "31.13.103.8"
    ]
  },
...
So while it's close, it would require a lot of additional processing and thus not an option.

Perhaps the syntax error in nft is a bug, since of the line shown in the wiki doesn't actually work.
 
Old 07-31-2022, 06:20 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557

Yep, a mismatch between documented behaviour and observed behaviour is a bug, since at least one of the two needs correcting.

Probably asking on the nftables mailing list is the best way to find out which.

 
  


Reply

Tags
named set, nft, nftables



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What is the relationship or difference among iptables, xtables, iptables-nft, xtables-nft, nf_tables, nftables blueray Linux - Newbie 1 01-25-2022 06:06 PM
nftables : nft commands throwing " error - Operation not supported" Santoshkb Linux - Networking 2 05-12-2020 07:51 AM
Need help for nftables : nft commands throwing " error - Operation not supported" Santoshkb Linux - Security 1 05-11-2020 07:56 AM
nft chain priority and policy keithwilliamsnp Linux - Security 0 12-01-2018 12:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration