netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Easynet <devel@easynet.dev>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: libnftnl adding element to a set of type ipv4_addr or ipv6_addr
Date: Wed, 19 Jul 2023 12:53:38 +0200	[thread overview]
Message-ID: <ZLfAshHpX+Zqp6Mh@orbyte.nwl.cc> (raw)
In-Reply-To: <ff54bc23-95f3-8300-c9d4-e5d74581a0e7@easynet.dev>

Hi,

On Tue, Jul 18, 2023 at 09:02:02PM +0200, Easynet wrote:
> I'm building a small firewall daemon that it receives if an user is 
> authenticated and then is adding his IP in a set to be allowed for 24h.
> I'm new in nftnl library and I started to read the documentation and 
> also the examples.
> 
> Until now I was able to add in my daemon these tools based on libnftnl:
> 
> - create / delete / get tables
> - create / delete chains
> - create / delete sets.
> 
> Right now I'm facing an issue that I can't understand how to build the 
> nftnl packet for adding an element to my set, which has interval and 
> timeout flags.

With libnftnl, source is documentation. Go check nftables code on how to
use it. If you need a simpler interface to nftables, I highly recommend
using libnftables instead. You'll either have to pass strings or use a
JSON library for structured in- and output. For simple things such as
adding an element to a set, it more or less boils down to:

| struct nft_ctx *ctx = nft_ctx_new(NFT_CTX_DEFAULT);
| nft_run_cmd_from_buffer(ctx, "add element mytable myset { 123 }");
| nft_ctx_free(ctx);

Cheers, Phil

  reply	other threads:[~2023-07-19 10:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 19:02 libnftnl adding element to a set of type ipv4_addr or ipv6_addr Easynet
2023-07-19 10:53 ` Phil Sutter [this message]
2023-07-19 11:31   ` Easynet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZLfAshHpX+Zqp6Mh@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=devel@easynet.dev \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).