* [Buildroot] [git commit] package/iptables: add init script
@ 2021-09-22 21:27 Arnout Vandecappelle
0 siblings, 0 replies; only message in thread
From: Arnout Vandecappelle @ 2021-09-22 21:27 UTC (permalink / raw)
To: buildroot
[-- Attachment #1: Type: text/plain, Size: 2261 bytes --]
commit: https://git.buildroot.net/buildroot/commit/?id=4906e77d5957a78df3181a0c8a1b5f0e55ce44da
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master
This patch will add an init script that allows
to set a ruleset in /etc/iptables.conf to be loaded
on boot, or flushed on stop, as well as a saving
command to generate a new file.
Signed-off-by: José Pekkarinen <jose.pekkarinen@unikie.com>
[Arnout: change handling of readonly filesystem]
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
package/iptables/S35iptables | 58 ++++++++++++++++++++++++++++++++++++++++++++
package/iptables/iptables.mk | 6 +++++
2 files changed, 64 insertions(+)
diff --git a/package/iptables/S35iptables b/package/iptables/S35iptables
new file mode 100644
index 0000000000..ff3f51a2ba
--- /dev/null
+++ b/package/iptables/S35iptables
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+DAEMON="iptables"
+
+IPTABLES_ARGS=""
+
+start() {
+ printf 'Starting %s: ' "$DAEMON"
+ iptables-restore < /etc/iptables.conf
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ return "$status"
+}
+
+stop() {
+ printf 'Stopping %s: ' "$DAEMON"
+ iptables -F
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ return "$status"
+}
+
+restart() {
+ stop
+ sleep 1
+ start
+}
+
+save() {
+ printf 'Saving %s: ' "$DAEMON"
+ iptables-save > /etc/iptables.conf
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "OK"
+ else
+ echo "SKIP (read-only file system detected)"
+ fi
+ return "$status"
+}
+
+case "$1" in
+ start|stop|restart|save)
+ "$1";;
+ reload)
+ # Restart, since there is no true "reload" feature.
+ restart;;
+ *)
+ echo "Usage: $0 {start|stop|restart|reload}"
+ exit 1
+esac
diff --git a/package/iptables/iptables.mk b/package/iptables/iptables.mk
index ca8178425e..555bb384fd 100644
--- a/package/iptables/iptables.mk
+++ b/package/iptables/iptables.mk
@@ -57,4 +57,10 @@ define IPTABLES_LINUX_CONFIG_FIXUPS
$(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES)
endef
+define IPTABLES_INSTALL_INIT_SYSV
+ $(INSTALL) -m 0755 -D package/iptables/S35iptables \
+ $(TARGET_DIR)/etc/init.d/S35iptables
+ touch $(TARGET_DIR)/etc/iptables.conf
+endef
+
$(eval $(autotools-package))
[-- Attachment #2: Type: text/plain, Size: 156 bytes --]
_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-23 7:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 21:27 [Buildroot] [git commit] package/iptables: add init script Arnout Vandecappelle
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).