Skip to content

Commit 404913f

Browse files
committed
server: Support multiple "local" options
Starting with OpenVPN 2.7 "local" can be specified multiple times (with differing addresses/ports/protocols). Signed-off-by: Frank Lichtenheld <[email protected]>
1 parent 6564c2f commit 404913f

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

REFERENCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,9 +1188,9 @@ Default value: `false`
11881188

11891189
##### <a name="-openvpn--server--local"></a>`local`
11901190

1191-
Data type: `String`
1191+
Data type: `Variant[String, Array[String]]`
11921192

1193-
Interface for openvpn to bind to.
1193+
Interface(s) for openvpn to bind to. To use the array form you need OpenVPN 2.7 or newer.
11941194

11951195
Default value: `$facts['networking']['ip']`
11961196

manifests/server.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# @param group User to drop privileges to after startup
1818
# @param ipp Persist ifconfig information to a file to retain client IP addresses between sessions
1919
# @param duplicate_cn Allow multiple connections on one cn
20-
# @param local Interface for openvpn to bind to.
20+
# @param local Interface(s) for openvpn to bind to. To use the array form you need OpenVPN 2.7 or newer.
2121
# @param logfile Logfile for this openvpn server
2222
# @param manage_logfile_directory Manage the directory that the logfile is located in
2323
# @param logdirectory_user The owner user of the logfile directory
@@ -163,7 +163,7 @@
163163
Optional[String] $group = undef,
164164
Boolean $ipp = false,
165165
Boolean $duplicate_cn = false,
166-
String $local = $facts['networking']['ip'],
166+
Variant[String, Array[String]] $local = $facts['networking']['ip'],
167167
Variant[Boolean, String] $logfile = false,
168168
Boolean $manage_logfile_directory = false,
169169
String[1] $logdirectory_user = 'nobody',

spec/defines/openvpn_server_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,40 @@
201201
it { is_expected.to contain_file("#{server_directory}/test_server.conf").with_content(%r{^rcvbuf\s+393215$}) }
202202
end
203203

204+
context 'with empty local' do
205+
let(:params) do
206+
{
207+
'country' => 'CO',
208+
'province' => 'ST',
209+
'city' => 'Some City',
210+
'organization' => 'example.org',
211+
'email' => '[email protected]',
212+
'local' => '',
213+
}
214+
end
215+
216+
it { is_expected.to contain_file("#{server_directory}/test_server.conf").
217+
without_content(%r{^local}) }
218+
end
219+
220+
context 'with array local' do
221+
let(:params) do
222+
{
223+
'country' => 'CO',
224+
'province' => 'ST',
225+
'city' => 'Some City',
226+
'organization' => 'example.org',
227+
'email' => '[email protected]',
228+
'local' => ['1.2.3.4 1194 udp4', '1111::2:3:4 1194 udp6'],
229+
}
230+
end
231+
232+
it { is_expected.to contain_file("#{server_directory}/test_server.conf").
233+
with_content(%r{^local\s+1\.2\.3\.4 1194 udp4}).
234+
with_content(%r{^local\s+1111::2:3:4 1194 udp6}) }
235+
end
236+
237+
204238
%w[udp tcp udp4 tcp4 udp6 tcp6].each do |proto|
205239
context "with proto=#{proto}" do
206240
let(:params) do

templates/server.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ status <%= @status_log %>
8888
status-version <%= @status_version %>
8989
<% end -%>
9090
dev <%= @dev %>
91-
<% if @local != '' -%>
92-
local <%= @local %>
91+
<% @local = [@local] unless @local.kind_of?(Array) -%>
92+
<% @local.each do |item| -%>
93+
<% if item != '' -%>
94+
local <%= item %>
95+
<% end -%>
9396
<% end -%>
9497
<% if @ipp -%>
9598
ifconfig-pool-persist <%= @name %>/vpn-ipp.txt

0 commit comments

Comments
 (0)