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