pigeond pigeond

pigeon's blog - the pigeon concerto in D minor

< older blogs newer blogs >

First post! In my new blog system…
2008/01/26 08:36:09
personal software

I’ve finally done it. I’ve replaced my old blog system.

Unfortunately for anyone who has subscribed to my rss feed, your reader will probably see all old posts appearing as new ones. I apologies if this causes any troubles.

permlink :: trackback :: Comments Off

Bonding – switching network interface without losing connections
2007/02/12 17:48:19
linux software

There’s wireless setup at my wife’s home in Taiwan. But whenever I’m upstairs in our room I prefer using the wired connection. While when I’m downstairs I have no choice as there’s no extra ethernet port.

Switching between the two networks is not a big deal. And with the help of ifplugd, the switching is automatic. But after all, they are two different interfaces. It would be good if I could switch between them without losing any existing connections. After a bit of googling around, I’ve found one solution: Ethernet channel bonding.

From the Linux source code Documentation/networking/bonding.txt: “The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical “bonded” interface”. In my case, I’m bonding the eth0 (wired) and the eth2 (wireless) together.

Under Debian, the bonding driver is built as a module bonding. I’ve also installed the ifenslave. So I put the bonding driver into my /etc/modules so it’s loaded at system startup:

bonding mode=1 miimon=500

where mode=1 sets the bonding mode to active-backup. The bonding driver also supports a few different load-balancing modes, which you might want to check out as well. miimon=500 sets the link check interval in milliseconds.

There’s also a primary parameter which you could specify which slave interface will always be used if it is available (e.g. primary=eth0).

The bonding driver gives you a new network interface bond0. Now to setup bond0, eth0 and eth2 in /etc/network/interfaces:

# the wired interface
iface eth0 inet manual
    hostname xxxxxxx

# the wireless interface
iface eth2 inet manual
    wireless-key s:xxxxxxxxxxxxx restricted
    wireless-essid xxxxxxxxxxxx
    wireless-mode managed

# the bonding interface, eth0 + eth2
iface bond0 inet dhcp
    pre-up ifconfig bond0 up
    pre-up ifenslave bond0 eth0 eth2
    pre-down ifenslave -d bond0 eth0 eth2

bond0 is set to use DHCP, while eth0 and eth2 are not, as they will act as slave interfaces. bond0 is the master. The 2nd pre-up command for bond0 attaches both eth0 and eth2 as slaves to the bonding device. Note that it is possible to configure a bonding device via sysfs, which is also documented in Documentation/network/bonding.txt.

While ifplugd takes care of eth0 going up and down, I also want to turn off the wireless completely when the wired network is plugged in. So I added my own script /etc/ifplugd/action.d/bonding:

set -e

if [ ! -f /proc/net/bonding/bond0 ]; then

case "$1" in
    case "$2" in
        /sbin/ifdown eth2
        /sbin/ifconfig eth2 down
        /sbin/iwconfig eth2 txpower off

        /sbin/iwconfig eth2 txpower auto
        /sbin/ifup eth2
        /sbin/ifconfig eth2 up

    # I need to do this sometimes, so I've put it in
    # or could someone comment on this?
    ifdown bond0
    ifup bond0


This script will turn off the wireless radio for me when my eth0 wired network is up.

I’m relying on ifplugd to bring up bond0, which will then bring up eth0 and eth2. Hence in /etc/network/interfaces I did not set any of the interfaces to be auto. I also added -l to the arguments of ifplugd in /etc/default/ifplugd:

ARGS="-q -f -u0 -d10 -w -I -l"

so that it will run the “down” script on ifplugd startup if no cable is detected. That way my script will bring up my wireless eth2 if eth0 is not plugged, say at boot time.

With this setup, the bonding driver automatically switches to use eth0 or eth2, whichever is brought up. In my setup, eth0 and eth2 won’t be up at the same time. If you use the primary parameter, the primary slave interface will always be used, even if the other slaves become available.

/proc/net/bonding/bond0 shows the status of the bonding interface. For example I’m now on the wireless network:

Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 500
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:11:2f:9c:57:25

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:11:2f:9c:57:25

It’s pretty obvious that the currently active slave is my eth2 wireless. I can run something like watch -n 1 cat /proc/net/bonding/bond0, and as I plug the ethernet cable back, the active slave will become eth0. You can also find out the currently active slave via /sys/class/net/bond0/bonding/active_slave.

For completeness, here is the output of ifconfig:

