Networking with a gateway not on the local subnet on NetBSD at OVH

NetBSD has a FAQ for networking that outlines how to do Networking with a gateway not on the local subnet, unfortunately the recipe that they provide doesn't actually work "in the real world." The route command they provide does not make the network stack send an ARP who-has for the IP address and requires that you statically set the MAC address of the gateway.

I figured out a work-around for this, based on some insight from people on the NetBSD tech-talk mailing list. This allows you to use NetBSD as a guest operating system on providers such as OVH and Hetzner:

# ifconfig fxp0 inet 10.0.0.1 
# route add -net 192.168.0.1/32 -cloning -link fxp0 -iface 
# route add default -ifa 10.0.0.1 192.168.0.1

The trick was to specify use route cloning, and use a net definition instead of a host definition. Now NetBSD will send an ARP who-has request for the gateway IP address.

To supplement the OVH bridge client guide that is available on their Wiki, it would fit into the following template:

# ifconfig fxp0 inet Fail.over.IP netmask 255.255.255.255 broadcast Fail.over.IP 
# route add -net Your.Server.IP.254/32 -cloning -link fxp0 -iface 
# route add default -ifa Fail.over.IP Your.Server.IP.254

This should allow you to use NetBSD as a guest and not get blocked by OVH robots that check for too many ARP requests.

Accessing USB devices as non-root: writing udev rules the easy way

I recently purchased a TEMPered USB thermometer, which I wanted to use as non-root using an open source utility called TEMPered. All the recipes I found, required that I use root to access the /dev/hidraw0 device that the particular TEMPered USB device exposed – of course this was not acceptable.

systemd (and udev, in general – I believe) has a handy utility called udevadm. You can use this tool to query a device on your system, for example:

udevadm info --query=all --name=/dev/hidraw0 --attribute-walk

Which allows you to retrieve all the required attributes to craft a file to put in /etc/dev/rules.d. I have created the following to expose PCsensor TEMPerV1.4 to a user that is part of the group temper:

# TEMPer1.4 USB thermometer
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7401", GROUP="temper", MODE="0660"

I placed this in a file called /etc/udev/rules.d/60-temper.rules. You can now use TEMPered as a non-root user, which is a member of the group in question!

Android's K-9 Mail battery life and Dovecot's Push-IMAP

What is Push-IMAP, and why is it useful?

In the world of mobile phones, battery life is a concern. You want to be able maximize the battery life on your mobile phone, while still getting instant notifications of new e-mail. This is where Push-IMAP (aka. IMAP PUSH, P-IMAP) comes into play, an extension based on an RFC which combines with IMAP IDLE. You no longer need to poll the IMAP server if you are using this feature, as you always have an open connection.

What's the problem?

I am using K-9 Mail on my Android phone, and would like to make use of the IMAP PUSH feature but I found it consumes far too much battery. In Dovecot 1.2 when you initiate IMAP IDLE via your IMAP client (eg. K-9 Mail) Dovecot sends a message every 2 minutes stating "OK Still here", this causes the mobile data connection to have to wake up and consumes excessive amounts of battery. There is no way to configure this behavior in Dovecot 1.2 except by a source edit.

The solution

