All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Zagrabelny <mzagrabe@d.umn.edu>
To: netfilter <netfilter@vger.kernel.org>
Subject: Re: testing if a named set exists?
Date: Sat, 2 Oct 2021 06:50:35 -0500	[thread overview]
Message-ID: <CAOLfK3VJ28CLb5K-gbKVHO+F+vQh5wywb65wbFnAdsSpq2DQ-Q@mail.gmail.com> (raw)
In-Reply-To: <20211002035707.bf92730b8f667517ba53dfad@plushkava.net>

Hey Kerin (and Duncan),

Thanks for the replies.

On Fri, Oct 1, 2021 at 9:57 PM Kerin Millar <kfm@plushkava.net> wrote:
>
> On Fri, 1 Oct 2021 20:16:17 -0500
> Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
>
> > I'd like to do something like the following:
> >
> > if exists $named_set
> >     nft add rule ip filter output ip daddr $named_set accept
> > else
> >     nft add rule ip filter output ip daddr $default_set accept
> >
> > Does anyone know if I can accomplish this with nftables?
> >
>
> The output of nft isn't particularly amenable to parsing unless it is instructed to produce JSON. The simplest way is to act upon the exit status value of a list set command.
>
> if nft --terse list set ip filter "$named_set" >/dev/null 2>&1; then ...

I should have been more specific...

I'm hoping to do this all in nft without hitting the shell. For
example, from "man bash" we have:

       ${parameter:-word}
              Use Default Values.  If parameter is unset or null, the
expansion of word is  substituted.   Otherwise,
              the value of parameter is substituted.

I was hoping for some sort of similar mechanism in nft. Like:

nft add rule ip filter output ip daddr
${named_set_does_not_exist:-default_named_set} accept

Thanks for the help!

-m

  reply	other threads:[~2021-10-02 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-02  1:16 testing if a named set exists? Matt Zagrabelny
2021-10-02  2:52 ` Duncan Roe
2021-10-02  2:57 ` Kerin Millar
2021-10-02 11:50   ` Matt Zagrabelny [this message]
2021-10-02 23:50     ` Kerin Millar

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=CAOLfK3VJ28CLb5K-gbKVHO+F+vQh5wywb65wbFnAdsSpq2DQ-Q@mail.gmail.com \
    --to=mzagrabe@d.umn.edu \
    --cc=netfilter@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.