diff options
Diffstat (limited to 'bootstrap/make-dhcpd6.pl')
-rwxr-xr-x | bootstrap/make-dhcpd6.pl | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/bootstrap/make-dhcpd6.pl b/bootstrap/make-dhcpd6.pl new file mode 100755 index 0000000..e27e0f4 --- /dev/null +++ b/bootstrap/make-dhcpd6.pl @@ -0,0 +1,140 @@ +#!/usr/bin/perl -I /root/tgmanage +use strict; + +use Net::IP; + +BEGIN { + require "include/config.pm"; + eval { + require "include/config.local.pm"; + }; +} + +my $base = "/etc"; +$base = $ARGV[0] if $#ARGV > -1; +$base .= "/" if not $base =~ m/\/$/ and not $base eq ""; + +my $dhcpd_base = $base . "dhcp/"; +my $dhcpd_conf = $dhcpd_base . "dhcpd.conf"; +my $dhcpd_pxeconf = $dhcpd_base . "v6-pxe-boot.conf"; +my $dhcpd_wlc_conf = $dhcpd_base . "v6-wlc.conf"; +my $dhcpd_voip_conf = $dhcpd_base . "v6-voip.conf"; + +# primary +my $pri_range = Net::IP->new($nms::config::pri_net) or die ("pri_range fail"); +my $pri_mask = $pri_range->mask(); +my $pri_net = $pri_range->ip(); + +# secondary +my $sec_range = Net::IP->new($nms::config::sec_net) or die ("sec_range fail"); +my $sec_mask = $sec_range->mask(); +my $sec_net = $sec_range->ip(); + +# Create PXE-boot configuration file for DHCP +if ( not -f $dhcpd_conf ) +{ + print STDERR "Creating file " . $dhcpd_conf . "\n"; + open DHCPDFILE, ">" . $dhcpd_conf or die ( $! . " " . $dhcpd_conf); + + print DHCPDFILE <<"EOF"; +# GENERATED BY make-dhcpd.pl +# +# Central concept: as little config in the main .conf, +# include almost everything from separate files.. +# +# log-facility local7; +option domain-name "$nms::config::tgname.gathering.org"; +option domain-name-servers $nms::config::pri_v4, $nms::config::sec_v4; +default-lease-time 3600; +max-lease-time 7200; +authoritative; + +ddns-update-style interim; +key DHCP_UPDATER { + algorithm HMAC-MD5.SIG-ALG.REG.INT; + secret $nms::config::ddns_key; +} + +subnet $pri_net netmask $pri_mask {} +subnet $sec_net netmask $sec_mask {} + +include "/etc/dhcp/v6-generated-include.conf"; +include "$dhcpd_pxeconf"; +#include "$dhcpd_wlc_conf"; +#include "$dhcpd_voip_conf"; + +EOF + close DHCPDFILE; +} + +# Create PXE-boot configuration file for DHCP +if ( not -f $dhcpd_pxeconf ) +{ + print STDERR "Creating file " . $dhcpd_pxeconf . "\n"; + open PXEFILE, ">" . $dhcpd_pxeconf or die ( $! . " " . $dhcpd_pxeconf); + + print PXEFILE <<"EOF"; +option dhcp6.bootfile-url code 59 = string; +option dhcp6.client-arch-type code 61 = array of unsigned integer 16; + +if option dhcp6.client-arch-type = 00:07 { + option dhcp6.bootfile-url "tftp://[$nms::config::pxe_server_v6]/bootx64.efi"; +} else { + # support a hypothetical BIOS system that can PXE boot over IPv6 + option dhcp6.bootfile-url "tftp://[$nms::config::pxe_server_v6]/pxelinux.0"; +} + +EOF + + close PXEFILE; +} + +# Create WLC configuration file +if ( not -f $dhcpd_wlc_conf ) +{ + print STDERR "Creating file " . $dhcpd_wlc_conf . "\n"; + open WLCFILE, ">" . $dhcpd_wlc_conf or die ( $! . " " . $dhcpd_wlc_conf); + + print WLCFILE <<"EOF"; +option space AP; +option AP.server-address code 241 = array of ip-address; +set vendor-string = option vendor-class-identifier; + +class "cisco-aps" { + match if substring (option vendor-class-identifier, 0, 8) = "Access Point"; + vendor-option-space AP; + option AP.server-address $nms::config::wlc1; +} +EOF + close WLCFILE; +} + +# Create VoIP config +if ( not -f $dhcpd_voip_conf ) +{ + print STDERR "Creating file " . $dhcpd_voip_conf . "\n"; + open VOIPFILE, ">" . $dhcpd_voip_conf or die ( $! . " " . $dhcpd_voip_conf); + + print VOIPFILE <<"EOF"; +option space CiscoVOIP; +option CiscoVOIP.cm-tftp-server code 150 = array of ip-address; + +class "cisco-voip-lan" { + match if substring (option vendor-class-identifier, 0, 28) = "Cisco Systems, Inc. IP Phone"; + vendor-option-space CiscoVOIP; + log( info, concat( "LOLOPHONE: " , option vendor-class-identifier )); + option CiscoVOIP.cm-tftp-server $nms::config::voip1; + next-server $nms::config::voip1; +} + +class "cisco-voip-wlan" { + match if substring (option vendor-class-identifier, 0, 33) = "Cisco Systems Inc. Wireless Phone"; + vendor-option-space CiscoVOIP; + log( info, concat( "BANANAPHONE: " , option vendor-class-identifier )); + option CiscoVOIP.cm-tftp-server $nms::config::voip1; + next-server $nms::config::voip1; +} +EOF + close VOIPFILE; +} + |