4 PPPD_PIDFILE=/var/run/umts_pppd.pid
8 STROK="remote IP address"
16 DESTS_FILE="/tmp/umts_dest_file"
18 FILE_TEMP_NID="/tmp/umts_temp_nid"
20 FILE_UMTS_INT="/var/run/umts_int"
23 function set_umts_dev(){
24 echo $1 > $FILE_UMTS_INT
27 function get_umts_dev(){
32 function start_gcom(){
33 if ! $GCOM -d `get_umts_dev`; then
46 if [ -f /usr/bin/gcom ]; then
48 elif [ -f /usr/bin/comgt ]; then
51 echo "I couldn't find gcom"
55 for i in /dev/umts_modem /dev/umts_modem1; do
56 echo "Testing if the umts interface is present on the device $i..."
64 if ! [ $found == 0 ]; then
65 echo "I couldn't find the umts device; make a symlink from it to /dev/umts_modem"
69 if ! grep umts_table /etc/iproute2/rt_tables > /dev/null 2>&1; then
70 echo "20 umts_table" >> /etc/iproute2/rt_tables
80 function get_temp_nid(){
85 function workaround_on(){
89 iptables -t mangle -A OUTPUT -j MARK --copy-xid 0x00
90 iptables -t mangle -A OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
91 iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address`
92 iptables -t mangle -I POSTROUTING 1 -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
94 # iptables -t mangle -D POSTROUTING -j MARK --copy-xid 0x00
95 # iptables -t mangle -I POSTROUTING 1 ! -p icmp -j MARK --copy-xid 0x00
99 function workaround_off(){
103 iptables -t mangle -D OUTPUT -j MARK --copy-xid 0x00
104 iptables -t mangle -D OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid
105 iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address`
106 iptables -t mangle -D POSTROUTING -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid
108 # iptables -t mangle -I POSTROUTING 1 -j MARK --copy-xid 0x00
109 # iptables -t mangle -D POSTROUTING ! -p icmp -j MARK --copy-xid 0x00
112 #called when the connection is up
120 touch $DESTS_FILE > /dev/null 2>&1
123 set_temp_nid $sliver_nid
124 local temp_nid=`get_temp_nid`
129 workaround_on $sliver_nid $temp_nid
131 cat $LOGF | grep "local"
136 #called when the connection is down
141 temp_nid=`get_temp_nid`
142 workaround_off $sliver_nid $temp_nid
148 function start_umts(){
150 local sliver_nid=`get_nid $sliver`
154 echo "Already connected"
158 if ! [ -c `get_umts_dev` ]; then
159 echo "Umts interface not present"
165 exec /usr/sbin/pppd nodetach `get_umts_dev` 460800 \
167 connect "/usr/sbin/chat -v \
170 ABORT '\nNO ANSWER\r' \
171 ABORT '\nRINGING\r\n\r\nRINGING\r' \
172 '' ATZ OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' OK \
173 ATD*99***1# CONNECT ''" > $LOGF &
175 echo $! > $PPPD_PIDFILE
178 sleep 5s; #waiting for the interface to establish the link
179 if grep "$STROK" $LOGF >/dev/null 2>&1; then
181 conn_on $sliver $sliver_nid
185 if grep "$STROK" $LOGF >/dev/null 2>&1; then
186 conn_on $sliver $sliver_nid
197 function stop_umts(){
200 if ! [ -e $PPPD_PIDFILE ]; then
205 PID=`cat $PPPD_PIDFILE`;
207 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
209 conn_off $sliver `get_nid $sliver`
217 cat $LOGF | grep "time"
224 function status_umts(){
226 if ! [ -e $PPPD_PIDFILE ]; then return 1; fi
228 PID=`cat $PPPD_PIDFILE`
230 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
237 #add the ppp interface from the slice - not used at the moment
238 function add_interface(){
239 local nid=`get_nid $1`
240 $NADDRESS --add --nid $nid --ip $PPP_INT >>$LOGFILE 2>&1;
243 #remove the ppp interface from the slice - not used at the moment
244 function del_interface(){
245 #not working yet because of naddress incompleteness
246 local nid=`get_nid $1`
247 #$NADDRESS --remove --nid $NID --ip $PPP_INT >>$LOGFILE 2>&1;
250 #get slice network id needed by naddress
252 #NIDFILE="/usr/local/etc/vservers/${1}/context"
257 #enable the explicit bind to the ppp interface
258 function set_routes(){
260 local sliver_nid=`get_nid $sliver`
261 PPP_ADDR=`get_ppp_address`
264 ip route flush table umts_table >/dev/null 2>&1
266 # OLD ip rule add from $PPP_ADDR fwmark $sliver_nid table umts_table >/dev/null 2>&1
267 ip rule add from $PPP_ADDR fwmark `get_temp_nid` table umts_table >/dev/null 2>&1
269 ip route add default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1
270 ip route flush cache >/dev/null 2>&1
273 #disable the explicit bind to the ppp interface
274 function unset_routes(){
276 local sliver_nid=`get_nid $sliver`
277 local ppp_addr=`get_ppp_address`
279 ip rule del from $ppp_addr fwmark `get_temp_nid` table umts_table >/dev/null 2>&1
280 ip route del default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1
281 ip route flush cache >/dev/null 2>&1
283 for i in `cat $DESTS_FILE`; do
284 del_destination $i $sliver > /dev/null 2>&1
287 rm $DESTS_FILE >/dev/null 2>&1
291 function add_destination(){
295 local sliver_nid=`get_nid $sliver`
297 local temp_nid=`get_temp_nid`
299 if [[ ! $dest ]]; then return 1; fi
301 if ! status_umts; then
305 #old - if ip route add to "$dest" dev $PPP_INT >/dev/null 2>&1 ; then
306 if ip rule add to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
307 echo "$dest" >> $DESTS_FILE
312 ip route flush cache >/dev/null 2>&1
315 function del_destination(){
319 local sliver_nid=`get_nid $sliver`
321 local temp_nid=`get_temp_nid`
323 if [[ ! $dest ]]; then return 1; fi
324 #old - if ip route del to "$dest" dev $PPP_INT >/dev/null 2>&1; then
325 if ip rule del to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then
330 ip route flush cache >/dev/null 2>&1
334 function get_ppp_address(){
335 ifconfig $PPP_INT | grep inet\ addr | cut -d ":" -f 2 | cut -d " " -f 1
338 function set_temp_nid(){
340 temp_nid=$((0x20000+$sliver_nid))
344 #temp_nid=$sliver_nid
346 #while grep :$temp_nid: /etc/passwd; do
347 # temp_nid=$((temp_nid+1))
349 # if [[ $k == 1000 ]]; then
350 # logger "Fatal error: I couldn't find a temp_nid"
356 echo $temp_nid > $FILE_TEMP_NID
362 function valid_dotted_quad(){
372 ""|*[!0-9]*) return 1; break ;; ## Segment empty or non-numeric char
373 *) [ $seg -gt 255 ] && return 2 ;;
377 return 3 ## Not 4 segments