]> git.sesse.net Git - nms/blob - config/make-dhcpd.pl
Enable netboot for all.
[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 # Netboot FTW
27 next-server 87.76.255.18;
28 filename "/pxelinux.0";
29
30 ddns-update-style interim;
31 omapi-port 7911;
32
33 # dnssec-keygen -a HMAC-MD5 -b 128 -n HOST DHCP_UPDATER
34 key DHCP_UPDATER {
35         algorithm HMAC-MD5.SIG-ALG.REG.INT;
36         secret F388UOhaIIKHRH9TDE5PTA==;
37 }
38
39 default-lease-time 14400;
40 max-lease-time 28800;
41
42 # Tele-nett
43 subnet 87.76.254.0 netmask 255.255.255.0 {
44 }
45
46 # Server-nett
47 subnet 87.76.255.0 netmask 255.255.255.0 {
48 }
49
50 zone 76.87.in-addr.arpa. {
51         primary 127.0.0.1;
52         key DHCP_UPDATER;
53 }
54
55 EOF
56
57 for my $net (@nets) {
58         my $domain = $net->{name};
59
60         my ($netmask, $numpc);
61         if ($net->{netmask} == 24) {
62                 $netmask = "255.255.255.0";
63                 $numpc = 256;
64         } elsif ($net->{netmask} == 25) {
65                 $netmask = "255.255.255.128";
66                 $numpc = 128;
67         } elsif ($net->{netmask} == 26) {
68                 $netmask = "255.255.255.192";
69                 $numpc = 64;
70         } else {
71                 die "Unknown netmask /" . $net->{netmask};
72         }
73
74         $net->{net} =~ /(\d+)\.(\d+)/ or die "Unknown net $net";
75         my ($majorsubnet,$minorsubnet) = ($1,$2);
76
77         # FIXME: Should use Net::CIDR
78         my $gw = "87.76.$majorsubnet." . ($minorsubnet + 1);
79         my $rangestart = "87.76.$majorsubnet." . ($minorsubnet + 10);
80         my $rangeend = "87.76.$majorsubnet." . ($minorsubnet + $numpc - 2);
81
82         print <<"EOF";
83 zone $domain.tg07.gathering.org. {
84         primary 127.0.0.1;
85         key DHCP_UPDATER;
86 }
87 subnet 87.76.$net->{net} netmask $netmask {
88         authoritative;
89         option routers $gw;
90
91         range $rangestart $rangeend;
92         option domain-name "$domain.tg07.gathering.org";
93         ddns-domainname "$domain.tg07.gathering.org";
94         ignore client-updates;
95 }
96 EOF
97 }
98