$dayjob uses a Microsoft server for DHCP. Not really a problem, except out of the box, the (K)Ubuntu dhcp client (dhclient3) doesn’t actually support option 249 – classless-static-routes (or ms-classless-static-routes as some sites on the net refer to it). The format that the MS DCHP server spits out is the mask, followed by the subnet, followed by the gateway, in hexidecimal, delimited with colons.

So, after a bit of digging around on the net, and not finding anything that useful, I rolled my own code to deal with it. It’s not pretty, it’s probably not efficient, but it certainly works (for me).

First off, a new file in /etc/dhcp3/dhclient-exit-hooks.d

configure_ms_classless_static_routes

#!/bin/sh
function process_routes() {
 perl /etc/dhcp3/perl-classless.pl $1 $interface
}
if [ "$reason" = "BOUND" ]
 then
 echo "ms_classless_static_routes = $new_ms_classless_static_routes"
 process_routes $new_ms_classless_static_routes
fi

Second, a perl script

/etc/dhcp3/perl-classless.pl

#!/usr/bin/perl
# Input line will be a long hex string, seperated by :s
# MS DHCP feeds us Class : SN : SN : SN : SN : RT : RT : RT : RT
$unit = '[dw]{1,2}';
$in = $ARGV[0];
$nic = $ARGV[1];
while ($in =~ m/($unit:$unit:$unit:$unit:$unit:$unit:$unit:$unit:$unit)/) {
 $match = $1;
 $in =~ s/$match://;
 @i = split(/:/, $match);
 $exec = sprintf("ip route add to unicast %d.%d.%d.%d/%d via %d.%d.%d.%d dev %s",
 hex($i[1]),hex($i[2]),hex($i[3]),hex($i[4]),hex($i[0]),
 hex($i[5]),hex($i[6]),hex($i[7]),hex($i[8]),$nic),
 print $exec . "n";
 system($exec);
}

Presto, working Microsoft classless static routes via DHCP.

Dhclient3 and MS DHCP classless static routes
Tagged on: