Skip to content

[Fix] Support multiple wireguard tunnels on same device #657#666

Merged
nemesifier merged 3 commits into
masterfrom
issues/657-multiple-wireguard-tunnels
Jun 24, 2022
Merged

[Fix] Support multiple wireguard tunnels on same device #657#666
nemesifier merged 3 commits into
masterfrom
issues/657-multiple-wireguard-tunnels

Conversation

@codesankalp

Copy link
Copy Markdown
Member

Fixes #657

Comment on lines +34 to +49
def disallow_multiple_wireguard_tunneling(apps, schema_editor):
templates = get_wireguard_and_vxlan_wireguard_templates(apps).iterator()
for template in templates:
config = template.config
interfaces = config['interfaces']
vpn_id = template.vpn.pk.hex
changed = False
for interface in interfaces:
if f'client_private_key_{vpn_id}' not in interface['private_key']:
continue
interface['private_key'] = '{{private_key}}'
changed = True
if not changed:
continue
template.config = config
template.save(update_fields=['config'])

@codesankalp codesankalp Jun 24, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this to unapply migration and thought it would be better to keep it here to revert the changes if anything goes wrong with the working of wireguard.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's good thanks!

@codesankalp
codesankalp force-pushed the issues/657-multiple-wireguard-tunnels branch from 92bb836 to 3f52468 Compare June 24, 2022 17:45
@coveralls

coveralls commented Jun 24, 2022

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 98.548% when pulling 6f3bcce on issues/657-multiple-wireguard-tunnels into 2504eaa on master.

Comment thread openwisp_controller/config/base/vpn.py Outdated
context_keys['server_ip_network']
] = f'{self.ip.ip_address}/{self.subnet.subnet.max_prefixlen}'
context[context_keys['vpn_subnet']] = str(self.subnet.subnet)
context[context_keys['private_key']] = '{{private_key}}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not super clear to me what is this used for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length of private_key variable was longer than expected in validation when it was not defined, so I used this as boilerplate to pass a smaller length value which looks more like the previous one.

Comment thread openwisp_controller/config/migrations/0042_multiple_wireguard_tunnels.py Outdated
Comment thread openwisp_controller/config/migrations/0042_multiple_wireguard_tunnels.py Outdated
Comment thread openwisp_controller/config/migrations/0042_multiple_wireguard_tunnels.py Outdated
Comment thread openwisp_controller/config/migrations/0042_multiple_wireguard_tunnels.py Outdated
@codesankalp
codesankalp force-pushed the issues/657-multiple-wireguard-tunnels branch from b33e10f to 6f3bcce Compare June 24, 2022 19:45
@codesankalp
codesankalp requested a review from nemesifier June 24, 2022 19:46
@codesankalp codesankalp self-assigned this Jun 24, 2022
@nemesifier
nemesifier merged commit c02d527 into master Jun 24, 2022
@nemesifier
nemesifier deleted the issues/657-multiple-wireguard-tunnels branch June 24, 2022 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] Can't support multiple wireguard tunnels on the same devices

3 participants