[PATCH 2/2] ipip6/ds-lite: Integrate ds-lite and ipip6 ds-lite and ipip6 now use the same backend ipip6.sh

ms at missing233.com ms at missing233.com
Fri Feb 2 22:13:00 PST 2024


From: Arayuki Mago <ms at missing233.com>

Signed-off-by: Arayuki Mago <ms at missing233.com>
---
 package/network/ipv6/ds-lite/Makefile         |  2 +-
 .../ds-lite/files/{dslite.sh => ipip6.sh}     | 72 +++++++++++++------
 package/network/ipv6/ipip6/Makefile           | 13 ++--
 package/network/ipv6/ipip6/files/ipip6.sh     | 68 +++++++++++++-----
 4 files changed, 109 insertions(+), 46 deletions(-)
 rename package/network/ipv6/ds-lite/files/{dslite.sh => ipip6.sh} (67%)

diff --git a/package/network/ipv6/ds-lite/Makefile b/package/network/ipv6/ds-lite/Makefile
index 502da366a9..a6ea315c88 100644
--- a/package/network/ipv6/ds-lite/Makefile
+++ b/package/network/ipv6/ds-lite/Makefile
@@ -36,7 +36,7 @@ endef
 
 define Package/ds-lite/install
 	$(INSTALL_DIR) $(1)/lib/netifd/proto
-	$(INSTALL_BIN) ./files/dslite.sh $(1)/lib/netifd/proto/dslite.sh
+	$(INSTALL_BIN) ./files/ipip6.sh $(1)/lib/netifd/proto/ipip6.sh
 endef
 
 $(eval $(call BuildPackage,ds-lite))
diff --git a/package/network/ipv6/ds-lite/files/dslite.sh b/package/network/ipv6/ds-lite/files/ipip6.sh
similarity index 67%
rename from package/network/ipv6/ds-lite/files/dslite.sh
rename to package/network/ipv6/ds-lite/files/ipip6.sh
index 017963926d..5c2755df76 100644
--- a/package/network/ipv6/ds-lite/files/dslite.sh
+++ b/package/network/ipv6/ds-lite/files/ipip6.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# dslite.sh - IPv4-in-IPv6 tunnel backend
+# ipip6.sh - IPv4-in-IPv6 tunnel backend for ipip6 and ds-lite
 # Copyright (c) 2013 OpenWrt.org
 
 [ -n "$INCLUDE_ONLY" ] || {
@@ -9,10 +9,13 @@
 	init_proto "$@"
 }
 
