]> git.sesse.net Git - nms/blob - config/make-dhcpd.pl
Fix reverse DHCP automagic.
[nms] / config / make-dhcpd.pl
1 #! /usr/bin/perl -w
2 use strict;
3
4 my $date = `date --rfc-2822`;
5 chomp $date;
6
7 my @nets = ();
8 open NAMES, "switches.txt"
9         or die "switches.txt: $!";
10 while (<NAMES>) {
11         chomp;
12         /87\.76\.(\d+\.\d+)\s+(\d+)\s+(\S+)/ or next;
13         push @nets, {
14                 net => $1,
15                 netmask => $2,
16                 name => $3
17         };
18 }       
19
20 print <<"EOF";
21 # Autogenerated by make-dhcpd.pl at $date. Do not edit manually!
22
23 option domain-name "tg07.gathering.org";
24 option domain-name-servers 87.76.254.2, 87.76.255.2;
25
26 ddns-update-style interim;
27 omapi-port 7911;
28
29 # dnssec-keygen -a HMAC-MD5 -b 128 -n HOST DHCP_UPDATER
30 key DHCP_UPDATER {
31         algorithm HMAC-MD5.SIG-ALG.REG.INT;
32         secret F388UOhaIIKHRH9TDE5PTA==;
33 }
34
35 default-lease-time 14400;
36 max-lease-time 28800;
37
38 # Tele-nett
39 subnet 87.76.254.0 netmask 255.255.255.0 {
40 }
41
42 # Server-nett
43 subnet 87.76.255.0 netmask 255.255.255.0 {
44 }
45
46 zone 76.87.in-addr.arpa. {
47         primary 127.0.0.1;
48         key DHCP_UPDATER;
49 }
50
51 EOF
52
53 for my $net (@nets) {
54         my $domain = $net->{name};
55
56         my ($netmask, $numpc);
57         if ($net->{netmask} == 24) {
58                 $netmask = "255.255.255.0";
59                 $numpc = 256;
60         } elsif ($net->{netmask} == 25) {
61                 $netmask = "255.255.255.128";
62                 $numpc = 128;
63         } elsif ($net->{netmask} == 26) {
64                 $netmask = "255.255.255.192";
65                 $numpc = 64;
66         } else {
67                 die "Unknown netmask /" . $net->{netmask};
68         }
69
70         $net->{net} =~ /(\d+)\.(\d+)/ or die "Unknown net $net";
71         my ($majorsubnet,$minorsubnet) = ($1,$2);
72
73         # FIXME: Should use Net::CIDR
74         my $gw = "87.76.$majorsubnet." . ($minorsubnet + 1);
75         my $rangestart = "87.76.$majorsubnet." . ($minorsubnet + 10);
76         my $rangeend = "87.76.$majorsubnet." . ($minorsubnet + $numpc - 2);
77
78         print <<"EOF";
79 zone $domain.tg07.gathering.org. {
80         primary 127.0.0.1;
81         key DHCP_UPDATER;
82 }
83 subnet 87.76.$net->{net} netmask $netmask {
84         authoritative;
85         option routers $gw;
86
87         range $rangestart $rangeend;
88         option domain-name "$domain.tg07.gathering.org";
89         ddns-domainname "$domain.tg07.gathering.org";
90         ignore client-updates;
91 }
92 EOF
93 }
94