July 2009 Archives

Jul 31 2009

DNS classes

Posted in dns(sec); by Miek Gieben; comments: 1

If you ever administered a DNS server you are probably familiar with the IN (internet) class, as in

localhost   IN      A       127.0.0.1

where you define an IP address for the name localhost. As you may, or may not, already know there are other classes defined (but hardly used) for the DNS. Two of those are the Chaos class (CH) and the Hesiod (HS) class. With these classes you can create some sort of parallel world where you can also define names. This feature of the DNS isn't exactly in great use, but is is nice to know where they were used for.

Chaos

The CH class has its use in the Chaosnet, which is a network implementation that didn't make it, unlike the current Ethernet + TCP/IP combo. If you want to read up on your knowledge of the Chaosnet protocol this pdf is your friend.

Today the CH class is missused by BIND, for the following neat tricks:

dig CH @localhost version.bind TXT

Which yields:

...
;; QUESTION SECTION:
;version.bind.      CH  TXT
;; ANSWER SECTION:
version.bind.   0   CH  TXT "9.5.1-P2"
;; AUTHORITY SECTION:
version.bind.   0   CH  NS  version.bind.
...

that shows the BIND version. Of course you can disable this so that people cannot query you server's version, DNS Fingerprinting works much better in that case.

And of course:

dig CH @localhost authors.bind TXT

which gives:

...
;; ANSWER SECTION:
authors.bind.       0   CH  TXT "David Lawrence"
authors.bind.       0   CH  TXT "Danny Mayer"
authors.bind.       0   CH  TXT "Damien Neil"
authors.bind.       0   CH  TXT "Matt Nelson"
authors.bind.       0   CH  TXT "Michael Sawyer"
authors.bind.       0   CH  TXT "Brian Wellington"
authors.bind.       0   CH  TXT "Mark Andrews"
authors.bind.       0   CH  TXT "James Brister"
authors.bind.       0   CH  TXT "Ben Cottrell"
authors.bind.       0   CH  TXT "Michael Graff"
authors.bind.       0   CH  TXT "Andreas Gustafsson"
authors.bind.       0   CH  TXT "Bob Halley"
...

So you know who to hit when the next bind bug hits your installation.

NSD also does this trick:

dig @ns4.nic.nl CH version.bind TXT

gives:

;; ANSWER SECTION:
version.bind.       0   CH  TXT "NSD 3.0.7"

Hesiod

The HS class has its origins Project Athena (also see Wikipedia). Which is a naming server ala nis or more recent ldap. With HS class you can put user and group data in your DNS, so you can do without an ldap server. The package hesiod still can be installed if you want to play with this.

Putting passwords in your DNS may need to be a smart thing to do, so with hesiod you also want to use Kerberos.

I don't know if there are any tricks BIND does with the HS class, esp. since hesiod can still be used.

If you want to use the HS class in BIND you must tell that to BIND, in your named.conf say:

zone "domain_name" hesiod {
type master;
filename "somewhere.db";
}

And in your zone file use HS instead of IN:

localhost   HS  A   127.0.0.1

Further reading

Further reading in RFC2929 and in BIND reference manual.


Jul 25 2009

Copyright

Posted in thoughts; by Miek Gieben; comments: 1

When you watch a DVD you bought or rented, you first have to watch a few warnings about being a criminal when you also show this DVD at school or to your grandpa or whatever... On a normal DVD player you can not fast forward this.

When you watch a downloaded DVD all this has been removed by some evil hacker. So you can just watch the movie without all this crap. Downloading is legal in almost all countries.

So thanks to Disney and other large (and evil) companies we are now in the following, ironic, situation:

When you play by their rules you get "punished" by having to watch ugly warnings.

When you play by your rules your movie watching experience is not diluted with scary warnings.

The movie industry does not have clients anymore, they only see criminals...


Jul 21 2009

Case insensitive cd

Posted in zsh; by Miek Gieben; comments: 2

Do I want this?

% ls -ld Joe_Cocker_-_The_Definitive_Collection 
drwxr-xr-x 2 miekg admin 4.0K Jul 20 22:20 Joe_Cocker_-_The_Definitive_Collection/
% cd *joe*
cd: no such file or directory: *joe*
% unsetop case_glob 
% cd *joe*
% pwd
/shared/vol/music/J/Joe_Cocker_-_The_Definitive_Collection

Jul 18 2009

SRM with KVM and DRBD

Posted in linux; by Miek Gieben; comments: 5

Currently we are building a fairly rock solid high availability cluster for a client. This has the "usual" ingredients: two locations, two NetApps, two clusters of three vmware ESX servers and a bunch of virtual machines running on top of the ESX servers. Also included in the mix is a VDI (now called View) virtual desktop infrastructure for running virtual windows XP clients.

This is all managed by SRM (site recovery manager) and it is almost working. But that is another story.

What got me thinking is the following.

Last week I did a consultancy job where they had a build a fail over cluster using DRBD. With DRBD you have a disk device /dev/drbd/0 which is transparently replicated. The device file can be used like any other, fdisk, mkfs and mount all work as expected.

Now throw KVM into the mix...

The virtual machine images must be stored on the DRBD device. Suppose we have two servers called master and slave. On master the kvm processes run. In a failover situation the following needs to happen:

  • If master is stil available, kill all kvm processes;
  • if master is still available, set the DRBD device in secondary mode or disable it all together;
  • On slave make the DRBD device primary (so that it will become available in rw mode. If you don't do this you get Wrong medium type errors;
  • On slave start the kvm processes again.

It would even be cooler if the virtual machines could actually be copied over while still are running, but I don't know if that would be possible.

Shared storage would be possible by letting one virtual machine export (via NFS/SaMBa/iSCSI) another DRBD device.

So my site recovery manager script (SRM script) will be something along the lines of this:

#!/bin/bash

# when doing a fail over call it on the old site
# (if still available): srm stop
# the other side call it like: srm start

case $1 in
stop)
    /etc/init.d/kvm stop
     drbdadm /dev/drbd/0 secondary

;;

start)
     drbdadm /dev/drbd/0 primary -o
    /etc/init.d/kvm start

;;
esac
exit 0

Is it really that simple?


Jul 17 2009

A library at home

Posted in perl, latex, linux; by Miek Gieben; comments: 2

I've told a few times about how to build a library.

But there a some extra things that must be done before you can call yourself a complete librarian.

  1. ID-ing the books you have
  2. Storing the information
  3. Marking the books
  4. Sorting and shelving the books
  5. Remembering who borrowed what

ID-ing books

For this I bought a barcode reader that reads the ISBN number of the book's backcover. With book_get (Perl code) I can retrieve the author, title, genre and year published from Google.

% book_get 9789024546497
Cryptonomicon
Neal Stephenson
none
2005
#Cryptonomicon‎by Neal Stephenson, Irene Ketman - 2005

Getting the genre right is a bit of a problem as Google will not always report the correct genre (or just slightly different, i.e. sometimes 'science' and sometimes 'computer science'). I solved this by explicitly asking for the genre in the next step.

Also the html returned is awful, so sometimes this script looses its way.

Storing the information

Getting the information is the first step, now it needs to be stored somewhere. In a SQLite database for instance. I've made a minimal database with only one table which holds all information: title, genre, author, isbn, and a few more items.

With book_sql (perl code) the information retrieved with book_get is normalized (correct the genre) and put into the SQLite db.

Marking the books

To help with this I needed a label writer to print the author, genre and title on a small label. Currently I am not confident enough to automate the printing of the labels so I manually query the database and feed the rows to labelfmt (Perl code). This little scripts uses LaTeX to format the labels and will print the resulting pdf on the labelwriter.

% sqlite3 biblio.db
sqlite> select * from books where title like '%crypto%';
146|9789024546497|Cryptonomicon|Neal Stephenson, Irene Ketman|science fiction|2005|1201339561|

Now I give this text to labelfmt and it will print the label

% ./labelfmt
146|9789024546497|Cryptonomicon|Neal Stephenson, Irene Ketman|science fiction|2005|1201339561|
....

And the labels gets printed:

label with print

Next you will needed:

  • little pieces of thick paper/carton; this is where you sticker the labels on. Like this:

paper with label

  • little (120 x 120 mm) plastic triangles; which can be glued in each book, so that the book's label can be put inside.

plastic in book

And insert the label:

label in book

And another one is ready :-)

Sorting and storing

We decided to catalog our books based on genre. So I made a map to tell which genres are placed where. Sorta like

  • COMPUTER - left shelve in the living room
  • SCIENCE - middle shelve in the living room
  • ... - somewhere else

So there you have it a full blown library setup for you books at home.

Borrowing

Now if somebody want to read one of our book it is simply a matter of: locating the book, getting the label out, writing the person's name on the label and storing the label in a safe place until the book is returned.

This last step could also be automated by using the barcode reader, but the desktop computer in our living room is not powered on 100% of the time. Booting the machine takes too long and makes it too cumbersome if someone just wants to borrow a book.


Jul 16 2009

Biking like hell

Posted in life; by Miek Gieben; comments: 0

After diner I biked the following trip:

ATB Berg en Dal, Nijmegen at EveryTrail

I had to stop a few times because of some stomach ache (mountain biking after eating is a bad idea). So the average speed was 13 km/h...

