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

Commit d275f30

Browse files
committed
add support for IP routing rules
Upstream documentation at: https://openwrt.org/docs/guide-user/network/routing/ip_rules Example configuration: PBR for traffic arriving on 'guest' interface rerouted to table 2000 which routes to VPN: ```yaml openwrt_network_rules4: guest_wifi_through_vpn: in: guest_wifi lookup: '2000' priority: '3000' ``` or IPV6: ```yaml openwrt_network_rules6: dmz_nullroute_fdca: in: dmz dest: 'fdca:1234::/64' action: 'blackhole' ```
1 parent 3b6c3f0 commit d275f30

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

roles/ansible_openwrtnetwork/templates/functions.jinja2

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,65 @@ config interface "{{ key }}"
390390
{% endif %}
391391
{% endfor %}
392392
{% endmacro %}
393+
394+
395+
{% macro create_rules(rules, family) %}
396+
{% for key, value in rules.items() %}
397+
{% if family == 4 %}
398+
config rule '{{ key }}'
399+
{% elif family == 6 %}
400+
config rule6 '{{ key }}'
401+
{% endif %}
402+
403+
{% if value['in'] is defined %}
404+
option in "{{ value['in'] }}"
405+
{% endif %}
406+
{% if value['out'] is defined %}
407+
option out "{{ value['out'] }}"
408+
{% endif %}
409+
{% if value['src'] is defined %}
410+
option src "{{ value['src'] }}"
411+
{% endif %}
412+
{% if value['dest'] is defined %}
413+
option dest "{{ value['dest'] }}"
414+
{% endif %}
415+
{% if value['tos'] is defined %}
416+
option tos "{{ value['tos'] }}"
417+
{% endif %}
418+
{% if value['mark'] is defined %}
419+
option mark "{{ value['mark'] }}"
420+
{% endif %}
421+
{% if value['uidrange'] is defined %}
422+
option uidrange "{{ value['uidrange'] }}"
423+
{% endif %}
424+
{% if value['suppress_prefixlength'] is defined %}
425+
option suppress_prefixlength "{{ value['suppress_prefixlength'] }}"
426+
{% endif %}
427+
{% if value['invert'] is defined %}
428+
option invert "{{ value['invert'] }}"
429+
{% endif %}
430+
{% if value['priority'] is defined %}
431+
option priority "{{ value['priority'] }}"
432+
{% endif %}
433+
{% if value['lookup'] is defined %}
434+
option lookup "{{ value['lookup'] }}"
435+
{% endif %}
436+
{% if value['goto'] is defined %}
437+
option goto "{{ value['goto'] }}"
438+
{% endif %}
439+
{% if value['action'] is defined %}
440+
option action "{{ value['action'] }}"
441+
{% endif %}
442+
{% if value['disabled'] is defined %}
443+
option disabled "{{ value['disabled'] }}"
444+
{% endif %}
445+
{% endfor %}
446+
{% endmacro %}
447+
448+
{% macro create_rules4(allrules4) %}
449+
{{ create_rules(allrules4, 4)}}
450+
{% endmacro %}
451+
452+
{% macro create_rules6(allrules6) %}
453+
{{ create_rules(allrules6, 6)}}
454+
{% endmacro %}

roles/ansible_openwrtnetwork/templates/network.jinja2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ config globals "globals"
4040
{% if openwrt_network_staticroutes6 is defined %}
4141
{{ functions.create_staticroutes6(openwrt_network_staticroutes6) }}
4242
{% endif %}
43+
44+
{% if openwrt_network_rules4 is defined %}
45+
# IPv4 rules
46+
{{ functions.create_rules4(openwrt_network_rules4) }}
47+
{% endif %}
48+
49+
{% if openwrt_network_rules6 is defined %}
50+
# IPv6 rules
51+
{{ functions.create_rules6(openwrt_network_rules6) }}
52+
{% endif %}

0 commit comments

Comments
 (0)