3 PPPD_PIDFILE=/var/run/umts_pppd.pid
7 STROK="remote IP address"
15 DESTS_FILE="/tmp/umts_dest_file"
17 FILE_TEMP_NID="/tmp/umts_temp_nid"
19 FILE_UMTS_INT="/tmp/umts_dev"
22 function set_umts_dev(){
23 echo $1 > $FILE_UMTS_INT
26 function get_umts_dev(){
31 function start_gcom(){
32 if ! $GCOM -d `get_umts_dev`; then
45 if [ -f /usr/bin/gcom ]; then
47 elif [ -f /usr/bin/comgt ]; then
50 echo "I couldn't find gcom"
54 for i in /dev/umts_modem /dev/umts_modem1; do
55 echo "Testing if the umts interface is present on the device $i..."
63 if ! [ $found == 0 ]; then
64 echo "I couldn't find the umts device; make a symlink from it to /dev/umts_modem"
68 if ! grep umts_table /etc/iproute2/rt_tables > /dev/null 2>&1; then
69 echo "20 umts_table" >> /etc/iproute2/rt_tables
77 function get_temp_nid(){
82 #called when the connection is started
87 #DESTS_FILE contains added destinations
89 touch $DESTS_FILE > /dev/null 2>&1
91 set_temp_nid $sliver_nid
95 cat $LOGF | grep "local"
100 #called when the connection is terminated
107 for i in `cat $DESTS_FILE`; do
108 del_destination $i $sliver > /dev/null 2>&1
111 rm $DESTS_FILE >/dev/null 2>&1
114 function start_umts(){
116 local sliver_nid=`get_nid $sliver`
120 echo "Already connected"
124 if ! [ -c `get_umts_dev` ]; then
125 echo "Umts interface not present"
131 exec /usr/sbin/pppd nodetach `get_umts_dev` 460800 \
133 connect "/usr/sbin/chat -v \
136 ABORT '\nNO ANSWER\r' \
137 ABORT '\nRINGING\r\n\r\nRINGING\r' \
138 '' ATZ OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' OK \
139 ATD*99***1# CONNECT ''" > $LOGF &
141 echo $! > $PPPD_PIDFILE
144 sleep 5s; #waiting for the interface to establish the link
145 if grep "$STROK" $LOGF >/dev/null 2>&1; then
147 conn_on $sliver $sliver_nid
151 if grep "$STROK" $LOGF >/dev/null 2>&1; then
152 conn_on $sliver $sliver_nid
163 function stop_umts(){
166 if ! [ -e $PPPD_PIDFILE ]; then
171 PID=`cat $PPPD_PIDFILE`;
173 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
175 conn_off $sliver `get_nid $sliver`
183 cat $LOGF | grep "time"
190 function status_umts(){
192 if ! [ -e $PPPD_PIDFILE ]; then return 1; fi
194 PID=`cat $PPPD_PIDFILE`
196 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
203 #add the ppp interface from the slice - not used at the moment
204 function add_interface(){
205 local nid=`get_nid $1`
206 $NADDRESS --add --nid $nid --ip $PPP_INT >>$LOGFILE 2>&1;
209 #remove the ppp interface from the slice - not used at the moment
210 function del_interface(){
211 local nid=`get_nid $1`
212 #$NADDRESS --remove --nid $NID --ip $PPP_INT >>$LOGFILE 2>&1;
215 #get slice network id
220 function set_routes(){
222 local sliver_nid=`get_nid $sliver`
223 local temp_nid=`get_temp_nid`
224 local ppp_addr=`get_ppp_address`
226 #remarking of packets to trigger rerouting and SNAT
227 iptables -t mangle -A OUTPUT -j MARK --copy-xid 0x00
228 iptables -t mangle -A OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
229 iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address`
230 iptables -t mangle -I POSTROUTING 1 -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
232 #enable the explicit bind to the ppp interface
233 ip route flush table umts_table >/dev/null 2>&1
234 ip rule add from $ppp_addr fwmark `get_temp_nid` table umts_table >/dev/null 2>&1
235 ip route add default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1
236 ip route flush cache >/dev/null 2>&1
239 function unset_routes(){
241 local sliver_nid=`get_nid $sliver`
242 local temp_nid=`get_temp_nid`
243 local ppp_addr=`get_ppp_address`
245 #remarking and SNAT removed
246 iptables -t mangle -D OUTPUT -j MARK --copy-xid 0x00
247 iptables -t mangle -D OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
248 iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address`
249 iptables -t mangle -D POSTROUTING -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
251 #disable the explicit bind to the ppp interface
252 ip rule del from $ppp_addr fwmark `get_temp_nid` table umts_table >/dev/null 2>&1
253 ip route del default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1
254 ip route flush cache >/dev/null 2>&1
258 function add_destination(){
262 local sliver_nid=`get_nid $sliver`
264 local temp_nid=`get_temp_nid`
266 if [[ ! $dest ]]; then return 1; fi
268 if ! status_umts; then
272 if ip rule add to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
273 echo "$dest" >> $DESTS_FILE
278 ip route flush cache >/dev/null 2>&1
281 function del_destination(){
285 local sliver_nid=`get_nid $sliver`
287 local temp_nid=`get_temp_nid`
289 if [[ ! $dest ]]; then return 1; fi
290 #old - if ip route del to "$dest" dev $PPP_INT >/dev/null 2>&1; then
291 if ip rule del to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
296 ip route flush cache >/dev/null 2>&1
300 function get_ppp_address(){
301 ifconfig $PPP_INT | grep inet\ addr | cut -d ":" -f 2 | cut -d " " -f 1
304 function set_temp_nid(){
306 local temp_nid=$((0x20000+$sliver_nid))
309 #temp_nid=$sliver_nid
311 #while grep :$temp_nid: /etc/passwd; do
312 # temp_nid=$((temp_nid+1))
314 # if [[ $k == 1000 ]]; then
315 # logger "Fatal error: I couldn't find a temp_nid"
321 echo $temp_nid > $FILE_TEMP_NID
327 function valid_dotted_quad(){
337 ""|*[!0-9]*) return 1; break ;; ## Segment empty or non-numeric char
338 *) [ $seg -gt 255 ] && return 2 ;;
342 return 3 ## Not 4 segments