Skip to content

Commit

Permalink
Add rfc3442 support - option for static routes
Browse files Browse the repository at this point in the history
Closes GH-43
  • Loading branch information
davidblaisonneau-orange authored and ekohl committed May 6, 2015
1 parent 80ad64b commit c22f464
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions manifests/pool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$nameservers = undef,
$pxeserver = undef,
$domain_name = undef,
$static_routes = undef,
) {

concat_fragment { "dhcp.conf+70_${name}.dhcp":
Expand Down
3 changes: 3 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
:dnsupdatekey => 'mydnsupdatekey',
:pxeserver => '10.0.0.5',
:pxefilename => 'mypxefilename',
:option_static_route => true,
} end

let(:facts) do {
Expand Down Expand Up @@ -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;',
Expand Down
3 changes: 3 additions & 0 deletions spec/defines/pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;",
Expand Down
5 changes: 5 additions & 0 deletions templates/dhcpd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
6 changes: 6 additions & 0 deletions templates/dhcpd.pool.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>;
Expand Down

0 comments on commit c22f464

Please sign in to comment.