diff --git a/src/packages/fff/fff-babeld/files/etc/gateway.d/40-babel b/src/packages/fff/fff-babeld/files/etc/gateway.d/40-babel
index cc1cf5d..4c94a12 100644
--- a/src/packages/fff/fff-babeld/files/etc/gateway.d/40-babel
+++ b/src/packages/fff/fff-babeld/files/etc/gateway.d/40-babel
@@ -1,4 +1,5 @@
 . /lib/functions.sh
+. /lib/functions/fff/babel
 
 #load board specific properties
 BOARD="$(uci get board.model.name)"
@@ -14,10 +15,9 @@ configure() {
 				# remove interface
 				uci -q del network.$name
 				# remove iif-rules
-				uci -q del network.${name}_rule
-				uci -q del network.${name}_rule6
+				babel_delete_iifrules "$name" || exit 1
 				# remove babel interface
-				uci -q del babeld.$name
+				babel_delete_interface "$name" || exit 1
 			fi
 		fi
 	}
@@ -67,37 +67,16 @@ configure() {
 		uci set network.$name.ifname=$iface
 
 		# add iif-rules
-		uci set network.${name}_rule=rule
-		uci set network.${name}_rule.in="$name"
-		uci set network.${name}_rule.lookup='10'
-		uci set network.${name}_rule.priority='31'
-
-		uci set network.${name}_rule6=rule6
-		uci set network.${name}_rule6.in="$name"
-		uci set network.${name}_rule6.lookup='10'
-		uci set network.${name}_rule6.priority='31'
+		babel_add_iifrules "$name" || exit 1
 
 		# peer_ip
-		if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then
-			uci set network.$name.ipaddr="$peer_ip"
-		elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
-			# use ipaddr (without subnet) if no peer_ip set
-			uci set network.$name.ipaddr=$(echo $ipaddr | cut -d / -f1)
-		else
-			echo "FATAL: Neither peer_ip nor ipaddr set! No peering ipv4 set!"
-			exit 1
-		fi
-
-		# peer_ip6
-		if peer_ip6=$(uci -q get gateway.@gateway[0].peer_ip6); then
-			uci set network.$name.ip6addr="$peer_ip6"
-		fi
+		uci -q delete "network.$name.ipaddr"
+		uci -q delete "network.$name.ip6addr"
+		babel_add_peeraddr "network.$name.ipaddr" || exit 1
+		babel_add_peer6addr "network.$name.ip6addr" || exit 1
 
 		# add babel interface
-		uci set babeld.$name=interface
-		uci set babeld.$name.ifname=$iface
-		uci set babeld.$name.type=$type
-		uci set babeld.$name.rxcost=$rxcost
+		babel_add_interface "$name" "$iface" "$type" "$rxcost" || exit 1
 	}
 
 	config_load gateway
diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babel b/src/packages/fff/fff-babeld/files/lib/functions/fff/babel
new file mode 100644
index 0000000..3789741
--- /dev/null
+++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babel
@@ -0,0 +1,74 @@
+babel_add_iifrules() {
+	[ "$#" -ne "1" ] && return 1
+
+	local name="$1"
+	local table='10'
+	local prio='31'
+
+	uci set network.${name}_rule=rule
+	uci set network.${name}_rule.in="$name"
+	uci set network.${name}_rule.lookup="$table"
+	uci set network.${name}_rule.priority="$prio"
+
+	uci set network.${name}_rule6=rule6
+	uci set network.${name}_rule6.in="$name"
+	uci set network.${name}_rule6.lookup="$table"
+	uci set network.${name}_rule6.priority="$prio"
+}
+
+babel_delete_iifrules() {
+	[ "$#" -ne "1" ] && return 1
+
+	local name="$1"
+
+	uci -q del network.${name}_rule
+	uci -q del network.${name}_rule6
+}
+
+babel_add_peeraddr() {
+	[ "$#" -ne "1" ] && return 1
+
+	local option="$1"
+
+	if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then
+		uci add_list "$option"="$peer_ip"
+	elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
+		# use ipaddr (without subnet) if no peer_ip set
+		uci add_list "$option"=$(echo $ipaddr | cut -d / -f1)
+	else
+		echo "FATAL: Neither peer_ip nor ipaddr set! No peering ipv4 set!"
+		return 1
+	fi
+}
+
+babel_add_peer6addr() {
+	[ "$#" -ne "1" ] && return 1
+
+	local option="$1"
+
+	if peer_ip6=$(uci -q get gateway.@gateway[0].peer_ip6); then
+		uci add_list "$option"="$peer_ip6"
+	fi
+}
+
+babel_add_interface() {
+	[ "$#" -ne "4" ] && return 1
+
+	local name="$1"
+	local interface="$2"
+	local type="$3"
+	local rxcost="$4"
+
+	uci set babeld.$name=interface
+	uci set babeld.$name.ifname="$interface"
+	uci set babeld.$name.type="$type"
+	uci set babeld.$name.rxcost="$rxcost"
+}
+
+babel_delete_interface() {
+	[ "$#" -ne "1" ] && return 1
+
+	local name="$1"
+
+	uci -q del babeld.$name
+}
