Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 560920 - net-firewall/nftables-0.5 init script is broken
Summary: net-firewall/nftables-0.5 init script is broken
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-20 15:55 UTC by diamond
Modified: 2015-12-25 07:57 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
nftables init script patch for version 0.5 (nftables.patch,5.14 KB, patch)
2015-09-20 18:28 UTC, nvinson234
Details | Diff
Updated init script for users of kernels older then 3.18 (nftables_deprecated.init,4.09 KB, text/plain)
2015-09-26 17:30 UTC, nvinson234
Details
Updated init script for users of kernel versions 3.18 or newer (nftables.init,2.32 KB, text/plain)
2015-09-26 17:31 UTC, nvinson234
Details
Updated ebuild (nftables-0.5.ebuild,1.24 KB, text/plain)
2015-09-26 17:31 UTC, nvinson234
Details
nftables-0.5 ebuild panic() patch (nftables-0.5.ebuild.diff,465 bytes, patch)
2015-10-07 01:10 UTC, nvinson234
Details | Diff
nftables-0.4 ebuild panic() patch (nftables-0.4.ebuild.diff,465 bytes, patch)
2015-10-07 01:11 UTC, nvinson234
Details | Diff
Revised nftables init script (nftables.init,4.60 KB, text/plain)
2015-10-07 01:13 UTC, nvinson234
Details
the panic nftables ruleset (rules-panic,461 bytes, text/plain)
2015-10-07 01:14 UTC, nvinson234
Details
IPv4 panic nftables ruleset (rules-panic.ip,230 bytes, text/plain)
2015-10-07 11:16 UTC, nvinson234
Details
IPv6 panic nftables ruleset (rules-panic.ip6,231 bytes, text/plain)
2015-10-07 11:17 UTC, nvinson234
Details
Revised nftables init script (nftables.init,5.22 KB, text/plain)
2015-10-07 11:21 UTC, nvinson234
Details
nftables-0.4. ebuild panic() patch (nftables-0.4.ebuild.patch,474 bytes, patch)
2015-10-07 11:24 UTC, nvinson234
Details | Diff
nftables-0.5 ebuild panic() patch (nftables-0.5.ebuild.patch,474 bytes, patch)
2015-10-07 11:25 UTC, nvinson234
Details | Diff
new ebuild version based on IRC discussion (nftable-0.5-r1.ebuild.patch,1.44 KB, patch)
2015-10-15 08:30 UTC, nvinson234
Details | Diff
and the new init script. (nftables.init-r1.patch,6.85 KB, patch)
2015-10-15 08:30 UTC, nvinson234
Details | Diff
git format patch output (0001-Fix-for-bug-560920.patch,8.79 KB, patch)
2015-10-15 08:45 UTC, Göktürk Yüksek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description diamond 2015-09-20 15:55:55 UTC
I can't either stop or start nftables because it's initscript has buggy save part. It should probably be rewritten, all tables may be listed using "nft list ruleset" command since Linux Kernel 3.18:
http://wiki.nftables.org/wiki-nftables/index.php/Operations_at_ruleset_level
The same keyword may be used for flushing.
Example of error message:
# rc-service nftables stop
nftables                 | * Saving nftables state ...
nftables                 |<cmdline>:1:15-16: Error: syntax error, unexpected ip, expecting string
nftables                 |list table ip ip filter
nftables                 |              ^^
nftables                 |<cmdline>:1:15-16: Error: syntax error, unexpected ip, expecting string
nftables                 |list table ip ip nat
nftables                 |              ^^
nftables                 |<cmdline>:1:16-17: Error: syntax error, unexpected ip, expecting string
nftables                 |list table arp ip filter
nftables                 |               ^^
nftables                 |<cmdline>:1:16-17: Error: syntax error, unexpected ip, expecting string
nftables                 |list table arp ip nat
nftables                 |               ^^
nftables                 |<cmdline>:1:16-17: Error: syntax error, unexpected ip, expecting string
nftables                 |list table ip6 ip filter
nftables                 |               ^^
nftables                 |<cmdline>:1:16-17: Error: syntax error, unexpected ip, expecting string
nftables                 |list table ip6 ip nat
nftables                 |               ^^
nftables                 |<cmdline>:1:19-20: Error: syntax error, unexpected ip, expecting string
nftables                 |list table bridge ip filter
...
Comment 1 nvinson234 2015-09-20 18:28:24 UTC
Created attachment 412362 [details, diff]
nftables init script patch for version 0.5

It's because the behavior of nft list tables <family> and nft list tables changed.  They both act the same now and return a list of tables in table <family> <identifier> format.