bond0     Link encap:Ethernet  HWaddr 00:11:2F:9C:57:25
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::211:2fff:fe9c:5725/64 Scope:Link
          RX packets:329306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:329010 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:732552585 (698.6 MiB)  TX bytes:204431117 (194.9 MiB)

eth0      Link encap:Ethernet  HWaddr 00:11:2F:9C:57:25
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:303936 errors:0 dropped:0 overruns:0 frame:0
          TX packets:304693 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:245381818 (234.0 MiB)  TX bytes:27905638 (26.6 MiB)
          Interrupt:5 Base address:0xd800

eth2      Link encap:Ethernet  HWaddr 00:11:2F:9C:57:25
          inet6 addr: fe80::211:2fff:fe9c:5725/64 Scope:Link
          RX packets:25370 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24317 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:487170767 (464.6 MiB)  TX bytes:176525479 (168.3 MiB)
          Interrupt:5 Base address:0xe000 Memory:ff9fe000-ff9fefff

which shows bond0 being the master, and eth0 and eth2 being slaves.

It almost makes plugging and unplugging the ethernet cable fun. I can just sit there and keep replugging the cable alllllll day… :)

I’ve been using this setup for at least a week now and has been working very well. Please let me know if there’s anything I’ve missed, or any even better way of setting this up.

Windows badness, and VirtualBox goodness
2007/02/11 21:31:29
linux software

Just don’t ask why, really, but (under the influence of my wife) we bought a AverMedia Hybrid (DVB-T + Analogue) + FM Radio USB 2.0 box. It’s a nice little USB device, and it also has composite and s-video input, audio input, and a remote control.

And of course it works under that proprietary . Then we realized it has rather serious issues with the composite-in being a bit slow (both slow frame rate and sometimes laggy).

As a Linuxer, naturally I then tried the device under Linux. Only just halfly expected, there is no driver for Linux yet. That’s no better way to spend your holidays overseas? I decided to spend a little on looking into the possibility to reverse engineer the windows driver.

Doing things on windows is always painful. Though I got one of the windows USB sniffer working, it wasn’t as convenient as doing things on Linux. So I went for using QEMU booting into windows and capture all the USB traffic. Unfortunately, windows (xp) crashes (classic BSOD style) while installing the device driver. I thought for a second, maybe it’s QEMU not emulating something that is needed?

Someone on #bochs pointed me to VirtualBox, so I gave it a go. Still out of luck though, windows xp crashes at the exact same spot. Damn.

On the bright side, I have discovered VirtualBox – yet another virtualizer for x86 hardware, and it’s pretty awesome:

  • (On this Pentium M 1.6GHz laptop) VirtualBox is much much faster than QEMU (with kqemu) for, well, running windows xp.
  • It has a GUI frontend for setting up VMs. As much as I prefer text/command-line based apps, a GUI frontend does help new users to try things out a lot.

Having said that, VirtualBox (currently anyway) is not entirely open source. It has two editions. And the version I tried was the one with those closed-source features. On the other hand they did say “some of these features will eventually be made available with the open-source version as well”.

So, no, I didn’t go very far with the reverse engineering. It’s usually a painful and time-consuming process. I did have some of the USB traffic sniffed and logged under windows, but I haven’t done much with them yet.

I have some more photos and info of the device here, including photos of it pulled apart.

“I know kung fu…”
2007/02/11 20:36:47
linux software

And so does everyone else. Simply apt-get install ipkungfu.

I’ve finally switched my gateway box from my 12 years old Pentium (I) 166MHz gateway box (still running Debian potato, kernel 2.2. This is Linux for you, when it works, it can work forever…), to my 5-6 years old Netwinder.

I was also very glad that the Netwinder is now (or still) officially supported by Debian. I had Debian potato installed on it for years. Upgrading it was painless.

My old gateway box was running such an old kernel, and the firewall was one of those copied-from-others script using ipchains. This time I decided to use a better way to manage my firewall rules. After a bit of research and trying things out, I’ve chosen ipkungfu. Again, it was painless to setup.

The only not-so-good bit was, I did the machine switching-over only 1 day before I went away. So as it turned out, my net connection went down in about 2 days time. I always have some scripts checking if the net is up or not, and it would reset everything (bringing down/up the interface, renewing IP, relogging on, etc). But looks like that wasn’t helping either. So I thought it might be one of those cable-modem-needed-to-be-reset situation.

I asked my uncle to power cycle the cable modem for me. And just to be safe I asked him to do the same for the gateway box too. As expected my net connection went up again. And I was happy, for a while.

