Skip to content

Commit

Permalink
Merge branch 'master' into issues/289-openwrt-wireless-network-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jul 9, 2024
2 parents 331a144 + 176b51b commit 1beb808
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_intermediate_loop(self, block, result, index=None):
return result

def __intermediate_peer(self, peer, index):
interface = peer.pop('interface')
interface = peer.pop('interface').replace('-', '_')
uci_name = f'wgpeer_{interface}'
if index > 1:
uci_name = f'{uci_name}_{index}'
Expand Down
5 changes: 0 additions & 5 deletions netjsonconfig/backends/wireguard/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ def __intermediate_vpn(self, config, remove=None):
config[self._forward_property_map[option]] = config.pop(option)
else:
config.pop(option, None)
# Remove default options
if config.get('Table') == 'auto':
config.pop('Table')
if config.get('MTU') == 1280:
config.pop('MTU')
config['peers'] = self.__intermediate_peers(config.get('peers', []))
return self.sorted_dict(config)

Expand Down
32 changes: 32 additions & 0 deletions tests/openwrt/test_wireguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,35 @@ def test_render_multiple_wireguard_peers(self):
def test_parse_multiple_wireguard_peers(self):
o = OpenWrt(native=self._multiple_peers_uci)
self.assertEqual(o.config, self._multiple_peers_netjson)

def test_render_dash(self):
o = OpenWrt(
{
"wireguard_peers": [
{
"interface": "wg-dash",
"public_key": "rn+isMBpyQ4HX6ZzE709bKnZw5IaLZoIS3hIjmfKCkk=",
"allowed_ips": ["10.0.0.1/32"],
"endpoint_host": "192.168.1.42",
"endpoint_port": 40840,
"preshared_key": "oPZmGdHBseaV1TF0julyElNuJyeKs2Eo+o62R/09IB4=",
"persistent_keepalive": 30,
"route_allowed_ips": True,
}
]
}
)
expected = self._tabs(
"""package network
config wireguard_wg_dash 'wgpeer_wg_dash'
list allowed_ips '10.0.0.1/32'
option endpoint_host '192.168.1.42'
option endpoint_port '40840'
option persistent_keepalive '30'
option preshared_key 'oPZmGdHBseaV1TF0julyElNuJyeKs2Eo+o62R/09IB4='
option public_key 'rn+isMBpyQ4HX6ZzE709bKnZw5IaLZoIS3hIjmfKCkk='
option route_allowed_ips '1'
"""
)
self.assertEqual(o.render(), expected)
2 changes: 2 additions & 0 deletions tests/wireguard/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ def test_confs(self):
PreDown = ip rule delete ipproto tcp dport 22 table 1234
PrivateKey = QFdbnuYr7rrF4eONCAs7FhZwP7BXX/jD/jq2LXCpaXI=
SaveConfig = true
Table = auto
# wireguard config: test2
[Interface]
Address = 10.0.1.1/24
DNS = 10.0.1.1,10.0.0.1
ListenPort = 40843
MTU = 1280
PrivateKey = AFdbnuYr7rrF4eONCAs7FhZwP7BXX/jD/jq2LXCpaXI=
Table = 1234
"""
Expand Down

0 comments on commit 1beb808

Please sign in to comment.