Skip to content

Commit d65b118

Browse files
author
AdrianBan
committed
First release
1 parent acdca44 commit d65b118

27 files changed

+535
-0
lines changed

Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/make -f
2+
3+
# This file is part of nftables-persistent
4+
# Copyright (C) 2019 Adrian Ban
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License
8+
# as published by the Free Software Foundation, either version 3
9+
# of the License, or (at your option) any later version.
10+
11+
PREFIX=/
12+
DEST=$(DESTDIR)$(PREFIX)
13+
14+
all:
15+
16+
clean:
17+
18+
install:
19+
install -d $(DEST)/usr/sbin
20+
install -d $(DEST)/usr/share/nftables-persistent
21+
install -d $(DEST)/usr/share/nftables-persistent/plugins.d
22+
# Main wrapper
23+
install nftables-persistent $(DEST)/usr/sbin
24+
# Systemd
25+
install -d $(DEST)/lib/systemd/system
26+
install --mode=644 systemd/* $(DEST)/lib/systemd/system
27+
# Manual
28+
install -d $(DEST)/usr/share/man/man8
29+
install --mode=644 nftables-persistent.8 $(DEST)/usr/share/man/man8
30+
31+
install-plugins:
32+
# Plugins
33+
install plugins/* $(DEST)/usr/share/nftables-persistent/plugins.d

debian/README

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
nftables-persistent and its plugins
2+
------------------------------------
3+
4+
nftables-persistent is used to load and save filter rules.
5+
This tool cames with a nft plugin.
6+
7+
Commands are run from nftables-persistent. For example, to save
8+
all filter rules:
9+
10+
nftables-persistent save
11+
12+
or to load them:
13+
14+
nftables-persistent start
15+
16+
For more details, see `man nftables-persistent`.
17+
18+
The system service will try to load rules at startup if enabled, but by
19+
default it will not flush rules at shutdown. This behaviour can be changed
20+
by editing /etc/default/nftables-persistent.
21+
22+
-- Adrian Ban <devel@abtelecom.ro> Tue, 16 Oct 2019 11:11:00 +0100

debian/README.source

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
nftables-persistent has become a native package (meaning there is no
3+
upstream tarball). In its present form, nftables-persistent is unlikely
4+
to be useful outside Debian or Debian-derivatives, and I do not plan to
5+
include any support for other distributions, so a native package makes the
6+
maintenance overhead considerably smaller.
7+
8+
-- Adrian Ban <devel@abtelecom.ro> Tue, 16 Oct 2019 16:38:17 +0200

debian/changelog

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
nftables-persistent (0.1.0) unstable; urgency=medium
2+
3+
* First release of nftables-persistent
4+
* Based on netfilter-persistent
5+
6+
-- Adrian Ban <devel@abtelecom.ro> Tue, 16 Oct 2019 16:12:28 +0200
7+

debian/compat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

debian/control

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Source: nftables-persistent
2+
Section: admin
3+
Priority: optional
4+
Maintainer: Adrian Ban <devel@abtelecom.ro>
5+
Build-Depends: debhelper (>= 7.0.50~), dh-systemd, po-debconf
6+
Standards-Version: 3.9.6
7+
Vcs-Browser: https://github.com/AdrianBan/nftables-persistent
8+
Vcs-Git: https://github.com/AdrianBan/nftables-persistent
9+
10+
Package: nftables-persistent
11+
Architecture: all
12+
Depends: lsb-base, ${misc:Depends}
13+
Breaks: iptables-persistent, netfilter-persistent, ipset-persistent
14+
Replaces: iptables-persistent, netfilter-persistent, ipset-persistent
15+
Pre-Depends: ${misc:Pre-Depends}
16+
Description: boot-time loader for nftables configuration
17+
This package provides a loader for nftables configuration using a
18+
plugin-based architecture. It can load, flush and save a running
19+
configuration. Extending nftables-persistent with plugins is trivial and can
20+
be done in any language.
21+

debian/copyright

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: nftables-persistent
3+
Upstream-Contact: Adrian Ban <devel@abtelecom.ro>
4+
5+
Files: *
6+
Copyright: © 2018, Adrian Ban <devel@abtelecom.ro>
7+
License: GPL-3
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
.
13+
This package is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
.
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
.
21+
On Debian systems, the complete text of the GNU General
22+
Public License version 3 can be found in `/usr/share/common-licenses/GPL-3'.

debian/gbp.conf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[DEFAULT]
2+
compression = bzip2
3+
debian-branch=debian
4+
5+
[dch]
6+
meta = true
7+
id-length = 6

debian/nftables-persistent.config

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Source debconf library
6+
. /usr/share/debconf/confmodule
7+
8+
db_get nft-persistent/autosave_done || true
9+
if [ "x$RET" != "xtrue" ]; then
10+
# Save nft rules?
11+
db_input high nft-persistent/autosave || true
12+
db_go
13+
fi

debian/nftables-persistent.default

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration for netfilter-persistent
2+
# Plugins may extend this file or have their own
3+
4+
FLUSH_ON_STOP=1
5+

debian/nftables-persistent.dirs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
etc/nftables
2+
usr/share/nftables-persistent/plugins.d

debian/nftables-persistent.docs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debian/README

debian/nftables-persistent.init

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
# This file is part of netfilter-persistent
4+
# Copyright (C) 2019 Adrian Ban
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License
8+
# as published by the Free Software Foundation, either version 3
9+
# of the License, or (at your option) any later version.
10+
11+
### BEGIN INIT INFO
12+
# Provides: netfilter-persistent
13+
# Required-Start: mountkernfs $remote_fs
14+
# Required-Stop: $remote_fs
15+
# Default-Start: S
16+
# Default-Stop: 0 1 6
17+
# Short-Description: Load boot-time netfilter configuration
18+
# Description: Loads boot-time netfilter configuration
19+
### END INIT INFO
20+
21+
. /lib/lsb/init-functions
22+
23+
case "$1" in
24+
start|restart|reload|force-reload)
25+
log_action_begin_msg "Loading nftables rules"
26+
/usr/sbin/nftables-persistent start
27+
log_action_end_msg $?
28+
;;
29+
save)
30+
log_action_begin_msg "Saving nftables rules"
31+
/usr/sbin/nftables-persistent save
32+
log_action_end_msg $?
33+
;;
34+
stop)
35+
log_action_begin_msg "Stopping nftables rules"
36+
/usr/sbin/nftables-persistent stop
37+
log_action_end_msg $?
38+
;;
39+
flush)
40+
log_action_begin_msg "Flushing nftables rules"
41+
/usr/sbin/nftables-persistent flush
42+
log_action_end_msg $?
43+
;;
44+
*)
45+
echo "Usage: $0 {start|restart|reload|force-reload|save|flush}" >&2
46+
exit 1
47+
;;
48+
esac
49+
50+
exit $rc

debian/nftables-persistent.install

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
plugins/15-nftables usr/share/nftables-persistent/plugins.d/
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm_conffile /etc/init.d/nftables-persistent 1~

debian/nftables-persistent.postinst

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Source debconf library
6+
. /usr/share/debconf/confmodule
7+
8+
case "$1" in
9+
configure)
10+
db_get nftables-persistent/autosave_done || true
11+
if [ "x$RET" != "xtrue" ]; then
12+
db_get nftables-persistent/autosave || true
13+
if [ "x$RET" = "xtrue" ]; then
14+
if which nft > /dev/null ; then
15+
if nft list ruleset > /dev/null; then
16+
nft list ruleset > /etc/nftables/rules
17+
else
18+
echo "NFTables: Unable to save"
19+
fi
20+
else
21+
echo "NFTables: Can't find nftables in $PATH, please check your system"
22+
fi
23+
fi
24+
25+
db_set nftables-persistent/autosave_done true || true
26+
fi
27+
28+
update-rc.d nftables-persistent remove
29+
;;
30+
esac
31+
32+
#DEBHELPER#

debian/nftables-persistent.postrm

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
case "$1" in
6+
purge)
7+
rm -rf /etc/nftables/rules
8+
;;
9+
esac
10+
11+
#DEBHELPER#

debian/nftables-persistent.templates

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# These templates have been reviewed by the debian-l10n-english
2+
# team
3+
#
4+
# If modifications/additions/rewording are needed, please ask
5+
# debian-l10n-english@lists.debian.org for advice.
6+
#
7+
# Even minor modifications require translation updates and such
8+
# changes should be coordinated with translators and reviewers.
9+
10+
Template: nftables-persistent/autosave
11+
Type: boolean
12+
Default: true
13+
_Description: Save current NFTables rules?
14+
Current nftables rules can be saved to the configuration
15+
file /etc/nftables/rules. These rules will then be loaded automatically
16+
during system startup.
17+
.
18+
Rules are only saved automatically during package installation. See the
19+
manual page of nft(8) for instructions on keeping the rules file
20+
up-to-date.
21+

debian/nftables.override

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Unit]
2+
Conflicts=iptables.service ip6tables.service ipset.service netfilter-persistent.service

debian/po/POTFILES.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[type: gettext/rfc822deb] iptables-persistent.templates

debian/po/templates.pot

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PACKAGE VERSION\n"
10+
"POT-Creation-Date: 2019-10-16 16:59+0200\n"
11+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Language-Team: LANGUAGE <LL@li.org>\n"
14+
"Language: \n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=CHARSET\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
19+
#. Type: boolean
20+
#. Description
21+
#: ../nftables-persistent.templates:2001
22+
msgid "Save current NFTables rules?"
23+
msgstr ""
24+
25+
#. Type: boolean
26+
#. Description
27+
#: ../nftables-persistent.templates:2001
28+
msgid ""
29+
"Current nftables rules can be saved to the configuration file /etc/nftables/"
30+
"rules. These rules will then be loaded automatically during system "
31+
"startup."
32+
msgstr ""
33+
34+
#. Type: boolean
35+
#. Description
36+
#: ../nftables-persistent.templates:2001
37+
msgid ""
38+
"Rules are only saved automatically during package installation. See the "
39+
"manual page of nft(8) for instructions on keeping the rules file "
40+
"up-to-date."
41+
msgstr ""
42+

debian/rules

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/make -f
2+
3+
override_dh_installinit:
4+
dh_installinit -- start 37 S . stop 37 0 1 6 .
5+
6+
%:
7+
dh $@ --with systemd

debian/source/format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0 (native)

nftables-persistent

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
# This file is part of nftables-persistent based on iptables-persistent
4+
# Copyright (C) 2019 Adrian Ban
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License
8+
# as published by the Free Software Foundation, either version 3
9+
# of the License, or (at your option) any later version.
10+
11+
set -e
12+
13+
IAM=$(whoami)
14+
PLUGINS=/usr/share/nftables-persistent/plugins.d
15+
16+
if [ ${IAM} != "root" ]; then
17+
echo "You must be root to use this utility"
18+
fi
19+
20+
# Source configuration
21+
if [ -f "/etc/default/nftables-persistent" ]; then
22+
. /etc/default/nftables-persistent
23+
fi
24+
25+
run_plugins () {
26+
if [ -d ${PLUGINS} ]; then
27+
run-parts -v -a ${1} ${PLUGINS}
28+
fi
29+
}
30+
31+
case $1 in
32+
start|save|flush)
33+
run_plugins ${1}
34+
;;
35+
reload|restart)
36+
run_plugins flush
37+
run_plugins start
38+
;;
39+
stop)
40+
if [ ${FLUSH_ON_STOP} -gt 0 ]; then
41+
run_plugins flush
42+
else
43+
echo "Automatic flush disabled; use '${0} flush'"
44+
fi
45+
;;
46+
*)
47+
echo "Usage: ${0} (start|stop|restart|reload|flush|save)"
48+
;;
49+
esac
50+
51+
52+
exit 0
53+

0 commit comments

Comments
 (0)