Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1761534

Summary: TestOnly: symbolic variables not working in interactive mode
Product: Red Hat Enterprise Linux 8 Reporter: Tomas Dolezal <todoleza>
Component: nftablesAssignee: Phil Sutter <psutter>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 8.1CC: todoleza
Target Milestone: rcKeywords: TestOnly
Target Release: 8.2Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nftables-0.9.3-4.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-28 16:42:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tomas Dolezal 2019-10-14 15:23:10 UTC
Description of problem:
symbolic variables are available in scripts but cannot be used if lines are executed sequentially in interactive mode. documentation is not 

Version-Release number of selected component (if applicable):
nftables-0.9.0-14.el8.x86_64

How reproducible:
always

Steps to Reproduce:
cat > variable.nft <<EOF
#!/usr/sbin/nft -f

add table inet test_table
add chain inet test_table test_chain

define DNS_SERVERS = { 192.0.2.1, 192.0.2.2 }
add rule inet test_table test_chain ip daddr $DNS_SERVERS accept
EOF

this script can be successfully executed and loads DNS_SERVERS variable.
when executed line-by-line in interactive mode `nft -i`:
nft> add rule inet test_table test_chain ip daddr $DNS_SERVERS accept
Error: unknown identifier 'DNS_SERVERS'
add rule inet test_table test_chain ip daddr $DNS_SERVERS accept
                                              ^^^^^^^^^^^
nft> 

Actual results:
reference to a defined variable (without a failure) leads to dereference error "Error: unknown identifier"

Expected results:
variables should be supported also in interactive mode for script debugging

Additional info:
include statement works in interactive mode

Comment 1 Tomas Dolezal 2019-10-14 16:50:28 UTC
command:
>define DNS_SERVERS = { 192.0.2.1, 192.0.2.2 }; add rule inet example_table example_chain ip daddr $DNS_SERVERS accept
apparently works because the context of variable is apparently ended by EOF

ref 'nft --debug all --interactive' after sole define command
Stack now 0
Entering state 1
Reading a token: --(end of buffer or a NUL)
--EOF (start condition 0)
Now at end of input.
Shifting token "end of file" (: )
Entering state 2
Stack now 0 1 2
Cleanup: popping token "end of file" (: )
Cleanup: popping nterm input (: )


Is there a way to preserve context so that the variable could be used later on during interactive execution?

Comment 2 Phil Sutter 2019-10-30 21:00:43 UTC
Fix sent upstream: https://lore.kernel.org/netfilter-devel/20191030205905.12779-1-phil@nwl.cc/

Comment 3 Phil Sutter 2019-11-07 12:22:44 UTC
Upstream commit to backport:

commit 332325e3c3fab4c25bb5f387f9663205f63748dc
Author: Phil Sutter <phil>
Date:   Wed Oct 30 21:45:39 2019 +0100

    libnftables: Store top_scope in struct nft_ctx
    
    Allow for interactive sessions to make use of defines. Since parser is
    initialized for each line, top scope defines didn't persist although
    they are actually useful for stuff like:
    
    | # nft -i
    | define goodports = { 22, 23, 80, 443 }
    | add rule inet t c tcp dport $goodports accept
    | add rule inet t c tcp sport $goodports accept
    
    While being at it, introduce scope_alloc() and scope_free().
    
    Signed-off-by: Phil Sutter <phil>
    Acked-by: Pablo Neira Ayuso <pablo>

Comment 4 Phil Sutter 2019-12-06 16:28:43 UTC
Implicitly fixed by rebase to 0.9.3 release.

Comment 6 errata-xmlrpc 2020-04-28 16:42:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2020:1774