This patch should fix the issue.
Comment 2 nvinson234 2015-09-20 18:37:47 UTC
(In reply to diamond from comment #0)
> I can't either stop or start nftables because it's initscript has buggy save
> part. It should probably be rewritten, all tables may be listed using "nft
> list ruleset" command since Linux Kernel 3.18:
> http://wiki.nftables.org/wiki-nftables/index.php/Operations_at_ruleset_level

Admittedly, I didn't know about this option when I wrote the patch; however, as 3.14.48 is still in the portage tree and supports nftables, I'm choosing not to update my patch to use that command so that compatibility is maintained.
Comment 3 Vladimir Datsevich 2015-09-21 10:11:34 UTC
Is it possible to add a check to the init script, which will decide by comparing the kernel version which method to use?

Or: is it possible to add an additional use flag, which will enable/disable the method to use?
Comment 4 nvinson234 2015-09-21 22:16:15 UTC
(In reply to bgo from comment #3)
> Is it possible to add a check to the init script, which will decide by
> comparing the kernel version which method to use?
> 
> Or: is it possible to add an additional use flag, which will enable/disable
> the method to use?

I could add a kernel version check to the patch and switch to using 'nft list ruleset' for kernels 3.18 or newer.  I imagine that would be a better approach than adding a USE flag.

However, switching to 'nft list ruleset' won't fix 560206.  To fix 560206, the sed hack would have to be removed.  However, removing the sed hack now will also reintroduce the bug it was attempting to fix.  The only way to fix both of those issues is to file a case upstream and have it fixed there.  If no one else files the issue, I'll try to do it later today or tomorrow.
Comment 5 diamond 2015-09-22 21:38:59 UTC
We can also check kernel version in ebuild and install different script versions depending on it. There are also some recommendations on atomic update there which may be useful:
https://lists.netfilter.org/pipermail/netfilter-announce/2015/000216.html

Wasn't bug #560206 fixed in that paticular version of nftables?
Comment 6 nvinson234 2015-09-22 22:40:01 UTC
(In reply to diamond from comment #5)
> We can also check kernel version in ebuild and install different script

Assuming I get a vote, I would like to vote for this idea.  If I have the time, I'll submit patches to the ebuild to allow it to choose between init scripts.

> versions depending on it. There are also some recommendations on atomic
> update there which may be useful:
> https://lists.netfilter.org/pipermail/netfilter-announce/2015/000216.html

I'm not sure I follow here.  Granted the script does not support atomic updates (mainly because the iptables script doesn't), but it does already use 'nft -f' in start() to restore the firewall.

> 
> Wasn't bug #560206 fixed in that paticular version of nftables?

Bug #560206 is actually my fault, as I'm the one who wrote the sed substitution (and the explanation for it) into the init script in the first place (see bug #508182 ).  At the time, I forgot to file a bug upstream to get the underlying issue fixed.  I have remedied that by filing the bug yesterday (http://bugzilla.netfilter.org/show_bug.cgi?id=1032).  Once that issue is fixed, the sed substitution shouldn't be needed anymore from that point forward.
Comment 7 nvinson234 2015-09-26 17:30:06 UTC
Created attachment 412986 [details]
Updated init script for users of kernels older then 3.18
Comment 8 nvinson234 2015-09-26 17:31:08 UTC
Created attachment 412988 [details]
Updated init script for users of kernel versions 3.18 or newer
Comment 9 nvinson234 2015-09-26 17:31:31 UTC
Created attachment 412990 [details]
Updated ebuild
Comment 10 nvinson234 2015-09-26 17:35:40 UTC
I've added a new set of init scripts and an updated ebuild that reflect the recommendations made in comments #1 and #5.  I also removed the calls to sed as that will likely fix issue #560206.  I don't think many people will hit the scenario that substitution is trying to fix.  However, if I'm wrong, an upstream bug report has already been filed.  The URL is http://bugzilla.netfilter.org/show_bug.cgi?id=1032 .
Comment 11 diamond 2015-09-27 07:37:21 UTC
Thank you. I've just checked your ebuild and new initscript. They are working fine for me. I think that your old initscript should work too (I've already checked it's old version before, it was ok too). I think it can be merged into portage tree.
Comment 12 Manuel Rüger (RETIRED) gentoo-dev 2015-10-06 13:31:44 UTC
Thanks for your help and contribution.

I'd rather see the change included in the init-script instead of making a hard decision during install time. A user might switch the kernel back or forward to another version later.
Comment 13 nvinson234 2015-10-07 01:05:17 UTC
(In reply to Manuel Rüger from comment #12)
> Thanks for your help and contribution.
> 
> I'd rather see the change included in the init-script instead of making a
> hard decision during install time. A user might switch the kernel back or
> forward to another version later.

I moved the change into the init script.  It makes it a bit more complicated, but I'm hoping I've got it organized in a way that the extra logic can be removed when it's no longer needed.

I also liked the nft -f approach to the panic() command over what I had previously done, so I chose to backport that to version 0.4 instead of using the original logic.
Comment 14 nvinson234 2015-10-07 01:10:02 UTC
Created attachment 413944 [details, diff]
nftables-0.5 ebuild panic() patch

This patch installs rules-panic into /var/lib/nftables.  rules-panic is a predefined rule set that is used in conjunction with /etc/init.d/nftables panic command to stop the nftables service and configure nftables to drop all packets.
Comment 15 nvinson234 2015-10-07 01:11:39 UTC
Created attachment 413946 [details, diff]
nftables-0.4 ebuild panic() patch

Same as the nftables-0.5 ebuild panic() patch, but for nftables-0.4.ebuild.
Comment 16 nvinson234 2015-10-07 01:13:03 UTC
Created attachment 413948 [details]
Revised nftables init script
Comment 17 nvinson234 2015-10-07 01:14:38 UTC
Created attachment 413950 [details]
the panic nftables ruleset

I'm not completely sure that /var/lib/nftables is the right place for this file, but I can't think of a better place to put it.
Comment 18 nvinson234 2015-10-07 11:16:26 UTC
Created attachment 413972 [details]
IPv4 panic nftables ruleset

I'm guessing there's someone who doesn't use a dual stack IP setup.  I've adjusted the scripts to handle that case.  Unfortunately, this meant breaking the panic ruleset file into two.  This is the IPv4 half.
Comment 19 nvinson234 2015-10-07 11:17:40 UTC
Created attachment 413974 [details]
IPv6 panic nftables ruleset

The IPv6 half of the panic ruleset
Comment 20 nvinson234 2015-10-07 11:21:34 UTC
Created attachment 413976 [details]
Revised nftables init script

I had to rewrite getfamilies() as the original function did not work as intended with 0.4 (nft always exits with status 0 when listing tables).
Comment 21 nvinson234 2015-10-07 11:24:27 UTC
Created attachment 413978 [details, diff]
nftables-0.4. ebuild panic() patch

updated for non-Dual Stack setups.
Comment 22 nvinson234 2015-10-07 11:25:58 UTC
Created attachment 413980 [details, diff]
nftables-0.5 ebuild panic() patch

updated for non-Dual Stack setups, and I think this fixes everything.  Sorry for the extra noise.  I'll be more rigorous in my testing in the future.
Comment 23 Manuel Rüger (RETIRED) gentoo-dev 2015-10-07 15:01:10 UTC
Thanks for your contribution, nvinson.
Are you interested in proxy maintaining nftables? [1]

[1] https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers
Comment 24 nvinson234 2015-10-08 23:40:38 UTC
(In reply to Manuel Rüger from comment #23)
> Thanks for your contribution, nvinson.
> Are you interested in proxy maintaining nftables? [1]
> 
> [1] https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers

I'll be happy to pick it up.  I would, however, would prefer to use a different email address than the one I've been using here.

Thanks.
Comment 25 Ian Delaney (RETIRED) gentoo-dev 2015-10-15 04:52:42 UTC
(In reply to nvinson from comment #24)
> (In reply to Manuel Rüger from comment #23)
> > Thanks for your contribution, nvinson.
> > Are you interested in proxy maintaining nftables? [1]
> > 
> > [1] https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers
> 
> I'll be happy to pick it up.  I would, however, would prefer to use a
> different email address than the one I've been using here.
> 
> Thanks.

done. Nicholas I will add you as maintainer when this reaches completion. My reading of it is it's not there yet.
Comment 26 nvinson234 2015-10-15 08:30:31 UTC
Created attachment 414588 [details, diff]
new ebuild version based on IRC discussion

obsoletes the 0.4 version because that version has been removed from the tree.
Comment 27 nvinson234 2015-10-15 08:30:59 UTC
Created attachment 414590 [details, diff]
and the new init script.
Comment 28 Göktürk Yüksek archtester gentoo-dev 2015-10-15 08:45:08 UTC
Created attachment 414592 [details, diff]
git format patch output
Comment 29 Ian Delaney (RETIRED) gentoo-dev 2015-10-15 09:07:24 UTC
commit 322474a9c7cb65b6ebd39d8efd8526f19c38f90b
Author: Ian Delaney <idella4@gentoo.org>
Date:   Thu Oct 15 17:05:28 2015 +0800

    net-firewall/nftables: revbump and patch to fix broken init script
    
    patches submitted by Nicholas Vinson via gentoo bug, set in metadata
    as new proxy maintainer by invitation by developer maintainer mreug,
    thanks to gokturk for assistance and cross testing
    
    Gentoo bug: #560920