SourceForge.net Logo

How to configure isc-dhcpd for RFC 3442 DHCP Listener Service

There is now native support for specifying classless routes options in the most commonly used isc-dhcpd DHCP server. However, classless routes can be easily passed to the clients using the vendor-encapsulated-options option.

This provided Perl function will generate the required vendor-encapsulated-options for the set of routes. There is also an example how to use this function.

#!/usr/bin/perl

use strict;

# Usage:
#   make_classless_option({ "subnet/mask" => "router", "subnet/mask" => "router", ... });
#     subnet   the subnet address, 4 dot-separated numbers
#     mask     the subnet mask length (e.g. /24 corresponds to 255.255.255.0, /8 corresponds to 255.0.0.0)
#     router   the router address, 4 dot-separated numbers
sub make_classless_option
{
    my $routes = shift;
    my ($s1, $s2, $s3, $s4, $len, @bytes, $net, $mask, $destination, $router);

    $len = 2;
    @bytes = ();
    foreach $destination(keys %{$routes}) {
        ($net, $mask) = split('/', $destination);
        $router = $routes->{$destination};
        ($s1, $s2, $s3, $s4) = split(/\./, $net);
        push(@bytes, sprintf('%02x', $mask));
        push(@bytes, sprintf('%02x', $s1));
        push(@bytes, sprintf('%02x', $s2)) if($mask > 8);
        push(@bytes, sprintf('%02x', $s3)) if($mask > 16);
        push(@bytes, sprintf('%02x', $s4)) if($mask > 24);
        ($s1, $s2, $s3, $s4) = split(/\./, $router);
        push(@bytes, sprintf('%02x', $s1));
        push(@bytes, sprintf('%02x', $s2));
        push(@bytes, sprintf('%02x', $s3));
        push(@bytes, sprintf('%02x', $s4));
    }

    return "option vendor-encapsulated-options 79:".sprintf('%02x', scalar @bytes).':'.join(':', @bytes);
}

# Sample usage

print make_classless_option({
        "172.16.0.0/12" => "10.0.0.1",
        "10.0.0.0/8" => "10.0.0.1"
        });


Copyright © 2004, Lev Shamardin <shamardin at theory.sinp.msu.ru>