]> git.sesse.net Git - nms/blob - config/make-dhcpd.pl
Added make-dhcpd.pl from TG05.
[nms] / config / make-dhcpd.pl
1 #! /usr/bin/perl -w
2 use strict;
3
4 # les inn nettnavn
5 my %netnames = ();
6 my %netmasks = ();
7 my @nets = ();
8 open NAMES, "switches.txt"
9         or die "switches.txt: $!";
10 while (<NAMES>) {
11         chomp;
12         /81\.162\.(\d+\.\d+)\s+(\d+)\s+(\S+)/ or next;
13         $netmasks{$1} = $2;
14         $netnames{$1} = $3;
15         push @nets, $1;
16 }       
17
18 print <<"EOF";
19 # Autogenerated by make-dhcpd.pl. Do not edit manually!
20
21 option domain-name "tg05.gathering.org";
22 option domain-name-servers 81.162.254.2, 81.162.254.76;
23
24 ddns-update-style interim;
25
26 key DHCP_UPDATER {
27         algorithm HMAC-MD5.SIG-ALG.REG.INT;
28         secret removed;
29 }
30
31 default-lease-time 14400;
32 max-lease-time 28800;
33
34 # Servernett
35 subnet 81.162.254.0 netmask 255.255.255.192 {
36 }
37 subnet 81.162.254.64 netmask 255.255.255.192 {
38 }
39
40 zone 162.81.in-addr.arpa. {
41         primary 127.0.0.1;
42         key DHCP_UPDATER;
43 }
44
45 EOF
46
47 for my $net (@nets) {
48         my $domain = $netnames{$net};
49
50         my ($netmask, $numpc);
51         if ($netmasks{$net} == 24) {
52                 $netmask = "255.255.255.0";
53                 $numpc = 256;
54         } elsif ($netmasks{$net} == 25) {
55                 $netmask = "255.255.255.128";
56                 $numpc = 128;
57         } elsif ($netmasks{$net} == 26) {
58                 $netmask = "255.255.255.192";
59                 $numpc = 64;
60         } else {
61                 die "Unknown netmask /$netmasks{$net}";
62         }
63
64         $net =~ /(\d+)\.(\d+)/ or die "Unknown net $net";
65         my ($majorsubnet,$minorsubnet) = ($1,$2);
66         
67         my $gw = "81.162.$majorsubnet." . ($minorsubnet + 1);
68         my $rangestart = "81.162.$majorsubnet." . ($minorsubnet + 10);
69         my $rangeend = "81.162.$majorsubnet." . ($minorsubnet + $numpc - 2);
70
71         print <<"EOF";
72 zone $domain.tg05.gathering.org. {
73         primary 127.0.0.1;
74         key DHCP_UPDATER;
75 }
76 subnet 81.162.$net netmask $netmask {
77         authoritative;
78         range $rangestart $rangeend;
79         option routers $gw;
80
81         option domain-name "$domain.tg05.gathering.org";
82         ddns-domainname "$domain.tg05.gathering.org";
83         ignore client-updates;
84 EOF
85
86         # hack for sesse =)
87         if ($net eq '250.0') {
88                 print <<"EOF";
89         host trofast {
90                 hardware ethernet 00:0e:0c:36:a7:66;
91                 filename "/pxelinux.0";
92                 next-server 81.162.254.89;
93         }
94 EOF
95         }
96         
97         print "}\n";
98 }