Browse Source

tayga: Add Netifd support

This patch integrates tayga with netifd. Parametres are nearly same as
with the older scripts. Support for static mapping of IPv4<=>IPv6 addresses
is missing. Example configuration:

config interface 'nat64'
        option proto 'tayga'
        option prefix 64:ff9b::/96
        option dynamic_pool 10.128.0.0/24
        option ipv4_addr 10.128.0.1	#address of the TAYGA itself
        option ipv6_addr 2001:470:5990::64
        option ipaddr  192.168.1.1 #optional address of TUN interface
        option ip6addr 2001:db8::1

Signed-off-by: Ondrej Caletka <ondrej@caletka.cz>
Ondřej Caletka 10 years ago
parent
commit
545b84c547
2 changed files with 96 additions and 4 deletions
  1. 4
    4
      ipv6/tayga/Makefile
  2. 92
    0
      ipv6/tayga/files/tayga-proto.sh

+ 4
- 4
ipv6/tayga/Makefile View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk
4 4
 
5 5
 PKG_NAME:=tayga
6 6
 PKG_VERSION:=0.9.2
7
-PKG_RELEASE:=1
7
+PKG_RELEASE:=2
8 8
 
9 9
 PKG_SOURCE:=tayga-$(PKG_VERSION).tar.bz2
10 10
 PKG_SOURCE_URL:=http://www.litech.org/tayga/
@@ -31,11 +31,11 @@ define Package/tayga/description
31 31
   kernel, which is the same driver used by OpenVPN and QEMU/KVM.
32 32
 endef
33 33
 
34
-# TODO: port scripts to netifd
35
-ifdef CONFIG_PACAKGE_netifd
34
+ifdef CONFIG_PACKAGE_netifd
36 35
   define Package/tayga/install
37
-	$(INSTALL_DIR) $(1)/usr/sbin
36
+	$(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/netifd/proto
38 37
 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/tayga $(1)/usr/sbin/
38
+	$(INSTALL_BIN) ./files/tayga-proto.sh $(1)/lib/netifd/proto/tayga.sh
39 39
   endef
40 40
 else
41 41
   define Package/tayga/install

+ 92
- 0
ipv6/tayga/files/tayga-proto.sh View File

@@ -0,0 +1,92 @@
1
+#!/bin/sh
2
+# tayga.sh - TAYGA proto
3
+# Copyright (c) 2014 OpenWrt.org
4
+
5
+[ -n "$INCLUDE_ONLY" ] || {
6
+	. /lib/functions.sh
7
+	. /lib/functions/network.sh
8
+	. ../netifd-proto.sh
9
+	init_proto "$@"
10
+}
11
+
12
+proto_tayga_setup() {
13
+	local cfg="$1"
14
+	local iface="$2"
15
+	local link="tayga-$cfg"
16
+
17
+	local ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
18
+	json_get_vars ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
19
+	[ -z "$ipv4_addr" -o -z "$prefix" ] && {
20
+		proto_notify_error "$cfg" "REQUIRED_PARAMETERS_MISSING"
21
+		proto_block_restart "$cfg"
22
+		return
23
+	}
24
+
25
+	local tmpconf="/var/etc/tayga-$cfg.conf"
26
+	mkdir -p /var/etc
27
+	mkdir -p /var/run/tayga/$cfg
28
+
29
+	echo "tun-device $link" >$tmpconf
30
+	echo "ipv4-addr $ipv4_addr" >>$tmpconf
31
+	[ -n "$ipv6_addr" ] &&
32
+		echo "ipv6-addr $ipv6_addr" >>$tmpconf
33
+	[ -n "$prefix" ] &&
34
+		echo "prefix $prefix" >>$tmpconf
35
+	[ -n "$dynamic_pool" ] &&
36
+		echo "dynamic-pool $dynamic_pool" >>$tmpconf
37
+	echo "data-dir /var/run/tayga/$cfg" >>$tmpconf
38
+	#TODO: Support static mapping of IPv4 <-> IPv6
39
+
40
+	# here we create TUN device and check configuration
41
+	tayga -c $tmpconf --mktun
42
+	[ "$?" -ne 0 ] && {
43
+		proto_notify_error "$cfg" "TAYGA_FAILED"
44
+		proto_block_restart "$cfg"
45
+		return
46
+	}
47
+
48
+	proto_init_update "$link" 1
49
+
50
+	[ -n "$ipaddr" ]  && proto_add_ipv4_address "$ipaddr" "255.255.255.255"
51
+	[ -n "$ip6addr" ] && proto_add_ipv6_address "$ip6addr" "128"
52
+	[ -n "$ipv6_addr" ] && proto_add_ipv6_route "$ipv6_addr" "128"
53
+	[ -n "$dynamic_pool" ] && {
54
+		local pool="${dynamic_pool%%/*}"
55
+		local mask="${dynamic_pool##*/}"
56
+		proto_add_ipv4_route "$pool" "$mask"
57
+	}
58
+	[ -n "$prefix" ] && {
59
+		local prefix6="${prefix%%/*}"
60
+		local mask6="${prefix##*/}"
61
+		proto_add_ipv6_route "$prefix6" "$mask6"
62
+	}
63
+
64
+	proto_send_update "$cfg"
65
+
66
+	proto_run_command "$cfg" tayga -n -c $tmpconf \
67
+		-p /var/run/$link.pid
68
+
69
+}
70
+
71
+proto_tayga_teardown() {
72
+	local cfg="$1"
73
+	local tmpconf="/var/etc/tayga-$cfg.conf"
74
+	proto_kill_command "$cfg"
75
+	sleep 1
76
+	tayga -c $tmpconf --rmtun
77
+}
78
+
79
+proto_tayga_init_config() {
80
+	no_device=1
81
+	available=1
82
+	proto_config_add_string "ipv4_addr"
83
+	proto_config_add_string "ipv6_addr"
84
+	proto_config_add_string "prefix"
85
+	proto_config_add_string "dynamic_pool"
86
+	proto_config_add_string "ipaddr"
87
+	proto_config_add_string "ip6addr:ip6addr"
88
+}
89
+
90
+[ -n "$INCLUDE_ONLY" ] || {
91
+	add_protocol tayga
92
+}