Thursday Night

Paul Betts’s personal website / blog / what-have-you

How I saved the Internet

For the last 9 months, I’ve been constantly fighting my wireless router. For some reason, my Linksys WRT54G (and before it, a Microsoft MN-700) would both randomly drop packets and cause really difficult to debug errors that to this day, I have no idea why they are happening.

If you know anything about TCP, if a network drops random packets every 30 seconds or so, it results in really horrible performance because TCP Reno will scale down every time it sees a dropped packet, so basically the end result is that I would download stuff at ~10K/s on a 6Mbps Cable modem which is absurd.

So basically, I was looking for a new solution, when I stumbled upon (while I was rebuilding all the software on my broken desktop PC, which is another story), the new Madwifi NG wireless driver for my Atheros card. The primary reason that this driver is so cool is that it allows what’s called virtual APs (VAPs). This allows you to create as many virtual wireless cards as you want, as long as they’re all on the same channel (the card still only has one radio, obviously). Why would you want to do this? The obvious application is to have one device in monitor mode to passively monitor packets while one device is associated. But I found another use that turned out really well.

First, I have to explain my network setup a bit. It’s fairly simple, the router is in the living room and is connected to a cable modem. The kicker though, is that my Xbox is connected via Ethernet to the Linksys because it has to be able to connect to my desktop upstairs so that I can watch movies on it (with Xbox Media Center). This is the part that causes all the problems, because I have to use the router somehow to connect the Xbox to my desktop.

The solution is fairly clever. First, I create some virtual devices; one device is in Master mode and is acting as an Access Point. The second device however, is acting as a client. I used the following commands to set it up:

wlanconfig ath0 create wlandev wifi0 wlanmode ap
wlanconfig ath1 create wlandev wifi0 wlanmode sta nosbeacon
wlanconfig ath2 create wlandev wifi0 wlanmode monitor

Now I’ve got 2 devices (and a monitor), both with independent ESSIDs. Here’s the trickerous part, we set the AP to run on the same channel as the Linksys router, allowing us to both act as an AP and be connected to the Linksys at the same time, like so:

ifconfig ath1 up
iwconfig ath1 essid LinksysRouter
dhcpcd -G -R ath1 # Prevent dhcpcd from changing routes
iwconfig ath0 essid ThisIsTheInternet
iwconfig ath0 channel 3 # Same as the router
ifconfig ath0 up 192.168.6.1
dhcpcd eth0 # Cable modem on eth0

After that, it’s a simple matter of setting up regular iptables-based routing; I used Firestarter (plus some hacking to get Samba WINS resolution to work), dhcpd and since I wanted to be fancy, I threw in bind and squid for faster web browsing.

Transferring files to my desktop is an order of magnitude faster now, for some reason either the Linksys really sucks or Linux is really good at wireless, but I get ~1Mb/s transferring over wireless now, it’s awesome. My desktop is directly connected to the Internet now, so I don’t have to worry about port forwarding nonsense, and my previous shim involving my roommate’s laptop refusing to connect to the router is solved for permanent now (his Linksys wireless card refused to connect to our router, I had to set up the broken MS router and my desktop to route the Internet, it was ridiculously inefficient). All in all, a successful venture, and only took me one night to set up!

Written by Paul Betts

May 3rd, 2006 at 11:54 pm

Posted in Linux