View Single Post
Posts: 25 | Thanked: 12 times | Joined on Mar 2008 @ Warsaw, Poland
#1
I've made myself a script that enables internet connection tethering over usbnet (1) (yes, i don't like ppp) and made my laptop connect to the internet automatically when i connect the N900 over usb cable (2).
The problem is, that the iptables rule gets multiplied when i connect and disconnect from my N900. I tried finding a signal that'd get emited when the usb cable is unplugged, to remove the iptables rule there, but there appears to be none (tried watching "initctl events").
Any ideas? i wouldn't want to create dozens of useless iptables rules.

(1) File /etc/event.d/usbtether, the "G_NOKIA_READY" signal only gets actually emitted when one selects "pc suite mode", but that's not a problem.
Code:
start on G_NOKIA_READY

console output

script 
        ifconfig usb0 up 192.168.99.1/24
        modprobe ipt_MASQUERADE
        iptables -A POSTROUTING -t nat -o gprs0 -j MASQUERADE
        echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
end script
(2) File /etc/conf.d/net, topic relevant parts start with "if [[ "${IFACE}" = "usb0" ]]; then"
Code:
config_lan0=( "dhcp" )
config_usb0=( "noop" "noop" )
dhcpcd_lan0="-q -t 10"

modules_wlan0=( "wpa_supplicant" "iproute2" "!plug" )
dhcpcd_wlan0="-q -t 15"

config_ferret="dhcp"
config_nibylandia="dhcp"
config_avantis_wifi="dhcp"
#config_arach="10.0.4.10/24"
config_arach="dhcp"

preup() {
    if [[ "${IFACE}" = "lan0" ]]; then
        if [[ $(/sbin/iwconfig wlan0|awk '/ESSID:/ { gsub(/.*ESSID:/, ""); print $1 }') = "\"arach\"" ]]; then
	    eselect rc stop net.wlan0
	fi
    fi
    if [[ "${IFACE}" = "usb0" ]]; then
        /etc/init.d/net.lan0 status 2> /dev/null > /dev/null || \
            /etc/init.d/net.wlan0 status 2> /dev/null > /dev/null
        if [[ ! $? -eq 0 ]]; then
            ifconfig usb0 up 192.168.99.100/24
            route add default gw 192.168.99.1
            echo nameserver 8.8.8.8 > /etc/resolv.conf
            /usr/bin/sleep 5
            su - arachnist -c "ssh 192.168.99.1 dbus-send --type=method_call \
                --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect \
                \"'string:Plus GSM INTERNET GPRS'\" uint32:0"
        fi
    fi
}


predown() {
    if [[ "${IFACE}" = "lan0" ]]; then
        /etc/init.d/net.wlan0 status > /dev/null 2>&1 || \
	    eselect rc start net.wlan0
    fi
}

Last edited by arachnist; 2010-03-13 at 15:01.
 

The Following 2 Users Say Thank You to arachnist For This Useful Post: