From 46cf404603955fa122ad50cfe9a72b82491f9b4d Mon Sep 17 00:00:00 2001 From: giovanni Date: Wed, 29 Oct 2008 17:42:52 +0000 Subject: [PATCH] umts can be enabled on more than a sliver --- backend.spec | 4 +- backend/ChangeLog | 3 +- backend/Makefile | 2 +- backend/VERSION | 2 +- backend/{umts => umts.init} | 0 backend/umts_backend | 6 +- backend/umts_functions | 126 +++++++++++++++++++++++++++++++----- frontend.spec | 4 +- frontend/README.PI | 2 +- frontend/umts.c | 2 + 10 files changed, 124 insertions(+), 27 deletions(-) rename backend/{umts => umts.init} (100%) diff --git a/backend.spec b/backend.spec index 578ece0..cbcc4bb 100644 --- a/backend.spec +++ b/backend.spec @@ -1,8 +1,8 @@ %define module_taglevel_varname release %define name planetlab-umts-tools-backend -%define version 0.5 -%define release 4 +%define version 0.6 +%define release 1 Summary: Umts-tools for PlanetLab - backend part Name: %{name} diff --git a/backend/ChangeLog b/backend/ChangeLog index 222c2ca..14abf6f 100644 --- a/backend/ChangeLog +++ b/backend/ChangeLog @@ -1,4 +1,5 @@ - +0.6 - Giovanni Di Stasi +* More than a sliver allowed to use the UMTS interface (one at a time) 0.4 - Giovanni Di Stasi diff --git a/backend/Makefile b/backend/Makefile index 4cdfc87..628eff8 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -4,7 +4,7 @@ install: install -D umts_functions ${prefix}/usr/lib/umts_functions install -D umts_backend ${prefix}/vsys/umts_backend install -D 96-umts-tools.rules ${prefix}/etc/udev/rules.d/96-umts-tools.rules - install -D umts ${prefix}/etc/rc.d/init.d/umts + install -D umts.init ${prefix}/etc/rc.d/init.d/umts clean: find . -name "*~" -exec rm \{} \; diff --git a/backend/VERSION b/backend/VERSION index 2eb3c4f..5a2a580 100644 --- a/backend/VERSION +++ b/backend/VERSION @@ -1 +1 @@ -0.5 +0.6 diff --git a/backend/umts b/backend/umts.init similarity index 100% rename from backend/umts rename to backend/umts.init diff --git a/backend/umts_backend b/backend/umts_backend index 29f7a53..2a4960a 100755 --- a/backend/umts_backend +++ b/backend/umts_backend @@ -72,8 +72,10 @@ case "$command" in ;; status) - if status_umts; then - echo "Connected" + if status_umts $sliver; then + if check_who_locked $sliver; then + echo "Connected" + fi else echo "Disconnected" fi diff --git a/backend/umts_functions b/backend/umts_functions index 9c7fc5d..2ed7a0b 100644 --- a/backend/umts_functions +++ b/backend/umts_functions @@ -8,8 +8,10 @@ PPPD_PIDFILE="/var/run/umts_pppd.pid" DESTS_FILE="/tmp/umts_dest_file" FILE_TEMP_NID="/tmp/umts_temp_nid" FILE_UMTS_INT="/tmp/umts_dev" -PPP_INT=ppp0 -PPPD=pppd +LOCK_DIR="/var/run/umts_lock" +FILE_LOCK_SLIVER="/var/run/umts_locking_sliver" +PPP_INT="ppp0" +PPPD="pppd" function set_umts_dev(){ @@ -41,6 +43,10 @@ function init_umts(){ fi unset_umts_dev + + if [ -e $LOCK_DIR ]; then + rmdir $LOCK_DIR + fi for i in /dev/umts_modem /dev/umts_modem1; do echo "Testing if the umts interface is present on the device $i..." @@ -78,7 +84,6 @@ function conn_on(){ #DESTS_FILE contains added destinations rm -f $DESTS_FILE - touch $DESTS_FILE set_temp_nid $sliver_nid @@ -92,8 +97,9 @@ function conn_on(){ #called when the connection is terminated function conn_off(){ local sliver=$1 + local ppp_addr=$2 - unset_routes $sliver + unset_routes $sliver $ppp_addr for i in `cat $DESTS_FILE`; do del_destination $i $sliver > /dev/null 2>&1 @@ -105,8 +111,11 @@ function conn_off(){ function start_umts(){ local sliver=$1 local sliver_nid=`get_nid $sliver` - - + + if ! lock $sliver; then + return 1 + fi + if status_umts; then echo "Already connected" return 0; @@ -158,44 +167,54 @@ function start_umts(){ function stop_umts(){ local sliver=$1 local sliver_nid=`get_nid $sliver` + local ppp_addr if ! [ -e $PPPD_PIDFILE ]; then echo "Disconnected" return 0; fi + ppp_addr=`get_ppp_address` + + if ! check_who_locked $sliver; then + return 1 + fi + PID=`cat $PPPD_PIDFILE`; if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then - conn_off $sliver $sliver_nid - kill $PID; + kill $PID; touch $DESTS_FILE + sleep 2s; fi if status_umts; then return 1; else + conn_off $sliver $ppp_addr cat $LOGF | grep "time" rm $PPPD_PIDFILE + unlock $sliver; return 0 fi } function status_umts(){ - + local sliver=$1 + if ! [ -e $PPPD_PIDFILE ]; then return 1; fi PID=`cat $PPPD_PIDFILE` if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then - return 0; + return 0; else return 1; fi } -#add the ppp interface from the slice - not used at the moment +#add the ppp interface to the slice - not used at the moment function add_interface(){ local nid=`get_nid $1` $NADDRESS --add --nid $nid --ip $PPP_INT >>$LOGFILE 2>&1; @@ -222,12 +241,14 @@ function set_routes(){ iptables -t mangle -A OUTPUT -j MARK --copy-xid 0x00 iptables -t mangle -A OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr + + #restores the original mark iptables -t mangle -I POSTROUTING 1 -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid #forbids other slices to use the UMTS interface - iptables -t nat -I POSTROUTING 1 -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP + iptables -t mangle -I POSTROUTING 2 -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP - #enable the explicit bind to the ppp interface + #enables the explicit bind to the ppp interface ip route flush table umts_table >/dev/null 2>&1 ip rule add from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1 ip route add default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1 @@ -236,9 +257,10 @@ function set_routes(){ function unset_routes(){ local sliver=$1 + local ppp_addr=$2 local sliver_nid=`get_nid $sliver` local temp_nid=`get_temp_nid` - local ppp_addr=`get_ppp_address` + #remarking and SNAT removed iptables -t mangle -D OUTPUT -j MARK --copy-xid 0x00 @@ -246,11 +268,11 @@ function unset_routes(){ iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr iptables -t mangle -D POSTROUTING -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid - iptables -t nat -D POSTROUTING -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP + iptables -t mangle -D POSTROUTING -o $PPP_INT -m mark ! --mark $sliver_nid -j DROP #disable the explicit bind to the ppp interface ip rule del from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1 - ip route del default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1 + #ip route del default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1 ip route flush cache >/dev/null 2>&1 } @@ -266,7 +288,11 @@ function add_destination(){ if ! status_umts; then return 1; fi - + + if ! check_who_locked $sliver; then + return 1; + fi + if ip rule add to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then echo "$dest" >> $DESTS_FILE return 0 @@ -283,6 +309,11 @@ function del_destination(){ local temp_nid=`get_temp_nid` if [[ ! $dest ]]; then return 1; fi + + if ! check_who_locked $sliver; then + return 1; + fi + if ip rule del to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then return 0; else @@ -315,6 +346,67 @@ function set_temp_nid(){ } +function check_who_locked(){ + local sliver=$1 + local sliver_nid=`get_nid $sliver` + local ret=0 + + if [ -e $LOCK_DIR ]; then + if [[ `cat $FILE_LOCK_SLIVER` != $sliver_nid ]]; then + echo "Interface in use by another slice."; + ret=1 + fi + else + ret=1 + fi + + return $ret + +} + +function lock(){ + local sliver=$1 + local sliver_nid=`get_nid $sliver` + local ret=0 + + if [ -e $LOCK_DIR ]; then + if ! check_who_locked $sliver; then + ret=1 + fi + else + if mkdir $LOCK_DIR >/dev/null 2>&1; then + echo "$sliver_nid" > $FILE_LOCK_SLIVER + else + ret=1 + fi + fi + + return $ret +} + +function unlock(){ + local sliver=$1 + local sliver_nid=`get_nid $sliver` + local ret=0 + + if ! [ -e $LOCK_DIR ]; then + ret=1 + else + if ! check_who_locked $sliver; then + ret=1 + else + if ! rmdir $LOCK_DIR; then + ret=1 + fi + fi + fi + + return $ret +} + + + + # checks ip addresses function valid_dotted_quad(){ oldIFS=$IFS diff --git a/frontend.spec b/frontend.spec index 4ffb9ae..9e7a7da 100644 --- a/frontend.spec +++ b/frontend.spec @@ -1,8 +1,8 @@ %define module_taglevel_varname release %define name planetlab-umts-tools-frontend -%define version 0.5 -%define release 4 +%define version 0.6 +%define release 1 Summary: UMTS tools for PlanetLab Name: %{name} diff --git a/frontend/README.PI b/frontend/README.PI index 614e715..fa86e2f 100644 --- a/frontend/README.PI +++ b/frontend/README.PI @@ -8,7 +8,7 @@ umts/hsdpa interface. First, you have to add your node to the nodegroup "umts" [1]. In this way the host environment of the node will get the tools needed to manage the 3G umts/hsdpa interface. Then, you have to add the vsys -attribute to the sliver you want to grant the access to the umts/hsdpa +attribute to the slivers you want to grant the access to the umts/hsdpa interface. The value of this attribute ("vsys") has to be set to "umts_backend" diff --git a/frontend/umts.c b/frontend/umts.c index 09455e8..1c8dd2c 100644 --- a/frontend/umts.c +++ b/frontend/umts.c @@ -27,6 +27,8 @@ #include "umts.h" +// vsys frontend + //#define DEBUG int vfd0, vfd1; -- 2.43.0