From ae6a0e45d820c61df8c06574661bfc6dc369f981 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Mon, 30 Jan 2017 10:50:46 +0100 Subject: [PATCH 1/6] nat46: support portless protocols in 1:1 share ratio 5fed76d nat46-core: support portless protocols in 1:1 share ratio df4c7da nat46-core: minor code improvements 4e45bd5 treewide: fix white space errors Signed-off-by: Hans Dedecker --- nat46/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nat46/Makefile b/nat46/Makefile index 0283dd4..47b5a5b 100644 --- a/nat46/Makefile +++ b/nat46/Makefile @@ -9,14 +9,14 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=nat46 -PKG_VERSION:=7 +PKG_VERSION:=8 PKG_RELEASE:=$(PKG_SOURCE_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_URL:=https://github.com/ayourtch/nat46.git PKG_SOURCE_PROTO:=git -PKG_SOURCE_VERSION:=8ff2ae59ec9840a7b8b45f976c51cae80abe0226 +PKG_SOURCE_VERSION:=1cd9fc7025906e1825767b05615d2cf02e1528da PKG_MAINTAINER:=Steven Barth PKG_LICENSE:=GPL-2.0 From e5e48d9a86f36a69ec488a101c6e41556b9db65c Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Tue, 16 May 2017 09:58:26 +0200 Subject: [PATCH 2/6] nat46: improve 1:1 map share ratio support 683fbd2 nat46-core: code clean-up 09df268 nat46-core: extend portless protocol support in 1:1 share ratio Signed-off-by: Hans Dedecker --- nat46/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nat46/Makefile b/nat46/Makefile index 47b5a5b..5224e57 100644 --- a/nat46/Makefile +++ b/nat46/Makefile @@ -9,14 +9,14 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=nat46 -PKG_VERSION:=8 +PKG_VERSION:=9 PKG_RELEASE:=$(PKG_SOURCE_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_URL:=https://github.com/ayourtch/nat46.git PKG_SOURCE_PROTO:=git -PKG_SOURCE_VERSION:=1cd9fc7025906e1825767b05615d2cf02e1528da +PKG_SOURCE_VERSION:=683fbd2b765506332a1af141545652bf58f03166 PKG_MAINTAINER:=Steven Barth PKG_LICENSE:=GPL-2.0 From ae774f4a9733b78052b60bee1d28025806c4d870 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Wed, 17 May 2017 22:18:33 +0200 Subject: [PATCH 3/6] nat46: add PKG_MIRROR_HASH Provide PKG_MIRROR_HASH for LEDE download mirror Signed-off-by: Hans Dedecker --- nat46/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/nat46/Makefile b/nat46/Makefile index 5224e57..3af8718 100644 --- a/nat46/Makefile +++ b/nat46/Makefile @@ -13,6 +13,7 @@ PKG_VERSION:=9 PKG_RELEASE:=$(PKG_SOURCE_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz +PKG_MIRROR_HASH:=43b7004bfa2c830d6025386bc2128015db0012277fd015f4ee44b9ee3b772a12 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_URL:=https://github.com/ayourtch/nat46.git PKG_SOURCE_PROTO:=git From 3d18d0cfc2e3023be075eb3a5f519da6571073b0 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Thu, 1 Jun 2017 14:19:42 +0200 Subject: [PATCH 4/6] 464xlat: rework process id write logic Write the process id in the pid file immediately after the 464xlat pid file has been openend. Before the process id was written when the parent process exits leaving a window where no valid process id was in place in the 464xlat pid file. This lead to issues if the 464xlat utility was launched to terminate a running 464xlat utility as it could possibly terminate a random process. If the parent process exits the pid file is updated with the process id of the forked 464xlat utility. Also rework the signal handling of SIGTERM so the running 464xlat utility is correctly terminated. Signed-off-by: Hans Dedecker --- nat46/src/464xlatcfg.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nat46/src/464xlatcfg.c b/nat46/src/464xlatcfg.c index f184616..0f9ad31 100644 --- a/nat46/src/464xlatcfg.c +++ b/nat46/src/464xlatcfg.c @@ -1,6 +1,7 @@ /* 464xlatcfg.c * * Copyright (c) 2015 Steven Barth + * Copyright (c) 2017 Hans Dedecker * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -40,8 +41,9 @@ int main(int argc, const char *argv[]) snprintf(buf, sizeof(buf), "/var/run/%s.pid", argv[1]); FILE *fp = fopen(buf, "r"); if (fp) { - fscanf(fp, "%d", &pid); - kill(pid, SIGTERM); + if (fscanf(fp, "%d", &pid) == 1) + kill(pid, SIGTERM); + unlink(buf); fclose(fp); } @@ -52,7 +54,9 @@ int main(int argc, const char *argv[]) if (!argv[3] || !argv[4] || !(fp = fopen(buf, "wx"))) return 1; - signal(SIGTERM, sighandler); + signal(SIGTERM, SIG_DFL); + setvbuf(fp, NULL, _IOLBF, 0); + fprintf(fp, "%d\n", getpid()); prefix[sizeof(prefix) - 1] = 0; strncpy(prefix, argv[3], sizeof(prefix) - 1); @@ -133,6 +137,7 @@ int main(int argc, const char *argv[]) fclose(stderr); chdir("/"); setsid(); + signal(SIGTERM, sighandler); pause(); nat46 = fopen("/proc/net/nat46/control", "w"); @@ -141,6 +146,7 @@ int main(int argc, const char *argv[]) fclose(nat46); } } else { + rewind(fp); fprintf(fp, "%d\n", pid); } From c39de0ab35663fc749432b65a43724f34169fc65 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Fri, 2 Jun 2017 15:35:58 +0200 Subject: [PATCH 5/6] 464xlat: fix white space errors Signed-off-by: Hans Dedecker --- nat46/src/464xlatcfg.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nat46/src/464xlatcfg.c b/nat46/src/464xlatcfg.c index 0f9ad31..288733e 100644 --- a/nat46/src/464xlatcfg.c +++ b/nat46/src/464xlatcfg.c @@ -32,12 +32,12 @@ int main(int argc, const char *argv[]) { char buf[INET6_ADDRSTRLEN], prefix[INET6_ADDRSTRLEN + 4]; int pid; - + if (argc <= 1) { fprintf(stderr, "Usage: %s [ifname] [ipv6prefix] [ipv4addr] [ipv6addr]\n", argv[0]); return 1; } - + snprintf(buf, sizeof(buf), "/var/run/%s.pid", argv[1]); FILE *fp = fopen(buf, "r"); if (fp) { @@ -47,10 +47,10 @@ int main(int argc, const char *argv[]) unlink(buf); fclose(fp); } - + if (!argv[2]) return 0; - + if (!argv[3] || !argv[4] || !(fp = fopen(buf, "wx"))) return 1; @@ -74,7 +74,7 @@ int main(int argc, const char *argv[]) strcat(prefix, "/96"); freeaddrinfo(res); } - + int i = 0; int sock; struct sockaddr_in6 saddr; @@ -102,7 +102,7 @@ int main(int argc, const char *argv[]) sleep(3); i++; } while (i < 3); - + struct ipv6_mreq mreq = {saddr.sin6_addr, if_nametoindex(argv[2])}; if (!argv[5]) { if (IN6_IS_ADDR_LINKLOCAL(&mreq.ipv6mr_multiaddr)) @@ -115,21 +115,21 @@ int main(int argc, const char *argv[]) } else if (inet_pton(AF_INET6, argv[5], &mreq.ipv6mr_multiaddr) != 1) { return 1; } - + if (setsockopt(sock, SOL_IPV6, IPV6_JOIN_ANYCAST, &mreq, sizeof(mreq))) return 3; - + inet_ntop(AF_INET6, &mreq.ipv6mr_multiaddr, buf, sizeof(buf)); fputs(buf, stdout); fputc('\n', stdout); fflush(stdout); - + FILE *nat46 = fopen("/proc/net/nat46/control", "w"); if (!nat46 || fprintf(nat46, "add %s\nconfig %s local.style NONE local.v4 %s/32 local.v6 %s/128 " "remote.style RFC6052 remote.v6 %s\n", argv[1], argv[1], argv[4], buf, prefix) < 0 || fclose(nat46)) return 4; - + if (!(pid = fork())) { fclose(fp); fclose(stdin); @@ -149,6 +149,6 @@ int main(int argc, const char *argv[]) rewind(fp); fprintf(fp, "%d\n", pid); } - + return 0; } From 8d7993d8f99c9d759f02ea7c694adb30cb291b80 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Fri, 2 Jun 2017 15:38:10 +0200 Subject: [PATCH 6/6] 464xlat: add ip rule logic in the proto shell handler Integrate ip rule support for the prelocal routing table lookup in the 464xlat proto shell handler as netifd does not install anymore an ip rule for the prelocal routing table. The prelocal routing table ip rule needs to be installed before the local routing table ip rule so the 464xlat traffic with as destination the IPv6 anycast address is routed to the nat46 module otherwise the traffic will be dropped in the IPv6 local table. Signed-off-by: Hans Dedecker --- nat46/Makefile | 4 ++-- nat46/files/464xlat.sh | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/nat46/Makefile b/nat46/Makefile index 3af8718..1140bcf 100644 --- a/nat46/Makefile +++ b/nat46/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=nat46 -PKG_VERSION:=9 +PKG_VERSION:=10 PKG_RELEASE:=$(PKG_SOURCE_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz @@ -33,7 +33,7 @@ endef define Package/464xlat SECTION:=net CATEGORY:=Network - DEPENDS:=+kmod-nat46 + DEPENDS:=+kmod-nat46 +ip TITLE:=464xlat CLAT support endef diff --git a/nat46/files/464xlat.sh b/nat46/files/464xlat.sh index 2ec1094..4b3cd1c 100755 --- a/nat46/files/464xlat.sh +++ b/nat46/files/464xlat.sh @@ -43,6 +43,11 @@ proto_464xlat_setup() { return fi + ip -6 rule del from all lookup local + ip -6 rule add from all lookup local pref 1 + ip -6 rule add to $ip6addr lookup prelocal pref 0 + echo "$ip6addr" > /tmp/464-$cfg-anycast + proto_init_update "$link" 1 proto_add_ipv4_route "0.0.0.0" 0 "" "" 2048 proto_add_ipv6_route $ip6addr 128 "" "" "" "" 128 @@ -74,7 +79,20 @@ proto_464xlat_setup() { } proto_464xlat_teardown() { - 464xlatcfg "464-$1" + local cfg="$1" + local link="464-$cfg" + local ip6addr=$(cat /tmp/464-$cfg-anycast) + local anycast_active + + 464xlatcfg "$link" + + rm -rf /tmp/464-$cfg-anycast + ip -6 rule del to $ip6addr lookup prelocal + + if [ -z "$(ls /tmp/464-*-anycast 2>&-)" ]; then + ip -6 rule del from all lookup local + ip -6 rule add from all lookup local pref 0 + fi } proto_464xlat_init_config() {