From c898baecf68147a133c6585930b444e6cbb2bdeb Mon Sep 17 00:00:00 2001
From: Jonathan Gazeley <jonathan.gazeley@bristol.ac.uk>
Date: Wed, 25 Nov 2015 12:39:40 +0000
Subject: [PATCH] Fix compatibility with FR2

---
 README.md                     | 32 +++++++++++++++++++++++++++++++-
 manifests/client.pp           |  2 +-
 templates/client.conf.fr2.erb |  5 +++--
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 2649f86..3651a87 100644
--- a/README.md
+++ b/README.md
@@ -211,6 +211,7 @@ Set file permissions on the installed certificate differently depending on wheth
 Define RADIUS clients as seen in `clients.conf`
 
 ```puppet
+# Single host example
 freeradius::client { "wlan-controller01":
   ip        => '192.168.0.1',
   secret    => 'testing123',
@@ -221,12 +222,41 @@ freeradius::client { "wlan-controller01":
 }
 ```
 
+```puppet
+# Range example on FreeRADIUS 2
+freeradius::client { "wlan-controllers":
+  ip        => '192.168.0.0',
+  netmask   => '24',
+  secret    => 'testing123',
+  shortname => 'wlc01',
+  nastype   => 'other',
+  port      => '1645-1646',
+  firewall  => true,
+}
+```
+
+```puppet
+# Range example in FreeRADIUS 3
+freeradius::client { "wlan-controllers":
+  ip        => '192.168.0.0/24',
+  secret    => 'testing123',
+  shortname => 'wlc01',
+  nastype   => 'other',
+  port      => '1645-1646',
+  firewall  => true,
+}
+```
+
 ##### `ip`
-The IP address of the client or range in CIDR notation.  For IPv6, use `ipv6addr`. `ip` and `ip6` are mutually exclusive but one must be supplied. Default: `undef`.
+The IP address of the client or range. For IPv6, use `ipv6addr`. `ip` and `ip6` are mutually exclusive but one must be supplied.
+On FreeRADIUS 2, specify the netmask separately. On FreeRADIUS 3, set `ip` in CIDR format. Default: `undef`.
 
 ##### `ip6`
 The IPv6 address of the client or range in CIDR notation. `ip` and `ip6` are mutually exclusive but one must be supplied. Default: `undef`.
 
+##### `netmask`
+The netmask of the client, specified as an integer, e.g. `24`. Only to be set on FreeRADIUS 2. Default: `undef`.
+
 ##### `shortname`
 A short alias that is used in place of the IP address or fully qualified hostname provided in the first line of the section. Required.
 
diff --git a/manifests/client.pp b/manifests/client.pp
index 500ab6d..542b9f9 100644
--- a/manifests/client.pp
+++ b/manifests/client.pp
@@ -30,7 +30,7 @@ define freeradius::client (
     default => "${ip6}/${netmask}",
   }
 
-  if ($netmask) {
+  if ($netmask and $fr_version == 3) {
     warning("netmask field found in client ${shortname} is deprecated, use CIDR notation instead. Please fix your configuration.")
   }
 
diff --git a/templates/client.conf.fr2.erb b/templates/client.conf.fr2.erb
index 4da0535..c7d9c28 100644
--- a/templates/client.conf.fr2.erb
+++ b/templates/client.conf.fr2.erb
@@ -1,6 +1,7 @@
 client <%= @shortname %> {
-	<% if @ip %>ipaddr= <%= @cidr %><% end %>
-	<% if @ip6 %>ipv6addr = <%= @cidr6 %><% end %>
+	<% if @ip %>ipaddr= <%= @ip %><% end %>
+	<% if @ip6 %>ipv6addr = <%= @ip6 %><% end %>
+	<% if @netmask %>netmask = <%= @netmask %><% end %>
 	shortname = <%= @shortname %>
 	secret = "<%= @secret %>"
 	<% if @virtual_server %>virtual_server = <%= @virtual_server %><% end %>
-- 
GitLab