Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of IPv6 support #151

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ openvpn_route_traffic: false
# Whether to create an iptables rule to allow connections to the openvpn server.
openvpn_open_firewall: true

# Listening also for IPv6
openvpn_ipv6_enabled: false

openvpn_ipv6_server: ''
# 2001:1::/64

openvpn_ipv6_ifconfig: ''
# 2001:1:1 2001:1::2

openvpn_ipv6_route_default: ''
# 2001:1::1

openvpn_ipv6_route_ranges: []
# - 2000:1::/64
# - 2000:3::/64

# The interface that traffic will come in from. This is used when creating
# firewall rules to allow the vpn server to successfully forward traffic (see
# `openvpn_route_traffic`). The interface you specify here will limit these
Expand Down
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
command: /etc/init.d/iptables-persistent save
when:
- ansible_os_family == "Debian"
- ansible_lsb.codename == "trusty"
- ansible_distribution_release == "trusty"
listen: openvpn save iptables

- name: Save the rules (Ubuntu)
command: netfilter-persistent save
when:
- ansible_os_family == "Debian"
- ansible_lsb.codename != "trusty"
- ansible_distribution_release != "trusty"
listen: openvpn save iptables

- name: Restart OpenVPN service
Expand Down
2 changes: 0 additions & 2 deletions tasks/openvpn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@

- include_tasks: "system/bridge/{{ ansible_os_family }}.yml"

- include_tasks: "system/bridge/{{ ansible_os_family }}.yml"

- include_tasks: service.yml
9 changes: 9 additions & 0 deletions tasks/system/forwarding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@
state: present
reload: true
when: not lookup('env', 'IN_MOLECULE') | d(true, true) | bool

- name: Set IPv6 forwarding in the sysctl file and reload if necessary
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also rename the previous task to say IPv4?

Choose a reason for hiding this comment

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

Done in c1cbc8c

sysctl:
name: net.ipv6.conf.all.forwarding
value: '1'
sysctl_set: true
state: present
reload: true
when: not lookup('env', 'IN_MOLECULE') | d(true, true) | bool and openvpn_ipv6_server is defined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you break this when into a list?

Choose a reason for hiding this comment

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

Done in c1cbc8c

19 changes: 18 additions & 1 deletion templates/server.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
{% if openvpn_local is defined -%}
local {{ openvpn_local }}
{% else -%}
;local a.b.c.d {% endif %}
;local a.b.c.d
{% endif %}

# Which TCP/UDP port should OpenVPN listen on? If you want to run multiple
# OpenVPN instances on the same machine, use a different port number for each
Expand All @@ -14,6 +15,10 @@ port {{ openvpn_port }}
# TCP or UDP server?
proto {{ openvpn_proto }}

{% if openvpn_ipv6_enabled %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add | bool for consistency.

Choose a reason for hiding this comment

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

Done in c1cbc8c

proto {{ openvpn_proto }}6
{% endif %}

{% if openvpn_portshare is defined %}
# Port sharing
port-share 127.0.0.1 {{ openvpn_portshare }}
Expand All @@ -31,6 +36,9 @@ cipher {{ openvpn_cipher }}
# most systems, the VPN will not function unless you partially or fully disable
# the firewall for the TUN/TAP interface.
dev {{ openvpn_dev }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you leave the non-ipv6 options outside of a conditional? Does this work?

Choose a reason for hiding this comment

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

Yes, this works

{% if openvpn_ipv6_enabled %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add | bool for consistency.

Choose a reason for hiding this comment

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

Done in c1cbc8c

dev {{ openvpn_dev }}-ipv6
{% endif %}

# SSL/TLS root certificate (ca), certificate (cert), and private key (key).
# Each client and the server must have their own cert and key file. The server
Expand Down Expand Up @@ -73,6 +81,11 @@ topology {{ openvpn_topology }}
# 10.8.0.1. Comment this line out if you are ethernet bridging. See the man
# page for more info.
server {{ openvpn_server }}
{% if openvpn_ipv6_enabled and openvpn_ipv6_server is defined %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

add | bool

Choose a reason for hiding this comment

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

Done in c1cbc8c

server-ipv6 {{ openvpn_ipv6_server }}
ifconfig-ipv6 {{ openvpn_ipv6_ifconfig }}
push "route-ipv6-default {{ openvpn_ipv6_route_default }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't find an option named route-ipv6-default. Where is this documented?

Also, why do you need lines 86-87 unconditionally when ipv6 is used?

Choose a reason for hiding this comment

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

openvpn_ipv6_server is defined will always be true. This variable is defined in defaults/main.yml as an empty string, what will matter in this template is if it's still empty or not.

According to the OpenVPN wiki

There are 2 ways to add IPv6 addressing and pool options to the server, similar to what OpenVPN supports for IPv4: using a helper-directive, and by expanding the helper-directive. The expansion is required if you do not wish to use the automatic values the helper-directive supplies.

  • therefore ifconfig-ipv6 will be a complementary and optional configuration
  • route-ipv6-default doesn't exist, it's optional, and can be pushed with the variable openvpn_ipv6_route_ranges which is defined as an empty list by default.

Choose a reason for hiding this comment

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

Done in c1cbc8c

{% endif %}
{% endif %}
{% if openvpn_bridge %}
# Configure server mode for ethernet bridging.
Expand Down Expand Up @@ -190,3 +203,7 @@ push "dhcp-option DNS {{ dns }}"
{% for push_route in openvpn_route_ranges %}
push "route {{ push_route }}"
{% endfor %}

{% for push_route_ipv6 in openvpn_ipv6_route_ranges %}
push "route-ipv6 {{ push_route_ipv6 }}"
{% endfor %}