Browse Source

ibrdtnd: add new package

This package contains the daemon (dtnd) of IBR-DTN, a modular and lightweight
implementation of the bundle protocol (RFC 5050). https://github.com/ibrdtn/ibrdtn

Signed-off-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
Johannes Morgenroth 10 years ago
parent
commit
02f1617c00

+ 58
- 0
net/ibrdtnd/Makefile View File

@@ -0,0 +1,58 @@
1
+#
2
+# Copyright (C) 2014 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=ibrdtnd
11
+PKG_VERSION:=0.12.1
12
+PKG_RELEASE:=1
13
+
14
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15
+PKG_SOURCE_URL:=http://www.ibr.cs.tu-bs.de/projects/ibr-dtn/releases
16
+PKG_MD5SUM:=8dad5ebbcfaa4c16ba151c9c289066c3
17
+PKG_MAINTAINER:=Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
18
+PKG_LICENSE:=Apache-2.0
19
+
20
+PKG_INSTALL:=1
21
+PKG_BUILD_DEPENDS:=dtndht ibrdtn libsqlite3
22
+
23
+include $(INCLUDE_DIR)/package.mk
24
+
25
+define Package/ibrdtnd
26
+  SECTION:=net
27
+  CATEGORY:=Network
28
+  DEPENDS:=+dtndht +ibrdtn +libsqlite3
29
+  TITLE:=DTN Deamon
30
+endef
31
+
32
+define Package/ibrdtnd/conffiles
33
+/etc/config/ibrdtn
34
+endef
35
+
36
+define Package/ibrdtnd/description
37
+ The implementation of the bundle protocol of the IBR (TU Braunschweig).
38
+endef
39
+
40
+CONFIGURE_ARGS += \
41
+        --with-tls --with-sqlite --with-dht
42
+
43
+define Package/ibrdtnd/install
44
+	$(INSTALL_DIR) $(1)/usr/sbin/
45
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/dtnd $(1)/usr/sbin/
46
+	$(INSTALL_BIN) files/safety-wrapper.sh $(1)/usr/sbin/dtnd-safety-wrapper.sh
47
+	$(INSTALL_DIR) $(1)/usr/share/ibrdtn/
48
+	$(INSTALL_BIN) files/build-config.sh $(1)/usr/share/ibrdtn/build-config.sh
49
+	$(INSTALL_BIN) files/mkcontainer.sh $(1)/usr/share/ibrdtn/mkcontainer.sh
50
+	$(INSTALL_BIN) files/mountcontainer.sh $(1)/usr/share/ibrdtn/mountcontainer.sh
51
+	$(INSTALL_BIN) files/systemcheck.sh $(1)/usr/share/ibrdtn/systemcheck.sh
52
+	$(INSTALL_DIR) $(1)/etc/init.d/
53
+	$(INSTALL_BIN) files/ibrdtn.init $(1)/etc/init.d/ibrdtn
54
+	$(INSTALL_DIR) $(1)/etc/config
55
+	$(INSTALL_CONF) files/ibrdtn.uci $(1)/etc/config/ibrdtn
56
+endef
57
+
58
+$(eval $(call BuildPackage,ibrdtnd))

+ 168
- 0
net/ibrdtnd/files/build-config.sh View File