So today I ate less and tried again (tried not to stop this time):

ATB Berg en Dal, Nijmegen at EveryTrail

16.9 km/h which is not bad considering all the climbing.

Note: there are some odd differences in vertical up/down. Probably due to only receiving two or three satellites (and not four).


Jul 14 2009

ZFS and Oracle

Posted in linux; by Miek Gieben; comments: 2

I already knew (Open)Solaris sucks, but now Ton has also figured it out.

ZFS definitely does not suck. Why not petition Oracle to GPL(v2) ZFS? Especially now Oracle wants to kill OpenSolaris?


Jul 11 2009

Kernel logs

Posted in linux; by Miek Gieben; comments: 1

So, there I am browsing my logs.

BAM

[650521.310292] INFO: task mysqld:2730 blocked for more than 120 seconds.
[650521.310320] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[650521.310364] mysqld        D 00000000     0  2730   2674
[650521.310367]  f6183ce0 00000086 c06ef6cc 00000000 f61c8c70 7834922a 00000dc2 00020050
[650521.310373]  00000296 c0796fe0 c0796fe0 f61c8f04 c2c35fe0 00000003 9500b16e 00024f83
[650521.310379]  00000002 00000002 f66bb500 f6d02e40 c2bf2090 f6e2e680 f6183ce8 c050eb68
[650521.310384] Call Trace:
[650521.310388]  [<c050eb68>] schedule+0x8/0x20
[650521.310391]  [<c0266701>] do_get_write_access+0x2a1/0x3d0
[650521.310395]  [<c0127d93>] ? kmap_atomic_prot+0x43/0xe0
[650521.310398]  [<c0150030>] ? wake_bit_function+0x0/0x60
[650521.310402]  [<c02669a3>] jbd2_journal_get_write_access+0x23/0x40
[650521.310405]  [<c0252a36>] __ext4_journal_get_write_access+0x26/0x60
[650521.310409]  [<c023e9d4>] ext4_reserve_inode_write+0x34/0x70
[650521.310413]  [<c023ea45>] ext4_mark_inode_dirty+0x35/0x140
[650521.310416]  [<c02669ac>] ? jbd2_journal_get_write_access+0x2c/0x40
[650521.310420]  [<c02446cf>] add_dirent_to_buf+0x12f/0x340
[650521.310423]  [<c0245032>] ext4_add_entry+0xe2/0x1d0
[650521.310427]  [<c024540a>] ext4_add_nondir+0x1a/0x70
[650521.310430]  [<c0245814>] ext4_create+0xc4/0x100
[650521.310434]  [<c01d0ced>] vfs_create+0xcd/0x170
[650521.310437]  [<c01d2562>] __open_namei_create+0x42/0xa0
[650521.310441]  [<c01d2be0>] do_filp_open+0x620/0x660
[650521.310444]  [<c01ca888>] ? cp_new_stat64+0xe8/0x100
[650521.310448]  [<c02d3a67>] ? strncpy_from_user+0x37/0x60
[650521.310451]  [<c01c52a1>] do_sys_open+0x51/0xe0
[650521.310455]  [<c01c5399>] sys_open+0x29/0x40
[650521.310458]  [<c0102ebc>] sysenter_do_call+0x12/0x28

Okay, what the hell...Two questions.

  1. What does it mean? Did the kernel crash or is this some kind of (error) reporting from the kernel?
  2. What should I do? Is this worth reporting as I'm running 2.6.30 (which is pretty new)?

Jul 08 2009

Playing with dhcpd

Posted in linux; by Miek Gieben; comments: 0

Yes! At work today we made dhcpd crash on a /etc/dhcpd.conf :) We were working towards the following (now working) setup:

class "igel" {
    match if binary-to-ascii(16, 8, "-", substring (hardware, 0, 5)) = "1-0-e0-c5-67";
}
pool {
    allow members of "igel"; 
    range 192.84.30.161 192.84.30.170; # igel[0-9]
}

But while figuring this out, dhcpd went boom :)

[root@vmaster cfengine]# dhcpd -d -f -cf hosts/vnet/etc/dhcpd.conf
Internet Systems Consortium DHCP Server V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
hosts/vnet/etc/dhcpd.conf line 20: can't override match.
    match if 
    ^
hosts/vnet/etc/dhcpd.conf line 22: pool declared outside of network pool
                ^
Segmentation fault

Jul 07 2009

Using LaTeX with a label writer

Posted in latex, linux; by Miek Gieben; comments: 2

I wanted to pretty print my labels on my (new) Dymo 400 label writer. All the howtos I found were detailing how to use LaTeX to print a sheet of labels. But I needed some LaTeX-foo to print only one. So /me to the rescue...

