Skip to content

Commit 04e2bf2

Browse files
okraitsnemesifier
andauthored
[feature] OpenVpn: added option proto to remote setting
Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
1 parent bd0db29 commit 04e2bf2

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

netjsonconfig/backends/openvpn/converters.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ def __intermediate_vpn(self, config, remove=[False, 0, '']):
4242
del config[key]
4343
# reformat remote list in order for simpler handling in template
4444
if 'remote' in config:
45-
remote = ['{host} {port}'.format(**r) for r in config['remote']]
45+
remote = [
46+
'{host} {port} {proto}'.format(**r)
47+
if 'proto' in r.keys() and r['proto'] != 'auto'
48+
else '{host} {port}'.format(**r)
49+
for r in config['remote']
50+
]
4651
config['remote'] = remote
4752
# do not display status-version if status directive not present
4853
if 'status' not in config and 'status_version' in config:
@@ -95,7 +100,12 @@ def __netjson_vpn(self, vpn):
95100
if 'remote' in vpn:
96101
remote = []
97102
for r in vpn['remote']:
98-
host, port = r.split()
99-
remote.append(dict(host=host, port=int(port)))
103+
items = r.split()
104+
if len(items) == 3:
105+
remote.append(
106+
dict(host=items[0], port=int(items[1]), proto=items[2])
107+
)
108+
else:
109+
remote.append(dict(host=items[0], port=int(items[1])))
100110
vpn['remote'] = remote
101111
return vpn

netjsonconfig/backends/openvpn/schema.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,32 @@
517517
"minimum": 1,
518518
"propertyOrder": 2,
519519
},
520+
"proto": {
521+
"title": "protocol",
522+
"type": "string",
523+
"default": "auto",
524+
"enum": [
525+
"auto",
526+
"udp",
527+
"udp4",
528+
"udp6",
529+
"tcp",
530+
"tcp4",
531+
"tcp6",
532+
],
533+
"options": {
534+
"enum_titles": [
535+
"Default (automatically determined)",
536+
"UDP",
537+
"UDP IPv4",
538+
"UDP IPv6",
539+
"TCP",
540+
"TCP IPv4",
541+
"TCP IPv6",
542+
]
543+
},
544+
"propertyOrder": 3,
545+
},
520546
},
521547
},
522548
},

tests/openvpn/test_backend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def test_client_mode(self):
145145
"pull": True,
146146
"remote": [
147147
{"host": "vpn1.test.com", "port": 1194},
148-
{"host": "176.9.43.231", "port": 1195},
148+
{"host": "176.9.43.231", "port": 1195, "proto": "udp4"},
149+
{"host": "176.9.43.232", "port": 1195, "proto": "auto"},
150+
{"host": "176.9.43.233", "port": 1196, "proto": "udp6"},
149151
],
150152
"resolv_retry": "infinite",
151153
"script_security": 1,
@@ -191,7 +193,9 @@ def test_client_mode(self):
191193
proto tcp-client
192194
pull
193195
remote vpn1.test.com 1194
194-
remote 176.9.43.231 1195
196+
remote 176.9.43.231 1195 udp4
197+
remote 176.9.43.232 1195
198+
remote 176.9.43.233 1196 udp6
195199
resolv-retry infinite
196200
script-security 1
197201
status /var/log/openvpn.status 30

0 commit comments

Comments
 (0)