]> arthur.barton.de Git - ocf-ra.git/blob - TunCtl
OCFS2_DRBD: verify-all should be validate-all ...
[ocf-ra.git] / TunCtl
1 #!/bin/sh
2 #
3 # OCF RA for tunctl(1) TUN/TAP device initialization
4 #
5 # Copyright (c) 2008,2009 Barton IT-Consulting
6 # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-BrĂ©e
7 #                    All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 #
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 #
28
29 # Initialization:
30 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
31
32 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33
34 meta_data() {
35         cat <<END
36 <?xml version="1.0"?>
37 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
38 <resource-agent name="TunCtl">
39 <version>1.1</version>
40
41 <longdesc lang="en">
42 OCF RA for tunctl(1) TUN/TAP device initialization.
43 </longdesc>
44 <shortdesc lang="en">TUN/TAP device initialization</shortdesc>
45
46 <parameters>
47 <parameter name="if_name" unique="1">
48 <shortdesc lang="en">Name of TUN/TAP interface</shortdesc>
49 <content type="string" default="" />
50 </parameter>
51 <parameter name="if_owner" unique="1">
52 <shortdesc lang="en">TUN/TAP interface owner</shortdesc>
53 <content type="string" default="" />
54 </parameter>
55 <parameter name="host_ip" unique="1">
56 <shortdesc lang="en">Host-side IP address</shortdesc>
57 <content type="string" default="" />
58 </parameter>
59 <parameter name="host_netmask" unique="1">
60 <shortdesc lang="en">Host-side netmask</shortdesc>
61 <content type="string" default="" />
62 </parameter>
63 <parameter name="client_ip" unique="1">
64 <shortdesc lang="en">Client-side IP address</shortdesc>
65 <content type="string" default="" />
66 </parameter>
67 <parameter name="if_proxyarp" unique="1">
68 <shortdesc lang="en">Interface for Proxy-ARP</shortdesc>
69 <content type="string" default="" />
70 </parameter>
71 </parameters>
72
73 <actions>
74 <action name="start" timeout="10" />
75 <action name="stop" timeout="10" />
76 <action name="monitor" timeout="10" interval="15" depth="0" start-delay="5" />
77 <action name="meta-data" timeout="5" />
78 <action name="verify-all" timeout="30" />
79 </actions>
80 </resource-agent>
81 END
82 }
83
84 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85
86 TunCtl_usage() {
87         echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
88 }
89
90 TunCtl_start() {
91         tunctl -u "${OCF_RESKEY_if_owner:-root}" -t "$OCF_RESKEY_if_name"
92         if [ $? -ne 0 ]; then
93                 return $OCF_ERR_GENERIC
94         fi
95         ifconfig "$OCF_RESKEY_if_name" "$OCF_RESKEY_host_ip" \
96          netmask "${OCF_RESKEY_host_netmask:-255.255.255.0}" up
97         if [ $? -ne 0 ]; then
98                 return $OCF_ERR_GENERIC
99         fi
100         echo 1 >/proc/sys/net/ipv4/ip_forward
101         route add -host "$OCF_RESKEY_client_ip" dev "$OCF_RESKEY_if_name"
102         if [ $? -ne 0 ]; then
103                 return $OCF_ERR_GENERIC
104         fi
105         if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
106                 # Proxy ARP
107                 echo 1 >/proc/sys/net/ipv4/conf/"$OCF_RESKEY_if_name"/proxy_arp
108                 if [ $? -ne 0 ]; then
109                         return $OCF_ERR_GENERIC
110                 fi
111                 arp -Ds "$OCF_RESKEY_client_ip" "$OCF_RESKEY_if_proxyarp" pub
112                 if [ $? -ne 0 ]; then
113                         return $OCF_ERR_GENERIC
114                 fi
115         fi
116         return $OCF_SUCCESS
117 }
118
119 TunCtl_stop() {
120         if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
121                 # Proxy ARP
122                 arp -d "$OCF_RESKEY_client_ip" -i "$OCF_RESKEY_if_proxyarp" pub
123         fi
124         ifconfig "$OCF_RESKEY_if_name" down >/dev/null 2>&1
125         tunctl -d "$OCF_RESKEY_if_name"
126         if [ $? -eq 0 ]; then
127                 return $OCF_SUCCESS
128         fi
129         return $OCF_ERR_GENERIC
130 }
131
132 TunCtl_monitor() {
133         ip link show "$OCF_RESKEY_if_name" | grep "UP" >/dev/null 2>&1
134         if [ $? -eq 0 ]; then
135                 return $OCF_SUCCESS
136         fi
137         return $OCF_NOT_RUNNING
138 }
139
140 TunCtl_validate() {
141         if [ -z "$OCF_RESKEY_if_name" ]; then
142                 return $OCF_ERR_ARGS
143         fi
144         if [ -z "$OCF_RESKEY_host_ip" ]; then
145                 return $OCF_ERR_ARGS
146         fi
147         if [ -z "$OCF_RESKEY_client_ip" ]; then
148                 return $OCF_ERR_ARGS
149         fi
150         return $OCF_SUCCESS
151 }
152
153 case $__OCF_ACTION in
154         meta-data)
155                 meta_data
156                 exit $OCF_SUCCESS
157                 ;;
158         start)
159                 TunCtl_start
160                 ;;
161         stop)
162                 TunCtl_stop
163                 ;;
164         monitor)
165                 TunCtl_monitor
166                 ;;
167         validate-all)
168                 TunCtl_validate
169                 ;;
170         usage|help)
171                 TunCtl_usage
172                 exit $OCF_SUCCESS
173                 ;;
174         *)
175                 TunCtl_usage
176                 exit $OCF_ERR_UNIMPLEMENTED
177                 ;;
178 esac
179
180 rc=$?
181 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
182 exit $rc
183
184 # -eof-