Who would have thought, it went down again. Suspiciously, it also only stayed up for about 2 days. My instinct told me it wasn’t a coincident. A few days later my uncle again power cycled the modem.

I got on and check the logs again and found that my firewall was blocking (and logging) a lot of IGMP packets from some mysterious 10.x.x.x (Telstra internal network instruments) IP. It’s strange though, I haven’t seen these logs when I was testing the net. So apparently just the bpalogin client heartbeat is not enough. Seems that without the IGMP packet response (or how-ever IGMP works), after a certain timeout period (2 days?) the other end terminates the net connection and stops leasing IP, even if the cable modem is on or even there are existing network connections. So of course, I’ve then updated my firewall rules.

Lesson learnt, testing the net for 1 day is not enough, cos it will go down in 2 days ;)

Once again, many thanks to my uncle for the trouble.

permlink :: trackback :: Comments Off

FlightGear + Google Earth fun
2006/12/12 04:56:39
flightgear linux software

Last week I briefly played with Google Earth (GE) and KML, exploring the potential of using it to do something useful with FlightGear (FG).

The quickest hack I did was the GE version FGMap, which shows a moving map of all the online pilots on the FG MP servers. It is basically a very simple change with the FGMap CGI that translate MP server info into XML, only this time it outputs KML. Very simple and straight forward, nothing fancy at all. Check it out by opening this file in GE (if no one is on the server, you’ll see nothing! Check FGMap too).

FGMap Google Earth

[Updated] GE MP map using 3D models work-in-progress:

FGMap Google Earth

This weekend I started looking into GE’s 3D model support. Currently it supports two kinds of 3D model definition. KML embedded model using MultiGeometry, or a Collada .dae format. After some investigation I figured I have to use Collada to do what I want – having a 3D model of an aircraft and updating its position/orientation in GE. MultiGeometry (current version at least) is a fixed coordinates format, while with a Collada model you can place it in GE and then move it around, and also altering its heading/pitch/roll.

Quickly I found this Collada exportor plugin for Blender. As a test I loaded the C172P aircraft AC3D model from FG into Blender, followed by a few trail-and-error and I figured out what I need to export for GE: 1) Convert all faces to triangles, 2) Export Triangles, Disable Physics, Use UV Image and optionally Use Relative Paths.

According to the KML tutorial I have to pack up the .dae file together with the textures, along with a textures.txt for textures path mapping. However I discovered you could actually alter the path referenced in the .dae file to a local jpeg file, or even an HTTP URL.

So now I’ve got GE to show a 3D model of an aircraft from FG. Next is to get FG to talk to GE. There are many ways (network, serial port, etc) in FG you can export real time flight data. To make things easier for now, I’ve set it up to export simply latitude, longitude, altitude, pitch, roll, heading to a file (or actually a fifo), then I wrote a little program to read and output a KML file for GE to read. Then on the GE side, I have to create a KML with a NetworkLink to refresh the actual FG KML.

Now, problems. It seems even if I set the refresh time to be 0 seconds, and I can see GE refreshing the link continuously, on screen it still only updates the position/orientation about once per second. It could well be a GE internal limitation (or feature). The bottom line is, we need a sane way to feed data into GE.

Another thing is I can never get GE to “follow” the aircraft properly. It’s either not panning faster enough, or it will go kinda crazy and jitter a lot. Guess I’m not a GE/KML yet. I need to test it more and tidy up my codes/scripts/things a bit and I’ll put them up.

Nevertheless, it’s kind of fun to “fly FG inside GE”.

Screenshots of FlightGear running side by side with Google Earth, whereby FG sending data to GE and showing the 3D aircraft. Possibly more screenshots here


Hong Kong with Computamaps Hong Kong 3D models

Got new software?
2006/09/19 05:28:09

As free and open source software getting more popular, more and more new ones are turning up. People are now more likely to try new things. But of course new things don’t always work as expected. Bugs, crashes, memory leaks, and these often stop people straight away from keep trying or using it again.

Well, the only thing I want to say is, I wonder why people don’t just stop using m$ windows when they first get the BSOD :)

permlink :: trackback :: Comments Off

< older blogs newer blogs >
blog top 24 tags
api bonding debian engrish fglive fgmap flightgear google ISP laptop lca2007 lca2008 linux live map mpserver navaids network qotd quote of the day taiwan vim windows wine
Web pigeond.net

this site is
created with vim

nearly all pages in this site are validated as
Valid HTML 4.01!

css validated by
Valid CSS!

pigeond.net copyright 2001 - 2014
designed, created, and coded by pigeon at pigeond dot net
all rights reserved