My labels are 36mm X 89 mm (Dymo part #99012) after some trial and error and four misprinted labels I came to the following LaTeX code which fits the text on the labels:

\documentclass{memoir}
\setstocksize{36mm}{89mm} %% dymo 99012 paper
\setlength{\headheight}{0mm}
\setlength{\headsep}{-28mm}
\setlength{\textwidth}{72mm} %% -17 mm
\setlength{\textheight}{28mm} %% -8 mm
\setlength{\oddsidemargin}{-16mm}
\setlength{\parindent}{0mm}

\begin{document}
...
\end{document}

For the actual text on the labels I use the following code (this should be placed at the dots (...) in the code above.

\sffamily
\textbf{My title}

\qquad The Author \\

\qquad\textbf{Genre} \\

ISBN: \textbf{9-785170-271955}\hfill2008

This LaTeX code is created by a little Perl script:

#!/usr/bin/perl
# labelfmt
# format bib db so that we can print labels
# gets standard sqlite text input:
# 663|9785170271955|Wat 3a Warom (russisch)|B. Barhep|computer|1998|1221413368|

use strict;
use warnings;
my $labelfile = "/tmp/label";

$_ = <>;  # only read one label at the time

my ($id, $i, $tit, $a, $g, $y) = split /\|/, $_;

# format the isbn number a bit
my @i = split //, $i;
local $"="";
$i = $i[0] . "-" . "@i[1..6]" . "-" . "@i[7..12]";

open TEX, ">", $labelfile . ".tex"; # yes, unsafe
select TEX;

print <<'EOF';
\documentclass{memoir}
\setstocksize{36mm}{89mm} %% dymo 99012 paper
\setlength{\headheight}{0mm}
\setlength{\headsep}{-28mm}
\setlength{\textwidth}{72mm} %% -6 mm
\setlength{\textheight}{28mm} %% -6 mm
\setlength{\oddsidemargin}{-16mm}
\setlength{\parindent}{0mm}

\begin{document}
\pagestyle{empty}
\sffamily
EOF

printf "\\textbf{%.30s}\n\n", $tit;
printf "\\qquad %.30s \\\\\n\n", $a;
printf "\\qquad\\textbf{%.30s} \\\\\n\n", uc $g;
printf "ISBN: \\textbf{%s}\\hfill%d\n", $i, $y;

print '\end{document}', "\n";
close TEX;

# now we make the pdf - after we clean up, the mess
if (system("pdflatex $labelfile") != 0) {
warn "Er ging iets falikant verkeerd";
} else {
unlink $labelfile . ".log", $labelfile . ".aux";
}

This will yield the following result

Example Label


Jul 05 2009

Biking with a GPS

Posted in life; by Miek Gieben; comments: 2

For the first time I took a GPS with me when mountain biking here in Nijmegen. So I can see the actual route we took at everytrail.com. Sure is cool what you can do on the web with your GPS data.

Map at EveryTrail

Only 11.4 km/h, but this is because we had some breaks on route. I'm a little bit amazed by the 'vertical up/down', 990 m up? Seems like a lot...


Jul 01 2009

Making a library

Posted in linux; by Miek Gieben; comments: 1

We (my wife and I) have a lot of books, currently some 637...

$ sqlite3 biblio.db 'select count(*) from books' 
637

But we seem to loose books occasionally because we lend them to people and forget about it. So Linux (and Perl) to the rescue. I already own a bar code reader to read the ISBN number of books and then I use Google to give the author, genre, etc. (fully automated of course).

To keep track of what we lend to people I want to use a piece of paper (don't know the right English term for this) to be put in the book. Every time we lend the book to someone we take out the paper and write the person's name on it. Just as in a real library, but more manual.

So now I want to print labels for our books and I need some paper on which I can sticker these labels.

First things first. So I've bought a Dymo 400 label printer. Which believe it or not just works out of the box on Ubuntu Jaunty.

Where are the go'old days when this kind of stuff took weeks??!

What next

Plug the label printer in a USB port, apt-get install cupsys, go to localhost:631, configure the label writer. Enter your user name and password when it asks for it and you are done.

The only extra thing I needed to do was to configure it to always print in landscape:

$ lpoptions -o landscape

Printing the labels

Printing with lpr now works 100% correct. So now I just need to format it so that it looks nice.

So I wrote a small Perl utility that transforms this (which is the standard output of sqlite3)

662|9780000000205|The Computer Revolution|Nigel
Hawkes|computer|1971|1221413260|

to this

The Computer Revolution
   Nigel Hawkes

   COMPUTER

ISBN: 9-780000-000205   1971

Which just fits on the label.

Hopefully this will keep us from loosing any books from now on.