Quellcode durchsuchen

tayga: import from oldpackages

Signed-off-by: Ondrej Caletka <ondrej@caletka.cz>
Ondřej Caletka vor 10 Jahren
Ursprung
Commit
db0236fb85

+ 48
- 0
ipv6/tayga/Makefile Datei anzeigen

@@ -0,0 +1,48 @@
1
+# $Id: Makefile 5624 2006-11-23 00:29:07Z nbd $
2
+
3
+include $(TOPDIR)/rules.mk
4
+
5
+PKG_NAME:=tayga
6
+PKG_VERSION:=0.9.2
7
+PKG_RELEASE:=1
8
+
9
+PKG_SOURCE:=tayga-$(PKG_VERSION).tar.bz2
10
+PKG_SOURCE_URL:=http://www.litech.org/tayga/
11
+PKG_MD5SUM:=7a7b24165ce008df772f398d86fa280e
12
+PKG_CAT:=bzcat
13
+
14
+PKG_BUILD_DIR:=$(BUILD_DIR)/tayga-$(PKG_VERSION)
15
+PKG_FIXUP:=autoreconf
16
+
17
+include $(INCLUDE_DIR)/package.mk
18
+
19
+define Package/tayga
20
+  SECTION:=net
21
+  CATEGORY:=Network
22
+  DEPENDS:=+ip +kmod-ipv6 +kmod-tun
23
+  TITLE:=Out-of-kernel stateless NAT64 implementation for Linux
24
+  URL:=http://www.litech.org/tayga/
25
+endef
26
+
27
+define Package/tayga/description
28
+  TAYGA is an out-of-kernel stateless NAT64 implementation for
29
+  Linux.  It uses the TUN driver to exchange packets with the
30
+  kernel, which is the same driver used by OpenVPN and QEMU/KVM.
31
+endef
32
+
33
+# TODO: port scripts to netifd
34
+ifdef CONFIG_PACAKGE_netifd
35
+  define Package/tayga/install
36
+	$(INSTALL_DIR) $(1)/usr/sbin
37
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/tayga $(1)/usr/sbin/
38
+  endef
39
+else
40
+  define Package/tayga/install
41
+	$(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/network $(1)/etc/hotplug.d/iface
42
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/tayga $(1)/usr/sbin/
43
+	$(INSTALL_DATA) ./files/tayga.sh $(1)/lib/network/tayga.sh
44
+	$(INSTALL_DATA) ./files/tayga.hotplug $(1)/etc/hotplug.d/iface/95-tayga
45
+  endef
46
+endif
47
+
48
+$(eval $(call BuildPackage,tayga))

+ 37
- 0
ipv6/tayga/files/tayga.hotplug Datei anzeigen

@@ -0,0 +1,37 @@
1
+#!/bin/sh
2
+
3
+if [ "$ACTION" = ifup ]; then
4
+	. /lib/functions.sh
5
+
6
+	include /lib/network
7
+	scan_interfaces
8
+
9
+	update_tunnel() {
10
+		local cfg="$1"
11
+
12
+		local proto
13
+		config_get proto "$cfg" proto
14
+		[ "$proto" = tayga ] || return 0
15
+
16
+		local wandev4
17
+		config_get wandev4 "$cfg" wan4_device "$(find_tayga_wanif4)"
18
+
19
+		local wandev6
20
+		config_get wandev6 "$cfg" wan6_device "$(find_tayga_wanif6)"
21
+
22
+		[ "$wandev4" = "$DEVICE" ] || [ "$wandev6" = "$DEVICE" ] || return 0
23
+
24
+		local wanip4=$(find_tayga_wanip4 "$wandev4")
25
+		local wanip6=$(find_tayga_wanip6 "$wandev6")
26
+
27
+		[ -n "$wanip4" ] && [ -n "$wanip6" ] && {
28
+			uci_set_state network "$cfg" ipv4addr "$wanip4"
29
+			uci_set_state network "$cfg" ipv6addr "$wanip6"
30
+
31
+			logger -t tayga-update "Re-establishing tayga NAT64 due to change on $INTERFACE ($DEVICE)"
32
+			ifup "$cfg" &
33
+		}
34
+	}
35
+
36
+	config_foreach update_tunnel interface
37
+fi

+ 152
- 0
ipv6/tayga/files/tayga.sh Datei anzeigen

@@ -0,0 +1,152 @@
1
+# tayga.sh - NAT64 backend
2
+
3
+find_tayga_wanif4() {
4
+	local if=$(ip -4 r l e 0.0.0.0/0); if="${if#default* dev }"; if="${if%% *}"
5
+	[ -n "$if" ] && grep -qs "^ *$if:" /proc/net/dev && echo "$if"
6
+}
7
+
8
+find_tayga_wanip4() {
9
+	local ip=$(ip -4 a s dev "$1"); ip="${ip#*inet }"
10
+	echo "${ip%%[^0-9.]*}"
11
+}
12
+
13
+find_tayga_wanif6() {
14
+	local if=$(ip -6 r l e ::/0); if="${if#default* dev }"; if="${if%% *}"
15
+	[ -n "$if" ] && grep -qs "^ *$if:" /proc/net/dev && echo "$if"
16
+}
17
+
18
+find_tayga_wanip6() {
19
+	local ip=$(ip -6 a s dev "$1"); ip="${ip#*inet6 }"
20
+	echo "${ip%%[^0-9A-Fa-f:]*}"
21
+}
22
+
23
+# Hook into scan_interfaces() to synthesize a .device option
24
+# This is needed for /sbin/ifup to properly dispatch control
25
+# to setup_interface_tayga() even if no .ifname is set in
26
+# the configuration.
27
+scan_tayga() {
28
+	config_set "$1" device "tayga-$1"
29
+}
30
+
31
+coldplug_interface_tayga() {
32
+	setup_interface_tayga "tayga-$1" "$1"
33
+}
34
+
35
+tayga_add_static_mappings() {
36
+	local tmpconf="$1"
37
+
38
+	(
39
+		. /lib/functions.sh
40
+		config_load firewall
41
+
42
+		tayga_map_rule_add() {
43
+			local cfg="$1"
44
+			local tmpconf="$2"
45
+			local ipv4_addr ipv6_addr
46
+			config_get ipv4_addr "$cfg" ipv4_addr ""
47
+			config_get ipv6_addr "$cfg" ipv6_addr ""
48
+			[ -n "$ipv4_addr" ] && [ -n "$ipv6_addr" ] &&
49
+				echo "map $ipv4_addr $ipv6_addr" >>$tmpconf
50
+		}
51
+
52
+		config_foreach tayga_map_rule_add nat64 "$tmpconf"
53
+	)
54
+}
55
+
56
+setup_interface_tayga() {
57
+	local iface="$1"
58
+	local cfg="$2"
59
+	local link="tayga-$cfg"
60
+
61
+	local ipv4_addr ipv6_addr prefix dynamic_pool
62
+
63
+	config_get ipv4_addr "$cfg" ipv4_addr
64
+	config_get ipv6_addr "$cfg" ipv6_addr
65
+	config_get prefix "$cfg" prefix
66
+	config_get dynamic_pool "$cfg" dynamic_pool
67
+
68
+	local args
69
+
70
+	include /lib/network
71
+	scan_interfaces
72
+
73
+	local wanip4=$(uci_get network "$cfg" ipv4addr)
74
+	local wanip6=$(uci_get network "$cfg" ipv6addr)
75
+
76
+	local wanif4=$(find_tayga_wanif4)
77
+	local wanif6=$(find_tayga_wanif6)
78
+
79
+	[ -z "$wanip4" ] && {
80
+		[ -n "$wanif4" ] && {
81
+			wanip4=$(find_tayga_wanip4 "$wanif4")
82
+			uci_set_state network "$cfg" wan4_device "$wanif4"
83
+		}
84
+	}
85
+
86
+	[ -z "$wanip6" ] && {
87
+		[ -n "$wanif6" ] && {
88
+			wanip6=$(find_tayga_wanip6 "$wanif6")
89
+			uci_set_state network "$cfg" wan6_device "$wanif6"
90
+		}
91
+	}
92
+
93
+	[ -n "$wanip4" ] && [ -n "$wanip6" ] || {
94
+		echo "Cannot determine local IPv4 and IPv6 addressed for tayga NAT64 $cfg - skipping"
95
+		return 1
96
+	}
97
+
98
+	local tmpconf="/var/etc/tayga-$cfg.conf"
99
+	args="-c $tmpconf"
100
+	mkdir -p /var/etc
101
+	mkdir -p /var/run/tayga/$cfg
102
+
103
+	echo "tun-device $link" >$tmpconf
104
+	echo "ipv4-addr $ipv4_addr" >>$tmpconf
105
+	[ -n "$ipv6_addr" ] &&
106
+		echo "ipv6-addr $ipv6_addr" >>$tmpconf
107
+	[ -n "$prefix" ] &&
108
+		echo "prefix $prefix" >>$tmpconf
109
+
110
+	tayga_add_static_mappings "$tmpconf"
111
+
112
+	[ -n "$dynamic_pool" ] &&
113
+		echo "dynamic-pool $dynamic_pool" >>$tmpconf
114
+	echo "data-dir /var/run/tayga/$cfg" >>$tmpconf
115
+
116
+	# creating the tunnel below will trigger a net subsystem event
117
+	# prevent it from touching or iface by disabling .auto here
118
+	uci_set_state network "$cfg" ifname $link
119
+	uci_set_state network "$cfg" auto 0
120
+
121
+	# here we create TUN device and check configuration
122
+	tayga $args --mktun || return 1
123
+
124
+	ip link set "$link" up
125
+
126
+	ip addr add "$wanip4" dev "$link"
127
+	ip addr add "$wanip6" dev "$link"
128
+
129
+	[ -n "$dynamic_pool" ] &&
130
+		ip -4 route add "$dynamic_pool" dev "$link"
131
+	[ -n "$prefix" ] &&
132
+		ip -6 route add "$prefix" dev "$link"
133
+
134
+	start-stop-daemon -S -x tayga -- $args -p /var/run/$link.pid
135
+
136
+	env -i ACTION="ifup" DEVICE="$link" INTERFACE="$cfg" PROTO="tayga" \
137
+		/sbin/hotplug-call iface
138
+}
139
+
140
+stop_interface_tayga() {
141
+	local cfg="$1"
142
+	local link="tayga-$cfg"
143
+
144
+	env -i ACTION="ifdown" DEVICE="$link" INTERFACE="$cfg" PROTO="tayga" \
145
+		/sbin/hotplug-call iface
146
+
147
+	service_kill tayga "/var/run/$link.pid"
148
+
149
+	ip link set "$link" down
150
+	ip addr flush dev "$link"
151
+	ip route flush dev "$link"
152
+}

+ 11
- 0
ipv6/tayga/patches/001-configure_unset_CFLAGS.patch Datei anzeigen

@@ -0,0 +1,11 @@
1
+--- a/configure.ac
2
++++ b/configure.ac
3
+@@ -5,8 +5,6 @@ AC_CONFIG_HEADERS(config.h)
4
+ 
5
+ AC_PROG_CC
6
+ 
7
+-CFLAGS='-g -Wall'
8
+-
9
+ tayga_conf_path=${sysconfdir}/tayga.conf
10
+ 
11
+ AC_SUBST(tayga_conf_path)