4 STROK="remote IP address"
7 PPPD_PIDFILE="/var/run/umts_pppd.pid"
8 DESTS_FILE="/tmp/umts_dest_file"
9 FILE_TEMP_NID="/tmp/umts_temp_nid"
10 FILE_UMTS_INT="/tmp/umts_dev"
15 function set_umts_dev(){
17 echo $umts_dev > $FILE_UMTS_INT
20 function get_umts_dev(){
21 if [ -e $FILE_UMTS_INT ]; then
26 function unset_umts_dev(){
34 if [ -f /usr/bin/gcom ]; then
36 elif [ -f /usr/bin/comgt ]; then
39 echo "I couldn't find gcom"
45 for i in /dev/umts_modem /dev/umts_modem1; do
46 echo "Testing if the umts interface is present on the device $i..."
56 if ! [ $found == 0 ]; then
57 echo "I couldn't find the umts device. Make a symlink from it to /dev/umts_modem."
61 if ! grep "umts_table" /etc/iproute2/rt_tables > /dev/null 2>&1; then
62 echo "20 umts_table" >> /etc/iproute2/rt_tables
70 function get_temp_nid(){
75 #called when the connection is started
79 #DESTS_FILE contains added destinations
83 set_temp_nid $sliver_nid
87 cat $LOGF | grep "local"
92 #called when the connection is terminated
98 for i in `cat $DESTS_FILE`; do
99 del_destination $i $sliver > /dev/null 2>&1
102 rm $DESTS_FILE >/dev/null 2>&1
105 function start_umts(){
107 local sliver_nid=`get_nid $sliver`
111 echo "Already connected"
115 if [[ `get_umts_dev` == "" ]]; then
116 if [[ init_umts != 0 ]]; then
121 if ! [ -e `get_umts_dev` ]; then
122 echo "Umts interface is not present"
128 exec /usr/sbin/pppd nodetach `get_umts_dev` 460800 \
130 connect "/usr/sbin/chat -v \
133 ABORT '\nNO ANSWER\r' \
134 ABORT '\nRINGING\r\n\r\nRINGING\r' \
135 '' ATZ OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' OK \
136 ATD*99***1# CONNECT ''" > $LOGF &
138 echo $! > $PPPD_PIDFILE
140 sleep 5s; #waiting for the interface to establish the link
141 if grep "$STROK" $LOGF >/dev/null 2>&1; then
142 conn_on $sliver $sliver_nid
146 if grep "$STROK" $LOGF >/dev/null 2>&1; then
147 conn_on $sliver $sliver_nid
158 function stop_umts(){
160 local sliver_nid=`get_nid $sliver`
162 if ! [ -e $PPPD_PIDFILE ]; then
167 PID=`cat $PPPD_PIDFILE`;
169 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
170 conn_off $sliver $sliver_nid
178 cat $LOGF | grep "time"
185 function status_umts(){
187 if ! [ -e $PPPD_PIDFILE ]; then return 1; fi
189 PID=`cat $PPPD_PIDFILE`
191 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
198 #add the ppp interface from the slice - not used at the moment
199 function add_interface(){
200 local nid=`get_nid $1`
201 $NADDRESS --add --nid $nid --ip $PPP_INT >>$LOGFILE 2>&1;
204 #remove the ppp interface from the slice - not used at the moment
205 function del_interface(){
206 local nid=`get_nid $1`
207 #$NADDRESS --remove --nid $NID --ip $PPP_INT >>$LOGFILE 2>&1;
210 #get slice network id
215 function set_routes(){
217 local sliver_nid=`get_nid $sliver`
218 local temp_nid=`get_temp_nid`
219 local ppp_addr=`get_ppp_address`
221 #remarking of packets, to trigger rerouting, and SNAT
222 iptables -t mangle -A OUTPUT -j MARK --copy-xid 0x00
223 iptables -t mangle -A OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
224 iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr
225 iptables -t mangle -I POSTROUTING 1 -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
227 #forbids other slices to use the UMTS interface
228 iptables -t nat -I POSTROUTING 1 -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP
230 #enable the explicit bind to the ppp interface
231 ip route flush table umts_table >/dev/null 2>&1
232 ip rule add from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1
233 ip route add default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1
234 ip route flush cache >/dev/null 2>&1
237 function unset_routes(){
239 local sliver_nid=`get_nid $sliver`
240 local temp_nid=`get_temp_nid`
241 local ppp_addr=`get_ppp_address`
243 #remarking and SNAT removed
244 iptables -t mangle -D OUTPUT -j MARK --copy-xid 0x00
245 iptables -t mangle -D OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
246 iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr
247 iptables -t mangle -D POSTROUTING -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
249 iptables -t nat -D POSTROUTING -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP
251 #disable the explicit bind to the ppp interface
252 ip rule del from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1
253 ip route del default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1
254 ip route flush cache >/dev/null 2>&1
258 function add_destination(){
261 local sliver_nid=`get_nid $sliver`
262 local temp_nid=`get_temp_nid`
264 if [[ ! $dest ]]; then return 1; fi
266 if ! status_umts; then
270 if ip rule add to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
271 echo "$dest" >> $DESTS_FILE
276 ip route flush cache >/dev/null 2>&1
279 function del_destination(){
282 local sliver_nid=`get_nid $sliver`
283 local temp_nid=`get_temp_nid`
285 if [[ ! $dest ]]; then return 1; fi
286 if ip rule del to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
291 ip route flush cache >/dev/null 2>&1
295 function get_ppp_address(){
296 ifconfig $PPP_INT | grep inet\ addr | cut -d ":" -f 2 | cut -d " " -f 1
299 function set_temp_nid(){
301 local temp_nid=$((0x20000+$sliver_nid))
304 #while grep :$temp_nid: /etc/passwd; do
305 # temp_nid=$((temp_nid+1))
307 # if [[ $k == 1000 ]]; then
308 # logger "Fatal error: I couldn't find a temp_nid"
313 echo $temp_nid > $FILE_TEMP_NID
318 # checks ip addresses
319 function valid_dotted_quad(){
329 ""|*[!0-9]*) return 1; break ;; ## Segment empty or non-numeric char
330 *) [ $seg -gt 255 ] && return 2 ;;
334 return 3 ## Not 4 segments