@@ -0,0 +1,168 @@
1
+#!/bin/sh
2
+#
3
+# convert uci configuration into daemon specific format
4
+#
5
+
6
+UCI=/sbin/uci
7
+
8
+create_file() {
9
+	echo "# -- DO NOT EDIT THIS FILE --" > $1
10
+	echo "# automatic generated configuration file for IBR-DTN daemon" >> $1
11
+	echo "#" >> $1
12
+}
13
+
14
+add_param() {
15
+	VALUE=`$UCI -q get $2`
16
+	
17
+	if [ $? == 0 ]; then
18
+		echo "$3 = $VALUE" >> $1
19
+	fi
20
+}
21
+
22
+getconfig() {
23
+	$UCI -q get ibrdtn.$1
24
+	return $?
25
+}
26
+
27
+if [ "$1" == "--safe-mode" ]; then
28
+	SAFEMODE=yes
29
+	CONFFILE=$2
30
+else
31
+	SAFEMODE=no
32
+	CONFFILE=$1
33
+fi
34
+
35
+# create the file and write some header info
36
+create_file $CONFFILE
37
+
38
+add_param $CONFFILE "ibrdtn.main.uri" "local_uri"
39
+add_param $CONFFILE "ibrdtn.main.routing" "routing"
40
+add_param $CONFFILE "ibrdtn.main.fragmentation" "fragmentation"
41
+
42
+if [ "$SAFEMODE" == "yes" ]; then
43
+	if [ -n "`getconfig safemode.forwarding`" ]; then
44
+		add_param $CONFFILE "ibrdtn.safemode.forwarding" "routing_forwarding"
45
+	else
46
+		add_param $CONFFILE "ibrdtn.main.forwarding" "routing_forwarding"
47
+	fi
48
+
49
+	if [ -n "`getconfig safemode.maxblock`" ]; then
50
+		add_param $CONFFILE "ibrdtn.safemode.maxblock" "limit_blocksize"
51
+	else
52
+		add_param $CONFFILE "ibrdtn.main.blocksize" "limit_blocksize"
53
+	fi
54
+
55
+	if [ -n "`getconfig safemode.storage`" ]; then
56
+		add_param $CONFFILE "ibrdtn.safemode.storage" "limit_storage"
57
+	else
58
+		add_param $CONFFILE "ibrdtn.storage.limit" "limit_storage"
59
+	fi
60
+else
61
+	add_param $CONFFILE "ibrdtn.main.forwarding" "routing_forwarding"
62
+	add_param $CONFFILE "ibrdtn.main.blocksize" "limit_blocksize"
63
+	add_param $CONFFILE "ibrdtn.storage.limit" "limit_storage"
64
+	add_param $CONFFILE "ibrdtn.storage.blobs" "blob_path"
65
+	add_param $CONFFILE "ibrdtn.storage.bundles" "storage_path"
66
+	add_param $CONFFILE "ibrdtn.storage.engine" "storage"
67
+fi
68
+
69
+add_param $CONFFILE "ibrdtn.main.max_predated_timestamp" "limit_predated_timestamp"
70
+add_param $CONFFILE "ibrdtn.main.limit_lifetime" "limit_lifetime"
71
+add_param $CONFFILE "ibrdtn.main.foreign_blocksize" "limit_foreign_blocksize"
72
+
73
+add_param $CONFFILE "ibrdtn.discovery.address" "discovery_address"
74
+add_param $CONFFILE "ibrdtn.discovery.timeout" "discovery_timeout"
75
+add_param $CONFFILE "ibrdtn.discovery.version" "discovery_version"
76
+add_param $CONFFILE "ibrdtn.discovery.crosslayer" "discovery_crosslayer"
77
+
78
+add_param $CONFFILE "ibrdtn.tcptuning.idle_timeout" "tcp_idle_timeout"
79
+add_param $CONFFILE "ibrdtn.tcptuning.nodelay" "tcp_nodelay"
80
+add_param $CONFFILE "ibrdtn.tcptuning.chunksize" "tcp_chunksize"
81
+
82
+add_param $CONFFILE "ibrdtn.security.level" "security_level"
83
+add_param $CONFFILE "ibrdtn.security.bab_key" "security_bab_default_key"
84
+add_param $CONFFILE "ibrdtn.security.key_path" "security_path"
85
+add_param $CONFFILE "ibrdtn.security.generate_dh" "generate_dh_params"
86
+
87
+add_param $CONFFILE "ibrdtn.tls.certificate" "security_certificate"
88
+add_param $CONFFILE "ibrdtn.tls.key" "security_key"
89
+add_param $CONFFILE "ibrdtn.tls.trustedpath" "security_trusted_ca_path"
90
+add_param $CONFFILE "ibrdtn.tls.required" "security_tls_required"
91
+add_param $CONFFILE "ibrdtn.tls.noencryption" "security_tls_disable_encryption"
92
+add_param $CONFFILE "ibrdtn.tls.fallback_badclock" "security_tls_fallback_badclock"
93
+
94
+add_param $CONFFILE "ibrdtn.timesync.reference" "time_reference"
95
+add_param $CONFFILE "ibrdtn.timesync.synchronize" "time_synchronize"
96
+add_param $CONFFILE "ibrdtn.timesync.discovery_announcement" "time_discovery_announcements"
97
+add_param $CONFFILE "ibrdtn.timesync.sigma" "time_sigma"
98
+add_param $CONFFILE "ibrdtn.timesync.psi" "time_psi"
99
+add_param $CONFFILE "ibrdtn.timesync.sync_level" "time_sync_level"
100
+add_param $CONFFILE "ibrdtn.timesync.time_set_clock" "time_set_clock"
101
+
102
+add_param $CONFFILE "ibrdtn.dht.enabled" "dht_enabled"
103
+add_param $CONFFILE "ibrdtn.dht.port" "dht_port"
104
+add_param $CONFFILE "ibrdtn.dht.id" "dht_id"
105
+add_param $CONFFILE "ibrdtn.dht.bootstrap" "dht_bootstrapping"
106
+add_param $CONFFILE "ibrdtn.dht.nodesfile" "dht_nodes_file"
107
+add_param $CONFFILE "ibrdtn.dht.enable_ipv4" "dht_enable_ipv4"
108
+add_param $CONFFILE "ibrdtn.dht.enable_ipv6" "dht_enable_ipv6"
109
+add_param $CONFFILE "ibrdtn.dht.bind_ipv4" "dht_bind_ipv4"
110
+add_param $CONFFILE "ibrdtn.dht.bind_ipv6" "dht_bind_ipv6"
111
+add_param $CONFFILE "ibrdtn.dht.ignore_neighbour_informations" "dht_ignore_neighbour_informations"
112
+add_param $CONFFILE "ibrdtn.dht.allow_neighbours_to_announce_me" "dht_allow_neighbours_to_announce_me"
113
+add_param $CONFFILE "ibrdtn.dht.allow_neighbour_announcement" "dht_allow_neighbour_announcement"
114
+
115
+
116
+# iterate through all network interfaces
117
+iter=0
118
+netinterfaces=
119
+while [ 1 == 1 ]; do
120
+	$UCI -q get "ibrdtn.@network[$iter]" > /dev/null
121
+	if [ $? == 0 ]; then
122
+		netinterfaces="${netinterfaces} lan${iter}"
123
+		add_param $CONFFILE "ibrdtn.@network[$iter].type" "net_lan${iter}_type"
124
+		add_param $CONFFILE "ibrdtn.@network[$iter].interface" "net_lan${iter}_interface"
125
+		add_param $CONFFILE "ibrdtn.@network[$iter].port" "net_lan${iter}_port"
126
+	else
127
+		break
128
+	fi
129
+	
130
+	let iter=iter+1
131
+done
132
+
133
+# write list of network interfaces
134
+echo "net_interfaces =$netinterfaces" >> $CONFFILE
135
+
136
+# iterate through all static routes
137
+iter=0
138
+while [ 1 == 1 ]; do
139
+	$UCI -q get "ibrdtn.@static-route[$iter]" > /dev/null
140
+	if [ $? == 0 ]; then
141
+		PATTERN=`$UCI -q get "ibrdtn.@static-route[$iter].pattern"`
142
+		DESTINATION=`$UCI -q get "ibrdtn.@static-route[$iter].destination"`
143
+		let NUMBER=iter+1
144
+		echo "route$NUMBER = $PATTERN $DESTINATION" >> $CONFFILE
145
+	else
146
+		break
147
+	fi
148
+	
149
+	let iter=iter+1
150
+done
151
+
152
+#iterate through all static connections
153
+iter=0
154
+while [ 1 == 1 ]; do
155
+	$UCI -q get "ibrdtn.@static-connection[$iter]" > /dev/null
156
+	if [ $? == 0 ]; then
157
+		let NUMBER=iter+1
158
+		add_param $CONFFILE "ibrdtn.@static-connection[$iter].uri" "static${NUMBER}_uri"
159
+		add_param $CONFFILE "ibrdtn.@static-connection[$iter].address" "static${NUMBER}_address"
160
+		add_param $CONFFILE "ibrdtn.@static-connection[$iter].port" "static${NUMBER}_port"
161
+		add_param $CONFFILE "ibrdtn.@static-connection[$iter].protocol" "static${NUMBER}_proto"
162
+		add_param $CONFFILE "ibrdtn.@static-connection[$iter].immediately" "static${NUMBER}_immediately"
163
+	else
164
+		break
165
+	fi
166
+	
167
+	let iter=iter+1
168
+done

