]> git.sesse.net Git - nms/blob - config/make-dhcpd.pl
Update make-dhcpd.pl for TG06 (no split support yet).
[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         /194\.0\.(\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 "tg06.gathering.org";
22 option domain-name-servers 194.0.254.2;
23
24 # ddns-update-style none;
25 ddns-update-style interim;
26
27 key DHCP_UPDATER {
28         algorithm HMAC-MD5.SIG-ALG.REG.INT;
29         secret removed;
30 }
31
32 default-lease-time 14400;
33 max-lease-time 28800;
34
35 # Tele-nett
36 subnet 194.0.254.0 netmask 255.255.255.0 {
37 }
38
39 # Server-nett
40 subnet 194.0.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 = $netnames{$net};
52
53         my ($netmask, $numpc);
54         if ($netmasks{$net} == 24) {
55                 $netmask = "255.255.255.0";
56                 $numpc = 256;
57         } elsif ($netmasks{$net} == 25) {
58                 $netmask = "255.255.255.128";
59                 $numpc = 128;
60         } elsif ($netmasks{$net} == 26) {
61                 $netmask = "255.255.255.192";
62                 $numpc = 64;
63         } else {
64                 die "Unknown netmask /$netmasks{$net}";
65         }
66
67         $net =~ /(\d+)\.(\d+)/ or die "Unknown net $net";
68         my ($majorsubnet,$minorsubnet) = ($1,$2);
69         
70         my $gw = "194.0.$majorsubnet." . ($minorsubnet + 1);
71         my $rangestart = "194.0.$majorsubnet." . ($minorsubnet + 10);
72         my $rangeend = "194.0.$majorsubnet." . ($minorsubnet + $numpc - 2);
73
74         print <<"EOF";
75 zone $domain.tg06.gathering.org. {
76         primary 127.0.0.1;
77         key DHCP_UPDATER;
78 }
79 subnet 194.0.$net netmask $netmask {
80         authoritative;
81         range $rangestart $rangeend;
82         option routers $gw;
83
84         option domain-name "$domain.tg06.gathering.org";
85         ddns-domainname "$domain.tg06.gathering.org";
86         ignore client-updates;
87 EOF
88
89         # hack for sesse =)
90 #       if ($net eq '250.0') {
91 #               print <<"EOF";
92 #       host trofast {
93 #               hardware ethernet 00:0e:0c:36:a7:66;
94 #               filename "/pxelinux.0";
95 #               next-server 194.0.254.89;
96 #       }
97 #EOF
98         }
99         
100         print "}\n";
101 }