I'm working on a script that will detect which network interfaces are connected and mess with the routing accordingly, but I'm having trouble detecting whether my USB ethernet gadget connection is up or down. ---- ethtool when it's up: lisa:~# ethtool usb0 Settings for usb0: Link detected: yes ethtool when it's down: lisa:~# ethtool usb0 Settings for usb0: Link detected: yes ---- Unlike on the host side, the usb0 interface doesn't appear and disappear, allowing udev scripts to bring up/down the interface. Anyone know if there's a way to detect that a network connection has actually been established? -- Daniel Benoy http://daniel.benoy.name _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
which kernel ? you might want to check this one: /sys/class/net/usb0/operstate F. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
The best way to do this is to listen for netlink route announcements. That way it's completely instantaneous and without polling. Look here for an example using python-netlink: http://git.freesmartphone.org/?p=framework.git;a=blob;f=tools/dump-netlink Note that if you're on FSO I expect that after full integration of connman (milestone6), we will have a global signal like org.freesmartphone.Network.ConnectionStatus( s:means, b:online ) 'means' being a string that indicates the type, like "GPRS/ppp", "IP/usb0", "IP/bnep0", etc. _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
I just tried that python script, and it shows an event when I connect my USB cable, but not when I disconnect it. _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
I opened a ticket on that a while ago... https://docs.openmoko.org/trac/ticket/2178 No progress in 3 months... _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
Is this necessary? Just set a higher metric on usb0, then routes thorough eth0 will be preferred when available. The default route through usb0 will only be used as a last resort when there is no other way. Such a setup works very well on my laptop. It doesn't on the freerunner yet, because the "ip" utility in busybox currently can't set metrics. But port that (or use debian with its binary ip utility) and you'll be fine. Helge Hafting _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
On Fri, 06 Mar 2009 11:04:40 +0100 You should be able to find iproute2 for freerunner... I know I've got an ipk of 2.2.26 at http://newkirk.us/om - my "OM stuff" attic, but I think it's in the feeds as well. Apart from that, I dug into this exact situation before, including dealing with usb0, wrote an article about it at my blog. (http://jthinks.com/better-freerunner-networking) You can use the standard 'route' command to set metrics, so iproute2 isn't required. j _______________________________________________ Openmoko community mailing list community@lists.openmoko.org http://lists.openmoko.org/mailman/listinfo/community
Yes. Packets will route out that interface whether it's connected or not because it never disappears even when the cable is completely unplugged, and I want (obviously) the usb0 interface to be a higher priority than my gprs interface, so every packet would go out usb0 if I set it to a preferable metric. Unless I brought the interface up and down manually when the cable is disconnected, which brings us back to the original problem. I eventually did come up with a solution to this. I check the charger state. If it detects a host it should be charging at 500mA. This doesn't prove that the network interface is successfully configured, but it's good enough for my purposes. If anyone's interested in seeing the convoluted script I had to make, I've attached it to this e-mail. Here's basically what it does for me: 1) Automatically brings up and down network interfaces. (Only for usb0 now. I took out eth0 wifi scanning because I found a way to do it outside of the script. And ppp0 I'm still handling manually.. may change that in the future) 2) Creates a routing table for each device with a default route out that device automatically by detecting changes to the main table made by ifup and other connection software. 3) Creates iptables rules automatically based on which interfaces are up and which are down, in accordance with my preferences. (xmpp and ssh always go out GPRS, because I want the connections to be unbroken when I roam away from my usb or wifi connection, and they're low bandwidth) The effect is that web browsing and such will switch over seamlessly when I come within range of my home network, while my instant messager never has its connection broken so long as it's in cell phone range. If you want to try the script as well you'll need some firewall rules, such as: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE iptables -t mangle -A OUTPUT -j ...
