From 4911da56e1f1a10843a23e16a80755051f04e94b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@c0d3.blue>
Date: Sun, 26 Nov 2017 22:40:02 +0100
Subject: [PATCH] gluon-ebtables: Enable concurrent ebtables updates
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This enables the ebtables internal locking mechanism which
will avoid race conditions between multiple, concurrent
ebtables calls.

This is a preparation for the upcoming gluon-arp-limiter
daemon, to avoid issues if upon restarting gluon-ebtables
the gluon-arp-limiter daemon tries to modify the tables.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 .../gluon-ebtables/files/etc/init.d/gluon-ebtables   | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/package/gluon-ebtables/files/etc/init.d/gluon-ebtables b/package/gluon-ebtables/files/etc/init.d/gluon-ebtables
index e6bffe965..40c9e061c 100755
--- a/package/gluon-ebtables/files/etc/init.d/gluon-ebtables
+++ b/package/gluon-ebtables/files/etc/init.d/gluon-ebtables
@@ -51,8 +51,12 @@ exec_all() {
 
 start() {
 	(
-		export EBTABLES_RULE='"ebtables -t " .. table .. " -A " .. command'
-		export EBTABLES_CHAIN='"ebtables -t " .. table .. "  -N " .. name .. " -P " .. policy'
+		export EBTABLES_RULE='"ebtables --concurrent -t " .. table .. " -A " .. command'
+		export EBTABLES_CHAIN='"ebtables --concurrent -t " .. table .. "  -N " .. name .. " -P " .. policy'
+
+		# Contains /var/lib/ebtables/lock for '--concurrent'
+		[ ! -d "/var/lib/ebtables" ] && \
+			mkdir -p /var/lib/ebtables
 
 		if [ -z "$1" ]; then
 			exec_all ''
@@ -64,8 +68,8 @@ start() {
 
 stop() {
 	(
-		export EBTABLES_RULE='"ebtables -t " ..	table .. " -D " .. command'
-		export EBTABLES_CHAIN='"ebtables -t " .. table .. " -X " .. name'
+		export EBTABLES_RULE='"ebtables --concurrent -t " ..	table .. " -D " .. command'
+		export EBTABLES_CHAIN='"ebtables --concurrent -t " .. table .. " -X " .. name'
 
 		if [ -z "$1" ]; then
 			exec_all '-r'
-- 
GitLab