Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from skrobul/ip-rules-support
Browse files Browse the repository at this point in the history
IP rules and common interface options support
  • Loading branch information
imp1sh authored Dec 25, 2023
2 parents 3b6c3f0 + 453a455 commit 6eecc66
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
88 changes: 82 additions & 6 deletions roles/ansible_openwrtnetwork/templates/functions.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ config interface "{{ key }}"
option device "{{ value['device'] }}"
{% endif %}
option proto "{{ value['proto'] }}"
{% if value['mtu'] is defined %}
option mtu "{{ value['mtu'] }}"
{% endif %}
{% if value['ipv6'] is defined %}
option ipv6 "{{ value['ipv6'] }}"
{% endif %}
{% if value['force_link'] is defined %}
option force_link "{{ value['force_link'] }}"
{% endif %}
{% if value['disabled'] is defined %}
option disabled "{{ value['disabled'] }}"
{% endif %}
{% if value['ip4table'] is defined %}
option ip4table "{{ value['ip4table'] }}"
{% endif %}
{% if value['ip6table'] is defined %}
option ip6table "{{ value['ip6table'] }}"
{% endif %}
{% if value['proto'] == "wireguard" %}
option private_key "{{ value['wg_private_key'] }}"
{% if value['wg_listen_port'] is defined %}
Expand Down Expand Up @@ -353,9 +371,7 @@ config interface "{{ key }}"
{% endif %}
{% if value['proto'] == "ppp" %}
# PPP config
{% if value['ipv6'] is defined %}
option ipv6 "value['ipv6']"
{% else %}
{% if value['ipv6'] is not defined %}
option ipv6 "auto"
{% endif %}
{% if value['device'] is defined %}
Expand All @@ -370,9 +386,7 @@ config interface "{{ key }}"
{% endif %}
{% if value['proto'] == "pppoe" %}
# PPPoE config
{% if value['ipv6'] is defined %}
option ipv6 "value['ipv6']"
{% else %}
{% if value['ipv6'] is not defined %}
option ipv6 "auto"
{% endif %}
{% if value['username'] is defined %}
Expand All @@ -390,3 +404,65 @@ config interface "{{ key }}"
{% endif %}
{% endfor %}
{% endmacro %}


{% macro create_rules(rules, family) %}
{% for key, value in rules.items() %}
{% if family == 4 %}
config rule '{{ key }}'
{% elif family == 6 %}
config rule6 '{{ key }}'
{% endif %}

{% if value['in'] is defined %}
option in "{{ value['in'] }}"
{% endif %}
{% if value['out'] is defined %}
option out "{{ value['out'] }}"
{% endif %}
{% if value['src'] is defined %}
option src "{{ value['src'] }}"
{% endif %}
{% if value['dest'] is defined %}
option dest "{{ value['dest'] }}"
{% endif %}
{% if value['tos'] is defined %}
option tos "{{ value['tos'] }}"
{% endif %}
{% if value['mark'] is defined %}
option mark "{{ value['mark'] }}"
{% endif %}
{% if value['uidrange'] is defined %}
option uidrange "{{ value['uidrange'] }}"
{% endif %}
{% if value['suppress_prefixlength'] is defined %}
option suppress_prefixlength "{{ value['suppress_prefixlength'] }}"
{% endif %}
{% if value['invert'] is defined %}
option invert "{{ value['invert'] }}"
{% endif %}
{% if value['priority'] is defined %}
option priority "{{ value['priority'] }}"
{% endif %}
{% if value['lookup'] is defined %}
option lookup "{{ value['lookup'] }}"
{% endif %}
{% if value['goto'] is defined %}
option goto "{{ value['goto'] }}"
{% endif %}
{% if value['action'] is defined %}
option action "{{ value['action'] }}"
{% endif %}
{% if value['disabled'] is defined %}
option disabled "{{ value['disabled'] }}"
{% endif %}
{% endfor %}
{% endmacro %}

{% macro create_rules4(allrules4) %}
{{ create_rules(allrules4, 4)}}
{% endmacro %}

{% macro create_rules6(allrules6) %}
{{ create_rules(allrules6, 6)}}
{% endmacro %}
10 changes: 10 additions & 0 deletions roles/ansible_openwrtnetwork/templates/network.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ config globals "globals"
{% if openwrt_network_staticroutes6 is defined %}
{{ functions.create_staticroutes6(openwrt_network_staticroutes6) }}
{% endif %}

{% if openwrt_network_rules4 is defined %}
# IPv4 rules
{{ functions.create_rules4(openwrt_network_rules4) }}
{% endif %}

{% if openwrt_network_rules6 is defined %}
# IPv6 rules
{{ functions.create_rules6(openwrt_network_rules6) }}
{% endif %}

0 comments on commit 6eecc66

Please sign in to comment.