All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: "José Pekkarinen" <jose.pekkarinen@unikie.com>
Cc: buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH v2] package/iptables: add init script
Date: Tue, 14 Sep 2021 19:20:19 +0300	[thread overview]
Message-ID: <87ee9rgm9e.fsf@tarshish> (raw)
In-Reply-To: <20210914132139.3597322-1-jose.pekkarinen@unikie.com>

Hi José,

On Tue, Sep 14 2021, José Pekkarinen wrote:
> 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>
> ---
> [v1 -> v2] s/touch $(DESTDIR)/touch $(TARGET_DIR)/
>
>  package/iptables/S41iptables | 58 ++++++++++++++++++++++++++++++++++++
>  package/iptables/iptables.mk |  6 ++++
>  2 files changed, 64 insertions(+)
>  create mode 100644 package/iptables/S41iptables
>
> diff --git a/package/iptables/S41iptables b/package/iptables/S41iptables
> new file mode 100644
> index 0000000000..93998b78de
> --- /dev/null
> +++ b/package/iptables/S41iptables
> @@ -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

What about read-only rootfs?

baruch

> +	status=$?
> +	if [ "$status" -eq 0 ]; then
> +		echo "OK"
> +	else
> +		echo "FAIL"
> +	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 dc01466607..1d3612dbf6 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/S41iptables \
> +		$(TARGET_DIR)/etc/init.d/S41iptables
> +	touch $(TARGET_DIR)/etc/iptables.conf
> +endef
> +
>  $(eval $(autotools-package))


-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2021-09-14 16:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 13:21 [Buildroot] [PATCH v2] package/iptables: add init script José Pekkarinen
2021-09-14 16:20 ` Baruch Siach [this message]
2021-09-15  9:14   ` José Pekkarinen
2021-09-15 10:05     ` Baruch Siach via buildroot
2021-09-15 11:41       ` José Pekkarinen
2021-09-15 12:11         ` Bartosz Biłas
2021-09-15 12:20           ` José Pekkarinen

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=87ee9rgm9e.fsf@tarshish \
    --to=baruch@tkos.co.il \
    --cc=buildroot@buildroot.org \
    --cc=jose.pekkarinen@unikie.com \
    /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.