-proto_dslite_setup() {
+tnl_setup() {
 	local cfg="$1"
 	local iface="$2"
-	local link="ds-$cfg"
+	local tnl_type="$3"
+	local ip4addr="$4"
+	local ip4gateway="$5"
+	local link="$tnl_type-$cfg"
 	local remoteip6
 
 	local mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
@@ -24,7 +27,7 @@ proto_dslite_setup() {
 		return
 	}
 
-	( proto_add_host_dependency "$cfg" "::" "$tunlink" )
+	proto_add_host_dependency "$cfg" "::" "$tunlink"
 
 	remoteip6=$(resolveip -6 "$peeraddr")
 	if [ -z "$remoteip6" ]; then
@@ -36,10 +39,7 @@ proto_dslite_setup() {
 		fi
 	fi
 
-	for ip6 in $remoteip6; do
-		peeraddr=$ip6
-		break
-	done
+	peeraddr=$(echo "$remoteip6" | head -n 1)
 
 	[ -z "$ip6addr" ] && {
 		local wanif="$tunlink"
@@ -59,7 +59,7 @@ proto_dslite_setup() {
 
 	proto_init_update "$link" 1
 	proto_add_ipv4_route "0.0.0.0" 0
-	proto_add_ipv4_address "192.0.0.2" "" "" "192.0.0.1"
+	proto_add_ipv4_address "$ip4addr" "" "" "$ip4gateway"
 
 	proto_add_tunnel
 	json_add_string mode ipip6
@@ -76,23 +76,22 @@ proto_dslite_setup() {
 	proto_add_data
 	[ -n "$zone" ] && json_add_string zone "$zone"
 
-	json_add_array firewall
-	  json_add_object ""
-	    json_add_string type nat
-	    json_add_string target ACCEPT
-	  json_close_object
-	json_close_array
+	if [ "$tnl_type" = "ds" ]; then
+        json_add_array firewall
+            json_add_object ""
+                json_add_string type nat
+                json_add_string target ACCEPT
+            json_close_object
+        json_close_array
+    fi
+
 	proto_close_data
 
 	proto_send_update "$cfg"
 }
 
-proto_dslite_teardown() {
-	local cfg="$1"
-}
-
-proto_dslite_init_config() {
-	no_device=1             
+init_config() {
+	no_device=1
 	available=1
 
 	proto_config_add_string "ip6addr"
@@ -105,6 +104,35 @@ proto_dslite_init_config() {
 	proto_config_add_string "weakif"
 }
 
+proto_ipip6_init_config() {
+	init_config
+	proto_config_add_string "ip4ifaddr"
+}
+
+proto_ipip6_setup() {
+	local ip4ifaddr
+	json_get_vars ip4ifaddr
+	tnl_setup "$1" "$2" "ipip6" "$ip4ifaddr" "0.0.0.0"
+}
+
+proto_ipip6_teardown() {
+	local cfg="$1"
+}
+
+proto_dslite_init_config() {
+	init_config
+}
+
+proto_dslite_setup() {
+	tnl_setup "$1" "$2" "ds" "192.0.0.2" "192.0.0.1"
+}
+
+proto_dslite_teardown() {
+	local cfg="$1"
+}
+
 [ -n "$INCLUDE_ONLY" ] || {
-        add_protocol dslite
+
+	add_protocol ipip6;
+	add_protocol dslite;
 }
diff --git a/package/network/ipv6/ipip6/Makefile b/package/network/ipv6/ipip6/Makefile
index 034f17e0c0..32d16181b0 100644
--- a/package/network/ipv6/ipip6/Makefile
+++ b/package/network/ipv6/ipip6/Makefile
@@ -1,6 +1,7 @@
 #
 # Copyright (C) 2013 OpenWrt.org
-# Copyright (C) 2021 kenjiuno
+#
+# Original Maintainers: Steven Barth <steven at midlink.org>, kenjiuno <ku at digitaldolphins.jp>
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,10 +10,8 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ipip6
-PKG_VERSION:=0.1
 PKG_RELEASE:=6
 PKG_LICENSE:=GPL-2.0
-PKG_MAINTAINER:=kenjiuno
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -20,13 +19,15 @@ define Package/ipip6
   SECTION:=net
   CATEGORY:=Network
   DEPENDS:=@IPV6 +kmod-ip6-tunnel +resolveip
-  TITLE:=IPv4 over IPv6 (RFC2473) configuration support
-  MAINTAINER:=kenjiuno <ku at digitaldolphins.jp>
+  TITLE:=IPv4 over IPv6 (RFC2473/DS-Lite) configuration support
+  MAINTAINER:=missing233 <ms at missing233.com>
   PKGARCH:=all
 endef
 
 define Package/ipip6/description
-Provides support for IPv4 over IPv6 (RFC2473) in /etc/config/network.
+Provides support for IPv4 over IPv6 (RFC2473/DS-Lite) in /etc/config/network.
+Refer to http://wiki.openwrt.org/doc/uci/network for
+configuration details.
 endef
 
 define Build/Compile
diff --git a/package/network/ipv6/ipip6/files/ipip6.sh b/package/network/ipv6/ipip6/files/ipip6.sh
index ceadf71f67..1fcf21adf5 100644
--- a/package/network/ipv6/ipip6/files/ipip6.sh
+++ b/package/network/ipv6/ipip6/files/ipip6.sh
@@ -1,7 +1,8 @@
 #!/bin/sh
-# ipip6.sh - ipip6 tunnel(RFC2473) backend
+# ipip6.sh - IPv4-in-IPv6 tunnel backend for ipip6 and ds-lite
 # Copyright (c) 2013 OpenWrt.org
 # Copyright (c) 2021 kenjiuno
+# Copyright (c) 2024 missing233
 
 [ -n "$INCLUDE_ONLY" ] || {
 	. /lib/functions.sh
@@ -10,14 +11,17 @@
 	init_proto "$@"
 }
 
-proto_ipip6_setup() {
+tnl_setup() {
 	local cfg="$1"
 	local iface="$2"
-	local link="ipip6-$cfg"
+	local tnl_type="$3"
+	local ip4addr="$4"
+	local ip4gateway="$5"
+	local link="$tnl_type-$cfg"
 	local remoteip6
 
-	local mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit ip4ifaddr
-	json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit ip4ifaddr
+	local mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
+	json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
 
 	[ -z "$peeraddr" ] && {
 		proto_notify_error "$cfg" "MISSING_ADDRESS"
@@ -25,7 +29,7 @@ proto_ipip6_setup() {
 		return
 	}
 
-	( proto_add_host_dependency "$cfg" "::" "$tunlink" )
+	proto_add_host_dependency "$cfg" "::" "$tunlink"
 
 	remoteip6=$(resolveip -6 "$peeraddr")
 	if [ -z "$remoteip6" ]; then
@@ -37,10 +41,7 @@ proto_ipip6_setup() {
 		fi
 	fi
 
-	for ip6 in $remoteip6; do
-		peeraddr=$ip6
-		break
-	done
+	peeraddr=$(echo "$remoteip6" | head -n 1)
 
 	[ -z "$ip6addr" ] && {
 		local wanif="$tunlink"
@@ -60,7 +61,7 @@ proto_ipip6_setup() {
 
 	proto_init_update "$link" 1
 	proto_add_ipv4_route "0.0.0.0" 0
-	proto_add_ipv4_address "$ip4ifaddr" "" "" "0.0.0.0"
+	proto_add_ipv4_address "$ip4addr" "" "" "$ip4gateway"
 
 	proto_add_tunnel
 	json_add_string mode ipip6
@@ -77,16 +78,21 @@ proto_ipip6_setup() {
 	proto_add_data
 	[ -n "$zone" ] && json_add_string zone "$zone"
 
+	if [ "$tnl_type" = "ds" ]; then
+        json_add_array firewall
+            json_add_object ""
+                json_add_string type nat
+                json_add_string target ACCEPT
+            json_close_object
+        json_close_array
+    fi
+
 	proto_close_data
 
 	proto_send_update "$cfg"
 }
 
-proto_ipip6_teardown() {
-	local cfg="$1"
-}
-
-proto_ipip6_init_config() {
+init_config() {
 	no_device=1
 	available=1
 
@@ -98,9 +104,37 @@ proto_ipip6_init_config() {
 	proto_config_add_string "encaplimit"
 	proto_config_add_string "zone"
 	proto_config_add_string "weakif"
+}
+
+proto_ipip6_init_config() {
+	init_config
 	proto_config_add_string "ip4ifaddr"
 }
 
+proto_ipip6_setup() {
+	local ip4ifaddr
+	json_get_vars ip4ifaddr
+	tnl_setup "$1" "$2" "ipip6" "$ip4ifaddr" "0.0.0.0"
+}
+
+proto_ipip6_teardown() {
+	local cfg="$1"
+}
+
+proto_dslite_init_config() {
+	init_config
+}
+
+proto_dslite_setup() {
+	tnl_setup "$1" "$2" "ds" "192.0.0.2" "192.0.0.1"
+}
+
+proto_dslite_teardown() {
+	local cfg="$1"
+}
+
 [ -n "$INCLUDE_ONLY" ] || {
-	add_protocol ipip6
+
+	add_protocol ipip6;
+	add_protocol dslite;
 }
-- 
2.40.1.windows.1




More information about the openwrt-devel mailing list