+ 71
- 0
net/ibrdtnd/files/ibrdtn.init View File

@@ -0,0 +1,71 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2007 OpenWrt.org
3
+
4
+START=90
5
+
6
+start() {
7
+	# check if the daemon is disabled
8
+	if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
9
+		/bin/echo "dtnd is disabled"
10
+		return
11
+	fi
12
+	
13
+	/bin/echo -n "running dtnd ..."
14
+	
15
+	# startup the safety-wrapper for the daemon
16
+	/usr/sbin/dtnd-safety-wrapper.sh &
17
+	
18
+	# store the pid of the process in uci states
19
+	/sbin/uci -P/var/state -q set ibrdtn.safetypid=`echo $!`
20
+	
21
+	/bin/echo " done"
22
+}
23
+
24
+stop() { 
25
+	# check if the daemon is disabled
26
+	if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
27
+		/bin/echo "dtnd is disabled"
28
+		return
29
+	fi
30
+	
31
+	/bin/echo -n "stopping dtnd ..."
32
+	
33
+	# set state to None, this indicates a clear shutdown to the safety-wrapper.
34
+	/sbin/uci -P/var/state -q set ibrdtn.state=None
35
+	
36
+	# stop the safety-wrapper
37
+	if [ -n "`/sbin/uci -P/var/state -q get ibrdtn.safetypid`" ]; then
38
+		/usr/bin/kill `/sbin/uci -P/var/state -q get ibrdtn.safetypid` 2> /dev/null >/dev/null
39
+	fi
40
+	
41
+	# finally kill really all safety-wrapper!
42
+	/bin/sleep 2
43
+	/usr/bin/killall -9 dtnd-safety-wrapper.sh
44
+	
45
+	# send a kill signal to the daemon
46
+	/usr/bin/killall dtnd 2> /dev/null >/dev/null
47
+	
48
+	# wait for some time
49
+	TIMEOUT=0;
50
+	
51
+	# check if the daemon is running
52
+	while [ -n "`ps | grep dtnd | grep -v grep`" ]; do
53
+		# check if the daemon is still running
54
+		if [ $TIMEOUT -ge 10 ]; then
55
+			/bin/echo " killing"
56
+			# kill all processes of dtnd
57
+			/usr/bin/killall -9 dtnd 2> /dev/null >/dev/null
58
+			return
59
+		fi
60
+		
61
+		# increment timeout
62
+		TIMEOUT=`expr $TIMEOUT + 1`
63
+		
64
+		echo -n "."
65
+		
66
+		# wait some time
67
+		/bin/sleep 1
68
+	done
69
+	
70
+	echo " done"
71
+}

