diff --git a/README.md b/README.md index 3f8037f9..f06514a5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,16 @@ Override global attributes with pool specific pxeserver => '10.0.1.2', } +For the support of static routes (RFC3442): + + dhcp::pool{ 'ops.dc1.example.net': + network => '10.0.1.0', + mask => '255.255.255.0', + range => '10.0.1.100 10.0.1.200', + gateway => '10.0.1.1', + static_routes => [ { 'mask' => '32', 'network' => '169.254.169.254', 'gateway' => $ip } ], + } + ### dhcp::host Create host reservations. diff --git a/manifests/init.pp b/manifests/init.pp index caab2ccd..88601834 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,6 +14,7 @@ $dhcp_dir = $dhcp::params::dhcp_dir, $packagename = $dhcp::params::packagename, $servicename = $dhcp::params::servicename, + $option_static_route = undef, ) inherits dhcp::params { # Incase people set interface instead of interfaces work around diff --git a/manifests/pool.pp b/manifests/pool.pp index 2db619a3..dbac77d8 100644 --- a/manifests/pool.pp +++ b/manifests/pool.pp @@ -8,6 +8,7 @@ $nameservers = undef, $pxeserver = undef, $domain_name = undef, + $static_routes = undef, ) { concat_fragment { "dhcp.conf+70_${name}.dhcp": diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 55173a29..2c1ff8e6 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -41,6 +41,7 @@ :dnsupdatekey => 'mydnsupdatekey', :pxeserver => '10.0.0.5', :pxefilename => 'mypxefilename', + :option_static_route => true, } end let(:facts) do { @@ -72,6 +73,8 @@ 'option fqdn.no-client-update on; # set the "O" and "S" flag bits', 'option fqdn.rcode2 255;', 'option pxegrub code 150 = text ;', + 'option rfc3442-classless-static-routes code 121 = array of integer 8;', + 'option ms-classless-static-routes code 249 = array of integer 8;', 'next-server 10.0.0.5;', 'filename "mypxefilename";', 'log-facility local7;', diff --git a/spec/defines/pool_spec.rb b/spec/defines/pool_spec.rb index 302c22a6..af456e79 100644 --- a/spec/defines/pool_spec.rb +++ b/spec/defines/pool_spec.rb @@ -51,6 +51,7 @@ :nameservers => ['10.0.0.2', '10.0.0.4'], :pxeserver => '10.0.0.2', :domain_name => 'example.org', + :static_routes => [ { 'mask' => '24', 'network' => '10.0.1.0', 'gateway' => '10.0.0.2' } ], } end it { @@ -64,6 +65,8 @@ " option domain-name \"example.org\";", " option subnet-mask 255.255.255.0;", " option routers 10.0.0.1;", + " option rfc3442-classless-static-routes 24, 10, 0, 1, 0, 10, 0, 0, 2;", + " option ms-classless-static-routes 24, 10, 0, 1, 0, 10, 0, 0, 2;", " option ntp-servers 10.0.0.2;", " max-lease-time 300;", " option domain-name-servers 10.0.0.2, 10.0.0.4;", diff --git a/templates/dhcpd.conf.erb b/templates/dhcpd.conf.erb index 08ac50f2..ee758b39 100644 --- a/templates/dhcpd.conf.erb +++ b/templates/dhcpd.conf.erb @@ -34,6 +34,11 @@ option fqdn.no-client-update on; # set the "O" and "S" flag bits option fqdn.rcode2 255; option pxegrub code 150 = text ; +<% if has_variable?( 'option_static_route' ) && @option_static_route -%> +option rfc3442-classless-static-routes code 121 = array of integer 8; +option ms-classless-static-routes code 249 = array of integer 8; +<% end -%> + <% if has_variable?( 'pxeserver' ) && has_variable?( 'pxefilename' ) && @pxeserver && diff --git a/templates/dhcpd.pool.erb b/templates/dhcpd.pool.erb index 01279be8..f2006bb3 100644 --- a/templates/dhcpd.pool.erb +++ b/templates/dhcpd.pool.erb @@ -16,6 +16,12 @@ subnet <%= @network %> netmask <%= @mask %> { <% if @gateway && !@gateway.strip.empty? -%> option routers <%= @gateway %>; <% end -%> +<% if @static_routes + @static_routes.each do |static_route| -%> + option rfc3442-classless-static-routes <%= static_route['mask'] %>, <%= static_route['network'].split('.').join(', ') %>, <%= static_route['gateway'].split('.').join(', ') %>; + option ms-classless-static-routes <%= static_route['mask'] %>, <%= static_route['network'].split('.').join(', ') %>, <%= static_route['gateway'].split('.').join(', ') %>; +<% end -%> +<% end -%> <% if @options.is_a? Array -%> <% @options.each do |opt| -%> option <%= opt %>;