You will need to upgrade your Dovecot installation to 2.0 (if you aren't running 2.0 already,) which is slightly out of the scope of this blog entry. I found the upgrade rather painless by following the Upgrading Dovecot v1.2 to v2.0 guide on the Dovecot Wiki.

Dovecot 2.0 supports a configuration option called imap_idle_notify_interval which enables you to specify the interval between "OK Still here" messages. K-9 mail by default refreshes IDLE connections every 24 minutes, but of course Dovecot wakes up the client much more frequently than that. We are going to fix this behavoir.

The configuration of Dovecot 2.0 is slightly different than Dovecot 1.2, composing of multiple files. If you are using Linux your Dovecot configuration is most likely contained under /etc/dovecot, and on FreeBSD it is contained under /usr/local/etc. You will want to edit the conf.d/20-imap.conf file under the respective directory based on your host operating system.

You will see a stanza similar to the one outlined below, and you will want to uncomment the imap_idle_notify_interval line and replace 2 mins with 29 mins.

protocol imap {
 # How long to wait between "OK Still here" notifications when client is
 # IDLEing.
 #imap_idle_notify_interval = 2 mins
}

When you have completed this step, you will want to restart Dovecot. This can be accomplished on Linux with /etc/init.d/dovecot restart, or /usr/local/etc/rc.d/dovecot restart on FreeBSD.

My results

By switching the Dovecot server to send the "OK Still here" notification to every 24 minutes instead of 2 minutes the mobile client is woken up much more infrequently, either when you receive a new e-mail or every 29 minutes respectively. This has greatly improved the battery life on my HTC Desire Z with K-9 Mail, and hopefully it will help out with your device issues and being able to instantly receive new e-mail notifications!

An update, RFC style

Clint Pachl e-mailed me to inform me that IMAP4 IDLE RFC (rfc2177) specifics that the client should issue a IDLE command every 29 minutes. I have updated the guide to reflect this change.

Because the K-9 default "Refresh IDLE connection" is 24 minutes, that gives a buffer of 5 minutes if the IMAP server timeout is set to 29 minutes. The RFC and K-9 default times, 29 and 24 respectively, don't seem like a coincidence. I think the RFC may have been an influence on the K-9 devs when choosing a default IDLE refresh.

Consequently, setting Dovecot's imap_idle_notify_interval to 29 minutes seems most appropriate considering K-9's default. This gives K-9 ample time to respond in case of short outages or passing between cell towers (<5min window). However, beyond that window, the server can then shut down the connection.

Setting both the server and the client to the same timeout/refresh may cause some cross-talk.

Disabling menu bar, navigation transparency in Firefox 4 on Windows 7, Vista

Why?

Firefox 4 which was released on March 22nd, 2011 is a very fast and featured browser with tons of improvements over previous versions. But like always, Mozilla has changed something in the browser that I don't like, and this time it is the transparency of the new title bar. It is quite distracting, and infact it was so distracting that I needed to figure out how to disable the transparency.

I heard some suggestions to disable Windows Aero, but this isn't really an option since it's disabled on a system basis and what if I only don't like the transparency in Firefox? I found a simple fix by using the features available in userChrome.css to modify the layout of the Firefox.

userChrome.css

@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
#TabsToolbar, #PersonalToolbar, window, page, dialog, wizard, prefwindow {
 background-color: -moz-dialog !important;
}

How do I edit userChrome.css?

This tutorial assumes that you have Hide Extensions for known file types unchecked in Windows Explorer Folder Options.

  1. Open Windows Explorer and enter %APPDATA%\Mozilla\Firefox\Profiles into the Address Bar,
  2. On screen you will see a folder with a random name (eg. 7q4fse53.default,) select the folder,
  3. Select the chrome folder in your profile for Mozilla Firefox,
  4. If a file named userChrome.css does not exist: create it by right clicking and selecting "New Text Document" under the New context menu, and rename the newly created file to userChrome.css,
  5. Open the file userChrome.css in Notepad or a text editor of your choice, and paste the content from the userChrome.css section (from above) into the file,
  6. Save the changes you have made to userChrome.css in your text editor,
  7. Restart Mozilla Firefox to see the changes you have made to your userChrome.css file.

It would be helpful if Mozilla made some of these layout changes configurable, this reminds me of the AwesomeBar (TM) feature which not everyone thinks is so awesome. But at least we have userChrome.css, and addons for layout changes.

VLAN tag un-NATed WAN connection on DD-WRT

This is a followup to my Netgear WNR3500L, DD-WRT and TELUS IPTV post.

I am using 802.1q VLAN on my Netgear switch and NAT device running DD-WRT, my whole network is behind a NAT with a separate VLAN for my IPTV. I wanted to have the ability to give unfiltered (un-NATed) network access to certain devices in my household, without having to change any wires.

The solution? 802.1q VLAN tag the WAN VLAN on DD-WRT. It was really very simple, on the Netgear WNR3500L DD-WRT uses VLAN2 as the WAN VLAN (because of the way the internals of this particular Broadcom device work.)

I simply logged into the DD-WRT interface of the device, selected VLANS tab (from the Setup tab) and checked Port 4 (which is really Port 1 on my device, which I have plugged into my 24 port switch) as Tagged, then I restarted the device. Now when I want unfettered internet access to a virtual machine, or desktop I simply add the port (either on my Netgear NAT device or my switch as tagged) to VLAN 2 and it works!