+ 175
- 0
net/ibrdtnd/files/ibrdtn.uci View File

@@ -0,0 +1,175 @@
1
+#####################################
2
+# IBR-DTN daemon                    #
3
+#####################################
4
+
5
+config 'daemon' 'main'
6
+	# The local eid of the dtn node. Default is the hostname.
7
+#	option uri			dtn://node.dtn
8
+	
9
+	# logfile for standard output
10
+	option logfile		/tmp/ibrdtn.log
11
+	option errfile		/tmp/ibrdtn.err
12
+	
13
+	# debug level
14
+#	option debug		20
15
+
16
+	# block size limit
17
+#	option blocksize		512M
18
+#	option foreign_blocksize	128M
19
+
20
+
21
+#
22
+# If something bad happened, the safe mode will be activated.
23
+# These are the restrictions for safe mode only.
24
+#
25
+config 'daemon' 'safemode'
26
+	option forwarding	no
27
+	option storage		64M
28
+	option maxblock		16M
29
+#	option wait_mount	/dev/sda1
30
+
31
+
32
+#####################################
33
+# storage configuration             #
34
+#####################################
35
+
36
+config 'daemon' 'storage'
37
+	# possible engines are: simple, sqlite
38
+	option engine		simple
39
+	option blobs		/tmp/ibrdtn/blobs
40
+	option bundles		/tmp/ibrdtn/bundles
41
+#	option container	/tmp/ibrdtn/container.img
42
+#	option path			/tmp/ibrdtn/container
43
+#	option limit		1G
44
+
45
+
46
+#####################################
47
+# routing configuration             #
48
+#####################################
49
+
50
+#
51
+# In the "default" the daemon only delivers bundles to neighbors and static
52
+# available nodes. The alternative module "epidemic" spread all bundles to
53
+# all available neighbors.
54
+#
55
+config 'daemon' 'main'
56
+	# values: none | default | epidemic | flooding | prophet
57
+	option	routing		prophet
58
+#	option	forwarding	no
59
+#	option	fragmentation	yes
60
+
61
+#
62
+# static routing rules
63
+# - a rule is a regex pattern
64
+# - format is <target-scheme> <routing-node>
65
+#
66
+#config 'static-route'
67
+#	list pattern		^dtn://[[:alpha:]].moon.dtn/[[:alpha:]]
68
+#	option destination	dtn://router.dtn
69
+
70
+
71
+#####################################
72
+# static connections
73
+#####################################
74
+
75
+#config 'static-connection'
76
+#	option uri			dtn://node-five.dtn
77
+#	option address		10.0.0.5
78
+#	option port			4556
79
+#	option protocol		tcp
80
+#	option immediately	yes
81
+
82
+#config 'static-connection'
83
+#	option uri			dtn://node-ten
84
+#	option address		10.0.0.10
85
+#	option port			4556
86
+#	option protocol		udp
87
+#	option immediately	no
88
+
89
+
90
+#####################################
91
+# convergence layer configuration   #
92
+#####################################
93
+
94
+#
95
+# You can specify an multicast address to listen to for discovery announcements.
96
+# If no address is specified the multicast equivalent of broadcast is used.
97
+#
98
+config 'daemon' 'discovery'
99
+#	option address		224.0.0.1
100
+#	option timeout		5
101
+#	option crosslayer	yes
102
+
103
+config 'daemon' 'tcptuning'
104
+#	option 'idle_timeout'	120
105
+#	option 'nodelay'		yes
106
+#	option 'chunksize'		4096
107
+
108
+config 'network'
109
+	option type			tcp
110
+	option interface	eth0
111
+	option port			4556
112
+	
113
+#config 'network'
114
+#	option type			tcp
115
+#	option interface	wlan0
116
+#	option port			4556
117
+
118
+
119
+#####################################
120
+# bundle security protocol          #
121
+#####################################
122
+
123
+#
124
+# the level specifies the security constains
125
+#
126
+# 0 = no constrains (default)
127
+# 1 = accept only BAB authenticated bundles
128
+# 2 = accept only encrypted bundles
129
+# 3 = accept only BAB authenticated and encrypted bundles
130
+#
131
+
132
+#config 'daemon' 'security'
133
+#	option level		0
134
+#	option bab_key		/path/to/default-bab-key.mac
135
+#	option key_path		/path/to/security-keys
136
+#	option generate_dh	yes
137
+	
138
+#config 'daemon' 'tls'
139
+#	option certificate	/path/to/tls-cert.crt
140
+#	option key			/path/to/tls-key.key
141
+#	option trustedpath	/path/to/tls-ca
142
+#	option required		no
143
+#	option noencryption no
144
+
145
+
146
+#####################################
147
+# time synchronization              #
148
+#####################################
149
+
150
+#config 'daemon' 'timesync'
151
+#	option reference		yes
152
+#	option synchronize		yes
153
+#	option discovery_announcement	yes
154
+#	option sigma			1.001
155
+#	option psi			0.9
156
+#	option sync_level		0.1
157
+
158
+#####################################
159
+# DHT                               #
160
+#####################################
161
+
162
+config 'daemon' 'dht'
163
+#	option 'enabled'	'yes'
164
+#	option 'id'		'<enter your unique id here>'
165
+	option 'bootstrap'	'yes'
166
+#	option 'nodesfile'	'/tmp/dht_nodes.dat'
167
+	option 'port' 		'9999'
168
+	option 'enable_ipv6'	'no'
169
+#	option 'enable_ipv4'	'no'
170
+#	option 'bind_ipv4'	'127.0.0.1'
171
+#	option 'bind_ipv6'	'::1'
172
+	option 'ignore_neighbour_informations'		'yes'
173
+	option 'allow_neighbours_to_announce_me'	'no'
174
+	option 'allow_neighbour_announcement'		'no'
175
+

