#include bugs which got intertwined over time with
const char * conversions bugs, which in turn require
some far reaching code changes due to the propagation of function
prototypes in unexpected code parts).
Since I'll be leaving tomorrow morning for the BSP in
M nchengladbach, I'll have a bit of time there to dive
a bit more into the issues.
Actually, what I fear most now is buying train tickets from
Cologne to Moenchengladbach and back, since I'm totally unable to
pronounce the name of the latter city (my German sucks, actually
there is no such "my German" at all). Luckily, I've been told
they've wonderful ticket-selling machines in Cologne
See you there, and
happy RC squashing!
This is the story of a weirdly unfriendly/non-compliant IMAP server, and some nice interactions that arose from a debugging session around it. Over the holidays, i got to do some computer/network debugging for friends and family. One old friend (I'll call him Fred) had a series of problems i managed to help work through, but was ultimately basically stumped based on the weird behavior of an IMAP server. Here's the details (names of the innocent and guilty have been changed), just in case it helps other folks in at least diagnosing similar situations. the diagnosis The initial symptom was that Fred's computer was "very slow". Sadly, this was a Windows machine, so my list of tricks for diagnosing sluggishness is limited. I went through a series of questions, uninstalling things, etc, until we figured it would be better to just have him do his usual work while i watched, kibitzing on what seemed acceptable and what seemed slow. Quite soon, we hit a very specific failure: Fred's Thunderbird installation (version 2, FWIW) was sometimes hanging for a very long period of time during message retrieval. This was not exhaustion of the CPU, disk, RAM, or other local resource. It was pure network delay, and it was a frequent (if unpredictable) frustrating hiccup in his workflow. One thought i had was Thunderbird's per-server max_cached_connections setting, which can sometimes cause a TB instance to hang if a remote server thinks Thunderbird is being too aggressive. After sorting out why Thunderbird was resetting the values after we'd set them to 0 (grr, thanks for the confusing UI, folks!), we set it to 1, but still had the same occasional, lengthy (about 2 minutes) hang when transfering messages between folders (including the trash folder!), or when reading new messages. Sending mail was quite fast, except for occasional (similarly lengthy) hangs writing the copy to the sent folder. So IMAP was the problem (not SMTP), and the 2-minute timeouts smelled like an issue with the networking layer to me. At this point, i busted out wireshark, the trusty packet sniffer, which fortunately works as well on Windows as it does on GNU/Linux. Since Fred was doing his IMAP traffic in the clear, i could actually see when and where in the IMAP session the hang was happening. (BTW, Fred's IMAP traffic is no longer in the clear: after all this happened, i switched him to IMAPS (IMAP wrapped in a TLS session), because although the IMAP server in question actually supports the STARTTLS directive, it fails to advertise it in response to the CAPABILITIES query, so Thunderbird refuses to try it. arrgh.) The basic sequence of Thunderbird's side of an initial IMAP conversation (using plain authentication, anyway) looks something like this:
1 capability 2 login "user" "pass" 3 lsub "" "*" 4 list "" "INBOX" 5 select "INBOX" 6 UID fetch 1:* (FLAGS)What i found with this server was that if i issued commands 1 through 5, and then left the connection idle for over 5 minutes, then the next command (even if it was just a 6 NOOP or 6 LOGOUT) would cause the IMAP server to issue a TCP reset. No IMAP error message or anything, just a failure at the TCP level. But a nice, fast, responsive failure -- any IMAP client could recover nicely from that by just immediately opening a new connection. I don't mind busy servers killing inactive connections after a reasonable timeout. If it was just this, though, Thunderbird should have continued to be responsive. the deep weirdness But if i issued commands 1 through 6 in rapid succession (the only difference is that extra 6 UID fetch 1:* (FLAGS) command), and then let the connection idle for 5 minutes, then sent the next command: no response of any kind would come from the remote server (not even a TCP ACK or TCP RST). In this circumstance, my client OS's TCP stack would re-send the data repeatedly (staggered at appropriate intervals), until finally the client-side TCP timeout would trigger, and the OS would report the failure to the app, which could turn around and do a simple connection restart to finish up the desired operation. This was the underlying situation causing Fred's Thunderbird client to hang. In both cases above (with or without the 6th command), the magic window for the idle cutoff was a little more than 300 seconds (5 minutes) of idleness. If the client issued a NOOP at 4 minutes, 45 seconds from the last NOOP, it could keep a connection active indefinitely. Furthermore, i could replicate the exact same behavior when i used IMAPS -- the state of the IMAP session itself was somehow modifying the TCP session behavior characteristics, whether it was wrapped in a TLS tunnel or not. One interesting thing about this set of data is that it rules out most common problems in the network connectivity between the two machines. Since none of the hops between the two endpoints know anything about the IMAP state (especially under TLS), and some of the failures are reported properly (e.g. the TCP RST in the 5-command scenario), it's probably safe to say that the various routers, NAT devices, and such were not themselves responsible for the failures. So what's going on on that IMAP server? The service itself does not announce the flavor of IMAP server, though it does respond to a successful login with
You are so in, and to a logout with
IMAP server logging out, mate. A bit of digging on the 'net suggests that they are running a perdition IMAP proxy. (clearly written by an Aussie, mate!) But why does it not advertise its STARTTLS capability, even though it is capable? And why do some idle connections end up timing out without so much as an RST, when other idle connections give at least a clean break at the TCP level? Is there something about issuing the UID command that causes perdition to hand off the connection to some other service, which in turn doesn't do proper TCP error handling? I don't really know anything about the internals of perdition, so i'm just guessing here. the workaround I ultimately recommended to Fred to reduce the number of cached connections to 1, and to set Thunderbird's interval to check for new mail down to 4 minutes. Hopefully, this will keep his one connection active enough that nothing will timeout, and will keep the interference to his workflow to a minimum. It's an unsatisfactory solution to me, because the behavior of the remote server still seems so non-standard. However, i don't have any sort of control over the remote server, so there's not too much i can do to provide a real fix (other than point the server admins (and perdition developers?) at this writeup). I don't even know the types of backend server that their perdition proxy is balancing between, so i'm pretty lost for better diagnostics even, let alone a real resolution. some notes I couldn't have figured out the exact details listed above just using Thunderbird on Windows. Fortunately, i had a machine with a decent OS available, and was able to cobble together a fake IMAP client from a couple files (imapstart contained the lines above, and imapfinish contained 8 LOGOUT), bash, and socat. Here's the bash snippet i used as a fake IMAP client:
spoolout() while read foo; do sleep 1 && printf "%s\r\n" "$foo" ; done ( sleep 2 && spoolout < imapstart && sleep 4 && spoolout < imapfinish && sleep 500 ) socat STDIO TCP4:imap.fubar.example.net:143To do the test under IMAPS, i just replaced TCP4:imap.fubar.example.net:143 with OPENSSL:imap.fubar.example.net:993. And of course, i had wireshark handy on the GNU/Linux machine as well, so i could analyze the generated packets over there. One thing to note about user empowerment: Fred isn't a tech geek, but he can be curious about the technology he relies on if the situation is right. He was with me through the whole process, didn't get antsy, and never tried to get me to "just fix it" while he did something else. I like that, and wish i got to have that kind of interaction more (though i certainly don't begrudge people the time if they do need to get other things done). I was nervous about breaking out wireshark and scaring him off with it, but it turned out it actually was a good conversation starter about what was actually happening on the network, and how IP and TCP traffic worked. Giving a crash course like that in a quarter of an hour, i can't expect him to retain any concrete specifics, of course. But i think the process was useful in de-mystifying how computers talk to each other somewhat. It's not magic, there are just a lot of finicky pieces that need to fit together a certain way. And Wireshark turned out to be a really nice window into that process, especially when it displays packets during a real-time capture. I usually prefer to do packet captures with tcpdump and analyze them as a non-privileged user afterward for security reasons. But in this case, i felt the positives of user engagement (how often do you get to show someone how their machine actually works?) far outweighed the risks. As an added bonus, it also helped Fred really understand what i meant when i said that it was a bad idea to use IMAP in the clear. He could actually see his username and password in the network traffic! This might be worth keeping in mind as an idea for a demonstration for workshops or hacklabs for folks who are curious about networking -- do a live packet capture of the local network, project it, and just start asking questions about it. Wireshark contains such a wealth of obscure packet dissectors (and today's heterogenous public/open networks are so remarkably chatty and filled with weird stuff) that you're bound to run into things that most (or all!) people in the room don't know about, so it could be a good learning activity for groups of all skill levels. Tags: debugging, imap, perdition, wireshark
With Guantanamo Bay about to be shut down, and President Obamas' first year in office complete, what do the American public think of him?
| % of Americans who approved of Pres. Bush after one year in office | |
| % of Americans who favor waterboarding the Christmas bomber | |
| % of Americans who approve of Pres. Obama after one year in office |

There are more webpages I need to fill in... mksh's TaC, arc4random (which needs some major redesign as well) and BSD::arc4random, the RANDEX protocol (entropy exchange over IRC) and its plugins and patches, ... Not just Mac OSX (and, I hope, iPhoneOS) will soon come with mksh(1), but also Android (I prepared patches to make it /bin/sh, which works quite well although I need to find out how to make a hardlink so that #!/bin/mksh scripts will run) and Maemo, for which I wrote an mksh package in a garage project, which also needs some love w.r.t. testing on actual devices, menu integration, etc. (Please contact me if you can help with either of the three.) We also have lewellyn:#ksh making a package for the new OpenSolaris system (thanks again). People persuading Apple to put it on the jesusPhone are also welcome. (This does not mean I endorse any of these right now, I'd probably get the most of a WinCE PDA with built-in GPSr, WLAN and maybe GSM/GPRS.) English and French native speakers, please review, and Dutch native speakers may contribute a translation of, our flyers. (Source code for these is not available, sorry. Benny makes them in Quark on System 7 in Basilisk II, used to be Classic until Apple yanked it. But still, they use only free fonts, free imagery or such the MirOS Project is allowed to use, and beat every single other FOSS project flyer I've ever seen by far!) There's probably more I could write, I bet I forgot half of it anyway, but I'll leave it at that for now. Get yourself a nice cup of hot chocolate, pour an Espresso into it, and enjoy the mix with a piece of cake (I'd say strawberry or mousse-pear but all they had was cassis-cr me) and pity me for not knowing any French next month.
Working on another laptop, I was missing my quiltrc settings. I think, I got them from a this email by Marco d Itri. Perhaps it is of help to somebody (for example, when I go searching for it again).
BTW, I changed it locally to check only for debian folder in parent directories and create debian/patches automatically if needed:
1 2 3 4 5 6 7 8 | for d in . .. ../.. ../../.. ../../../.. ../../../../..; do if [ -d $d/debian ]; then if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches fi export QUILT_PATCHES=debian/patches fi done |

So. I m trying to get familiar with libvirt and friends. To this end, I ve set up a Lucid virtual machine booting from PXE into an initrd environment which does a pivot_root to an AoE block device.
The #virt channel on irc.oftc.net told me that in order to have libvirt provide PXE capability, I would have to install a recent version of libvirt. I built version 0.7.5-3 from sid on my karmic laptop and it seems to be working okay.
I decided to set up the pxe root directoy in /var/lib/tftproot just because that s what the example code had in it.
I had to manually configure a virtual network. Here is the XML config file:
$ sudo virsh net-dumpxml netboot
<network>
<name>netboot</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward mode='nat'/>
<bridge name='virbr1' stp='off' delay='1' />
<domain name='example.com'/>
<ip address='192.168.123.1' netmask='255.255.255.0'>
<tftp root='/var/lib/tftproot' />
<dhcp>
<range start='192.168.123.2' end='192.168.123.254' />
<bootp file='pxelinux.0' />
</dhcp>
</ip>
</network>
This, of course, depends on the pxelinux.0 file. Luckily, this is packaged up in syslinux and can be installed with a simple
$ sudo apt-get install syslinux
$ sudo mkdir /var/lib/tftproot
$ sudo cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftproot
I had to create a pxelinux config file for the virtual machine (indexed by mac address). Note that I put a console=ttyS0,115200 argument on the kernel command line so that I can attach to the serial port from the host system for copy/paste debugging. Also of importance is the root=/dev/etherd/e0.1p1 argument, specifying which block device we ll be doing the pivot_root to eventually.
$ mkdir /var/lib/tftproot/pxelinux.cfg/
$ cat /var/lib/tftproot/pxelinux.cfg/01-52-54-00-44-34-67
DEFAULT linux
LABEL linux
SAY Now booting the kernel from PXELINUX...
KERNEL vmlinuz-lucid0
APPEND ro root=/dev/etherd/e0.1p1 console=ttyS0,115200 initrd=initrd.img-lucid0
I decided to use the karmic kernel for lucid initially. I ll eventually switch over to the lucid kernel ;)
$ sudo cp /boot/vmlinuz-2.6.31-17-generic /var/lib/tftproot/vmlinuz-lucid0
I copied /etc/initramfs-tools to ~/tmp/lucid so that I didn t mess up the system initrd scripts:
$ mkdir -p ~/tmp/lucid && cp -r /etc/initramfs-tools ~/tmp/lucid/
Since mkinitramfs doesn t currently have a system for AoE root, I had to do a bit of fiddling. I copied the NFS root boot script and made a couple of modifications.
$ diff -u /usr/share/initramfs-tools/scripts/nfs ~/tmp/lucid/initramfs-tools/scripts/aoe --- /usr/share/initramfs-tools/scripts/nfs 2008-06-23 23:10:21.000000000 -0700 +++ /home/cjac/tmp/lucid/initramfs-tools/scripts/aoe 2010-01-15 14:56:28.098298027 -0800 @@ -5,59 +5,25 @@ retry_nr=0 # parse nfs bootargs and mount nfs -do_nfsmount() +do_aoemount() - configure_networking - # get nfs root from dhcp - if [ "x$ NFSROOT " = "xauto" ]; then - # check if server ip is part of dhcp root-path - if [ "$ ROOTPATH#*: " = "$ ROOTPATH " ]; then - NFSROOT=$ ROOTSERVER :$ ROOTPATH - else - NFSROOT=$ ROOTPATH - fi - - # nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] - elif [ -n "$ NFSROOT " ]; then - # nfs options are an optional arg - if [ "$ NFSROOT#*, " != "$ NFSROOT " ]; then - NFSOPTS="-o $ NFSROOT#*, " - fi - NFSROOT=$ NFSROOT%%,* - if [ "$ NFSROOT#*: " = "$NFSROOT" ]; then - NFSROOT=$ ROOTSERVER :$ NFSROOT - fi - fi + ip link set up dev eth0 - if [ -z "$ NFSOPTS " ]; then - NFSOPTS="-o retrans=10" - fi + ls /dev/etherd/ - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-premount" - run_scripts /scripts/nfs-premount - [ "$quiet" != "y" ] && log_end_msg + echo > /dev/etherd/discover - if [ $ readonly = y ]; then - roflag="-o ro" - else - roflag="-o rw" - fi + ls /dev/etherd/ - nfsmount -o nolock $ roflag $ NFSOPTS $ NFSROOT $ rootmnt + mount $ ROOT $ rootmnt -# NFS root mounting +# AoE root mounting mountroot() - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-top" - run_scripts /scripts/nfs-top - [ "$quiet" != "y" ] && log_end_msg - - modprobe nfs - # For DHCP - modprobe af_packet + modprobe aoe # Default delay is around 180s # FIXME: add usplash_write info @@ -67,17 +33,13 @@ delay=$ ROOTDELAY fi - # loop until nfsmount succeds + # loop until aoemount succeds while [ $ retry_nr -lt $ delay ] && [ ! -e $ rootmnt $ init ]; do [ $ retry_nr -gt 0 ] && \ - [ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount" - do_nfsmount + [ "$quiet" != "y" ] && log_begin_msg "Retrying AoE mount" + do_aoemount retry_nr=$(( $ retry_nr + 1 )) [ ! -e $ rootmnt $ init ] && /bin/sleep 1 [ $ retry_nr -gt 0 ] && [ "$quiet" != "y" ] && log_end_msg done - - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom" - run_scripts /scripts/nfs-bottom - [ "$quiet" != "y" ] && log_end_msg(below is the full file in case udiff is less convenient)
$ cat ~/tmp/lucid/initramfs-tools/scripts/aoe
# NFS filesystem mounting -*- shell-script -*-
# FIXME This needs error checking
retry_nr=0
# parse nfs bootargs and mount nfs
do_aoemount()
configure_networking
ip link set up dev eth0
ls /dev/etherd/
echo > /dev/etherd/discover
ls /dev/etherd/
mount $ ROOT $ rootmnt
# AoE root mounting
mountroot()
modprobe aoe
# Default delay is around 180s
# FIXME: add usplash_write info
if [ -z "$ ROOTDELAY " ]; then
delay=180
else
delay=$ ROOTDELAY
fi
# loop until aoemount succeds
while [ $ retry_nr -lt $ delay ] && [ ! -e $ rootmnt $ init ]; do
[ $ retry_nr -gt 0 ] && \
[ "$quiet" != "y" ] && log_begin_msg "Retrying AoE mount"
do_aoemount
retry_nr=$(( $ retry_nr + 1 ))
[ ! -e $ rootmnt $ init ] && /bin/sleep 1
[ $ retry_nr -gt 0 ] && [ "$quiet" != "y" ] && log_end_msg
done
There was also a small modification to the initramfs.conf file:
$ diff -u /etc/initramfs-tools/initramfs.conf ~/tmp/lucid/initramfs-tools/initramfs.conf --- /etc/initramfs-tools/initramfs.conf 2008-07-08 18:37:42.000000000 -0700 +++ /home/cjac/tmp/lucid/initramfs-tools/initramfs.conf 2010-01-15 14:33:38.088295207 -0800 @@ -47,14 +47,16 @@ # # -# BOOT: [ local nfs ] +# BOOT: [ local nfs aoe] # # local - Boot off of local media (harddrive, USB stick). # # nfs - Boot using an NFS drive as the root of the drive. # +# aoe - Boot using an AoE drive as the root of the drive. +# -BOOT=local +BOOT=aoe # # DEVICE: ...I also needed to add aoe to the list of modules included in the initramfs:
$ echo aoe >> ~/tmp/lucid/initramfs-tools/modules
In order to generate the initrd.img file from this new config, I ran the following:
$ sudo mkinitramfs -d ~/tmp/lucid/initramfs-tools/ -o /var/lib/tftproot/initrd.img-lucid0
I created a lucid VM by installing from the desktop install disk. You can grab the ISO here:
http://cdimage.ubuntu.com/daily-live/current/
I ll leave the creation of the virtual machine and installation as an exercise for the reader. I put the filesystem on an lvm volume group called vg0 in a logical volume called lucid0 (ie, /dev/vg0/lucid0).
At this point, I created a new virtual machine called lucid0. Here is the xml for the domain:
$ sudo virsh dumpxml lucid0
<domain type='kvm' id='1'>
<name>lucid0</name>
<uuid>96fbad21-4f25-5700-ddd8-1a565c7170ee</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc-0.11'>hvm</type>
<boot dev='network'/>
</os>
<features>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<interface type='network'>
<mac address='52:54:00:44:34:67'/>
<source network='netboot'/>
<target dev='vnet0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/4'/>
<target port='0'/>
</serial>
<console type='pty' tty='/dev/pts/4'>
<source path='/dev/pts/4'/>
<target port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5901' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
<sound model='es1370'/>
<video>
<model type='cirrus' vram='9216' heads='1'/>
</video>
</devices>
</domain>
Now we re ready to start the AoE target and launch the virtual machine. If you don t have vblade installed, do so now:
$ sudo apt-get install vblade
Start the target up with the following command:
$ sudo vbladed 0 1 virbr1 /dev/vg0/lucid0
Now, if all goes well, you should be able to watch the virtual machine boot up and do its thing like so:
$ sudo virsh start lucid0 && sudo screen -S lucid0 sudo virsh ttyconsole lucid0 115200
If you get errors about /dev/etherd/e0.1p1 not existing (these might look like this):
Begin: Retrying AoE mount ... err discover interfaces revalidate flush err discover interfaces revalidate flush mount: mounting /dev/etherd/e0.1p1 on /root failed: No such file or directory Done.then you might want to try restarting vbladed like this:
$ sudo kill -9 ps auwx grep vblade grep -v grep awk ' print $2 ' && sudo vbladed 0 1 virbr1 /dev/vg0/lucid0
So. Now you should have a lucid gdm in your virt-manager console. Any questions? #virt on irc.oftc.net
I have to admit, I was a bit lazy in my RC bug squashing efforts during the
last two weeks. anyway, a short summary:
Next.