3 # OCF RA for tunctl(1) TUN/TAP device initialization
5 # Copyright (c) 2008,2009 Barton IT-Consulting
6 # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Brée
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.
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.
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.
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.
30 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
32 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
38 <resource-agent name="TunCtl">
39 <version>1.1</version>
42 OCF RA for tunctl(1) TUN/TAP device initialization.
44 <shortdesc lang="en">TUN/TAP device initialization</shortdesc>
47 <parameter name="if_name" unique="1">
48 <longdesc lang="en">Name of TUN/TAP interface</longdesc>
49 <shortdesc lang="en">Name of TUN/TAP interface</shortdesc>
50 <content type="string" default="" />
52 <parameter name="if_owner" unique="1">
53 <longdesc lang="en">TUN/TAP interface owner</longdesc>
54 <shortdesc lang="en">TUN/TAP interface owner</shortdesc>
55 <content type="string" default="" />
57 <parameter name="host_ip" unique="1">
58 <longdesc lang="en">Host-side IP address</longdesc>
59 <shortdesc lang="en">Host-side IP address</shortdesc>
60 <content type="string" default="" />
62 <parameter name="host_netmask" unique="1">
63 <longdesc lang="en">Host-side netmask</longdesc>
64 <shortdesc lang="en">Host-side netmask</shortdesc>
65 <content type="string" default="" />
67 <parameter name="client_ip" unique="1">
68 <longdesc lang="en">Client-side IP address</longdesc>
69 <shortdesc lang="en">Client-side IP address</shortdesc>
70 <content type="string" default="" />
72 <parameter name="if_proxyarp" unique="1">
73 <longdesc lang="en">Interface for Proxy-ARP</longdesc>
74 <shortdesc lang="en">Interface for Proxy-ARP</shortdesc>
75 <content type="string" default="" />
80 <action name="start" timeout="10" />
81 <action name="stop" timeout="10" />
82 <action name="monitor" timeout="10" interval="15" depth="0" start-delay="5" />
83 <action name="meta-data" timeout="5" />
84 <action name="validate-all" timeout="30" />
90 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
93 echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
97 tunctl -u "${OCF_RESKEY_if_owner:-root}" -t "$OCF_RESKEY_if_name"
99 return $OCF_ERR_GENERIC
101 ifconfig "$OCF_RESKEY_if_name" "$OCF_RESKEY_host_ip" \
102 netmask "${OCF_RESKEY_host_netmask:-255.255.255.0}" up
103 if [ $? -ne 0 ]; then
104 return $OCF_ERR_GENERIC
106 echo 1 >/proc/sys/net/ipv4/ip_forward
107 route add -host "$OCF_RESKEY_client_ip" dev "$OCF_RESKEY_if_name"
108 if [ $? -ne 0 ]; then
109 return $OCF_ERR_GENERIC
111 if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
113 echo 1 >/proc/sys/net/ipv4/conf/"$OCF_RESKEY_if_name"/proxy_arp
114 if [ $? -ne 0 ]; then
115 return $OCF_ERR_GENERIC
117 arp -Ds "$OCF_RESKEY_client_ip" "$OCF_RESKEY_if_proxyarp" pub
118 if [ $? -ne 0 ]; then
119 return $OCF_ERR_GENERIC
126 if [ -n "$OCF_RESKEY_if_proxyarp" ]; then
128 arp -d "$OCF_RESKEY_client_ip" -i "$OCF_RESKEY_if_proxyarp" pub
130 ifconfig "$OCF_RESKEY_if_name" down >/dev/null 2>&1
131 tunctl -d "$OCF_RESKEY_if_name"
132 if [ $? -eq 0 ]; then
135 return $OCF_ERR_GENERIC
139 ip link show "$OCF_RESKEY_if_name" | grep "UP" >/dev/null 2>&1
140 if [ $? -eq 0 ]; then
143 return $OCF_NOT_RUNNING
147 if [ -z "$OCF_RESKEY_if_name" ]; then
150 if [ -z "$OCF_RESKEY_host_ip" ]; then
153 if [ -z "$OCF_RESKEY_client_ip" ]; then
159 case $__OCF_ACTION in
182 exit $OCF_ERR_UNIMPLEMENTED
187 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"