+ 43
- 0
net/ibrdtnd/files/mkcontainer.sh View File

@@ -0,0 +1,43 @@
1
+#!/bin/sh
2
+#
3
+# This script creates a bundle storage of a given size.
4
+#
5
+# $1 = container file
6
+# $2 = size of the container in MB
7
+#
8
+
9
+help_message() {
10
+	echo "usage: "
11
+	echo " $0 <container file> <size in MB>"
12
+}
13
+
14
+if [ $# -le 1 ]; then
15
+	help_message
16
+	exit 1
17
+fi
18
+
19
+CONTAINER=$(cd "$(dirname "$1")"; pwd)/$(basename $1)
20
+SIZE=$2
21
+
22
+# check if the container already exists
23
+if [ -f $CONTAINER ]; then
24
+	echo "Aborted! The specified container already exists."
25
+	exit 1
26
+fi
27
+
28
+# create the container
29
+echo -n "creating the container file..."
30
+/bin/dd if=/dev/zero of=$CONTAINER bs=1M count=$SIZE >/dev/null 2>/dev/null
31
+echo " done" 
32
+
33
+# create file system
34
+echo -n "initializing ext3 filesystem for the container..."
35
+/usr/sbin/mkfs.ext3 -q -F $CONTAINER > /dev/null
36
+echo " done"
37
+
38
+# final hint
39
+echo "The container is now ready. To use it with IBR-DTN set the container with:"
40
+echo "# uci set ibrdtn.storage.container=$CONTAINER"
41
+echo "# uci set ibrdtn.storage.container_size=$SIZE"
42
+
43
+exit 0

+ 122
- 0
net/ibrdtnd/files/mountcontainer.sh View File

@@ -0,0 +1,122 @@
1
+#!/bin/sh
2
+#
3
+
4
+CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
5
+CPATH=`/sbin/uci -q get ibrdtn.storage.path`
6
+
7
+check_var() {
8
+	if [ -z "$1" ]; then
9
+		echo "$2"
10
+		exit 1
11
+	fi
12
+}
13
+
14
+check_path() {
15
+	if [ ! -d "$1" ]; then
16
+		echo "$2"
17
+		return 1
18
+	fi
19
+}
20
+
21
+check_file() {
22
+	if [ ! -f "$1" ]; then
23
+		echo "$2"
24
+		exit 1
25
+	fi
26
+}
27
+
28
+container_mount() {
29
+	CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
30
+	CPATH=`/sbin/uci -q get ibrdtn.storage.path`
31
+
32
+	if [ -z "`mount | grep ' on $CPATH '`" ]; then
33
+		# try to mount the container
34
+		/bin/mount -o loop $CONTAINER $CPATH
35
+
36
+		return $?
37
+	fi
38
+
39
+	return 0
40
+}
41
+
42
+container_reinitialize() {
43
+	SIZE=`/sbin/uci get -q ibrdtn.storage.container_size`
44
+	CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
45
+
46
+	# try to rebuild the container
47
+	if [ -n "$SIZE" ]; then
48
+		/bin/rm -f $CONTAINER
49
+		/usr/share/ibrdtn/mkcontainer.sh $CONTAINER $SIZE
50
+
51
+		if [ $? -eq 0 ]; then
52
+			container_mount
53
+			return $?
54
+		fi
55
+
56
+		return 1
57
+	fi
58
+
59
+	return 1
60
+}
61
+
62
+check_var $CONTAINER "Storage container not set in uci.\nuse: uci set ibrdtn.storage.container=<container-file>"
63
+check_var $CPATH "Storage container mount path not set in uci.\nuse: uci set ibrdtn.storage.path=<mount-path>"
64
+
65
+check_path $CPATH "Storage container mount path does not exist."
66
+if [ $? -gt 0 ]; then
67
+	/bin/mkdir -p $CPATH
68
+
69
+	if [ $? -gt 0 ]; then
70
+		echo "can not create container mount path."
71
+		exit 1
72
+	fi
73
+fi
74
+
75
+if [ "$1" == "-u" ]; then
76
+	/bin/umount $CPATH
77
+	exit 0
78
+fi
79
+
80
+if [ -n "`/bin/mount | grep $CPATH`" ]; then
81
+	echo "Container already mounted"
82
+	exit 0
83
+fi
84
+
85
+if [ ! -f "$CONTAINER" ]; then
86
+	echo "Storage container file $CONTAINER does not exist."
87
+	container_reinitialize
88
+	exit $?
89
+fi
90
+
91
+# try to mount the container
92
+container_mount
93
+
94
+if [ $? -gt 0 ]; then
95
+	echo -n "can not mount container file. checking... "
96
+	/usr/sbin/e2fsck -p $CONTAINER
97
+
98
+	if [ $? -gt 0 ]; then
99
+		echo " error"
100
+		echo "Container file $CONTAINER broken. Try to reinitialize the container."
101
+		container_reinitialize
102
+
103
+		if [ $? -eq 0 ]; then
104
+			echo "container ready!"
105
+			exit 0
106
+		else
107
+			exit 1
108
+		fi
109
+	fi
110
+	echo "done"
111
+
112
+	container_mount
113
+
114
+	if [ $? -gt 0 ]; then
115
+		echo "mount failed!"
116
+		exit 1
117
+	fi
118
+fi
119
+
120
+echo "container ready!"
121
+exit 0
122
+

+ 172
- 0
net/ibrdtnd/files/safety-wrapper.sh View File

@@ -0,0 +1,172 @@
1
+#!/bin/sh
2
+#
3
+# safety wrapper for IBR-DTN daemon
4
+#
5
+# Tasks:
6
+#  * start IBR-DTN daemon
7
+#  * restart the daemon after a crash
8
+#  * if respawning to fast, then slow down with backoff
9
+#  * check for enough space on disk and delete bundles if necessary.
10
+#  * clean the blob directory on startup
11
+#
12
+
13
+DTND=/usr/sbin/dtnd
14
+TMPCONF=/tmp/ibrdtn.config
15
+UCI=/sbin/uci
16
+
17
+getstate() {
18
+	$UCI -P/var/state -q get ibrdtn.$1
19
+	return $?
20
+}
21
+
22
+setstate() {
23
+	$UCI -P/var/state -q set ibrdtn.$1=$2
24
+	return $?
25
+}
26
+
27
+getconfig() {
28
+	$UCI -q get ibrdtn.$1
29
+	return $?
30
+}
31
+
32
+setconfig() {
33
+	$UCI -q set ibrdtn.$1=$2
34
+	return $?
35
+}
36
+
37
+# remove the old state file
38
+/bin/rm /var/state/ibrdtn
39
+
40
+# read uci configuration
41
+BLOB_PATH=`getconfig storage.blobs`
42
+BUNDLE_PATH=`getconfig storage.bundles`
43
+CONTAINER_PATH=`getconfig storage.path`
44
+CONTAINER_FILE=`getconfig storage.container`
45
+LOG_FILE=`getconfig main.logfile`
46
+ERR_FILE=`getconfig main.errfile`
47
+DEBUG_LEVEL=`getconfig main.debug`
48
+SAFEMODE=no
49
+
50
+# run a system check
51
+/bin/sh /usr/share/ibrdtn/systemcheck.sh
52
+
53
+if [ $? -eq 0 ]; then
54
+	# mount container if specified
55
+	if [ -n "$CONTAINER_FILE" ] && [ -n "$CONTAINER_PATH" ]; then
56
+		/bin/sh /usr/share/ibrdtn/mountcontainer.sh
57
+
58
+		# if the mount of the container failed
59
+		# switch to safe mode!
60
+		if [ $? -gt 0 ]; then
61
+			SAFEMODE=yes
62
+		fi
63
+	fi
64
+else
65
+	SAFEMODE=yes
66
+fi
67
+
68
+# create blob & bundle path
69
+if [ -n "$BLOB_PATH" ]; then
70
+	/bin/mkdir -p $BLOB_PATH
71
+
72
+	# clean the blob directory on startup
73
+	/bin/rm -f $BLOB_PATH/file*
74
+fi
75
+
76
+if [ -n "$BUNDLE_PATH" ]; then
77
+	/bin/mkdir -p $BUNDLE_PATH
78
+fi
79
+
80
+LOGGING=""
81
+if [ -n "$LOG_FILE" ]; then
82
+	LOGGING="$LOGGING > $LOG_FILE"
83
+else
84
+	LOGGING="$LOGGING > /dev/null"
85
+fi
86
+
87
+if [ -n "$ERR_FILE" ]; then
88
+	LOGGING="$LOGGING 2> $ERR_FILE"
89
+else
90
+	LOGGING="$LOGGING 2> /dev/null"
91
+fi
92
+
93
+if [ -z "$LOG_FILE" ] && [ -z "$ERR_FILE" ]; then
94
+	LOGGING="-q"
95
+fi
96
+
97
+# check for debugging option
98
+if [ -n "$DEBUG_LEVEL" ]; then
99
+	DEBUG_ARGS="-v -d ${DEBUG_LEVEL}"
100
+else
101
+	DEBUG_ARGS=""
102
+fi
103
+
104
+# create configuration
105
+if [ "$SAFEMODE" == "yes" ]; then
106
+	/bin/sh /usr/share/ibrdtn/build-config.sh --safe-mode $TMPCONF
107
+else
108
+	/bin/sh /usr/share/ibrdtn/build-config.sh $TMPCONF
109
+fi
110
+
111
+# set the crash counter to zero
112
+CRASH=0
113
+
114
+# run the daemon
115
+setstate state running
116
+
117
+while [ "`getstate state`" == "running" ]; do
118
+	# run a system check
119
+	/bin/sh /usr/share/ibrdtn/systemcheck.sh
120
+
121
+	# run in safe mode if the system check has failed
122
+	if [ $? -gt 0 ] && [ "$SAFEMODE" == "no" ]; then
123
+		SAFEMODE=yes
124
+		/usr/bin/logger -t "ibrdtn-safe-wrapper" -p 2 "system check failed! Switch to safe-mode settings."
125
+		/bin/sh /usr/share/ibrdtn/build-config.sh --safe-mode $TMPCONF
126
+	fi
127
+
128
+	# measure the running time
129
+	TIMESTART=`/bin/date +%s`
130
+	
131
+	# run the daemon
132
+	echo "${DTND} ${DEBUG_ARGS} -c ${TMPCONF} ${LOGGING}" | /bin/sh
133
+	
134
+	# measure the stopping time
135
+	TIMESTOP=`/bin/date +%s`
136
+	
137
+	# calc the running time
138
+	let TIMERUN=$TIMESTOP-$TIMESTART
139
+	
140
+	# reset the CRASH counter if there is one hour between the crashes
141
+	if [ $TIMERUN -ge 3600 ]; then
142
+		CRASH=0
143
+	fi
144
+	
145
+	# check if the daemon is crashed
146
+	if [ "`getstate state`" == "running" ]; then
147
+		# if the crash counter is higher than 20 switch to safe-mode settings
148
+		if [ $CRASH -eq 20 ] && [ "$SAFEMODE" == "no" ]; then
149
+			SAFEMODE=yes
150
+			/usr/bin/logger -t "ibrdtn-safe-wrapper" -p 2 "IBR-DTN daemon crashed 20 times! Switch to safe-mode settings."
151
+			/bin/sh /usr/share/ibrdtn/build-config.sh --safe-mode $TMPCONF
152
+		fi
153
+
154
+		# increment the crash counter
155
+		let CRASH=$CRASH+1
156
+		
157
+		# backoff wait timer
158
+		let WAIT=2**$CRASH
159
+		
160
+		# set a upper limit for the wait time
161
+		if [ $WAIT -ge 1800 ]; then
162
+			WAIT=1800
163
+		fi
164
+
165
+		# log the crash
166
+		/usr/bin/logger -t "ibrdtn-safe-wrapper" -p 2 "IBR-DTN daemon crashed $CRASH times! Wait $WAIT seconds."
167
+		
168
+		# wait sometime
169
+		/bin/sleep $WAIT
170
+	fi
171
+done
172
+

+ 101
- 0
net/ibrdtnd/files/systemcheck.sh View File

@@ -0,0 +1,101 @@
1
+#!/bin/sh
2
+#
3
+#
4
+
5
+check_mounted() {
6
+	DIR=$1
7
+	while [ "$DIR" != "/" ]; do
8
+		if [ -n "`mount | grep "$DIR"`" ]; then
9
+			return 0
10
+		fi
11
+
12
+		DIR=`dirname $DIR`
13
+	done
14
+	return 1
15
+}
16
+
17
+check_writable() {
18
+	CHECKFILE="$1/.container-lock"
19
+	/bin/touch $CHECKFILE
20
+
21
+	if [ $? -gt 0 ]; then
22
+		return 1;
23
+	fi
24
+
25
+	/bin/echo "0123456789" >> $CHECKFILE
26
+
27
+	if [ $? -gt 0 ]; then
28
+		return 2;
29
+	fi
30
+
31
+	/bin/rm $CHECKFILE
32
+
33
+	if [ $? -gt 0 ]; then
34
+		return 3;
35
+	fi
36
+}
37
+
38
+check_mountdev() {
39
+	# get wait_mount option
40
+	WAIT_MOUNT_DEV=`uci -q get ibrdtn.safemode.wait_mount`
41
+	
42
+	if [ $? -ne 0 ]; then
43
+		return 0
44
+	fi
45
+	
46
+	DATA=`mount | grep ${WAIT_MOUNT_DEV}`
47
+
48
+	if [ -n "${DATA}" ]; then
49
+		return 0
50
+	fi
51
+	
52
+	return 1
53
+}
54
+
55
+# check the storage device
56
+check_mountdev
57
+RET=$?
58
+
59
+if [ ${RET} -ne 0 ]; then
60
+	WAIT_SECONDS=60
61
+	/usr/bin/logger -t "systemcheck.sh" -p 2 "disk storage not ready, wait max. ${WAIT_SECONDS} seconds until it is mounted"
62
+	while [ ${RET} -ne 0 ] && [ ${WAIT_SECONDS} -ne 0 ]; do
63
+		sleep 1
64
+		let WAIT_SECONDS=WAIT_SECONDS-1
65
+		check_mountdev
66
+		RET=$?
67
+	done
68
+fi
69
+
70
+if [ ${RET} -ne 0 ]; then
71
+	# failed, storage not mounted
72
+	exit 1
73
+fi
74
+
75
+# get the path for the container
76
+CONTAINER=`uci -q get ibrdtn.storage.container`
77
+
78
+if [ -z "$CONTAINER" ]; then
79
+	exit 0
80
+fi
81
+
82
+CONTAINER_PATH=`dirname $CONTAINER`
83
+
84
+if [ -n "$CONTAINER_PATH" ]; then
85
+	# check if the container is on a mounted device
86
+	check_mounted $CONTAINER_PATH
87
+
88
+	if [ $? -gt 0 ]; then
89
+		# failed
90
+		exit 1
91
+	fi
92
+
93
+	# check if the device is writable
94
+	check_writable $CONTAINER_PATH
95
+
96
+	if [ $? -gt 0 ]; then
97
+		# failed
98
+		exit 1
99
+	fi
100
+fi
101
+