File: network_macros.lua.j2

package info (click to toggle)
knot-resolver 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,392 kB
  • sloc: javascript: 42,732; ansic: 40,312; python: 12,616; cpp: 2,121; sh: 1,997; xml: 193; makefile: 181
file content (55 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{% macro http_config(http_cfg, kind, tls=true) -%}
http.config({tls={{ 'true' if tls else 'false'}},
{%- if http_cfg.cert_file -%}
    cert='{{ http_cfg.cert_file }}',
{%- endif -%}
{%- if http_cfg.key_file -%}
    key='{{ http_cfg.key_file }}',
{%- endif -%}
},'{{ kind }}')
{%- endmacro %}


{% macro listen_kind(kind) -%}
{%- if kind == "dot" -%}
'tls'
{%- elif kind == "doh-legacy" -%}
'doh_legacy'
{%- else -%}
'{{ kind }}'
{%- endif -%}
{%- endmacro %}


{% macro net_listen_unix_socket(path, kind, freebind) -%}
net.listen('{{ path }}',nil,{kind={{ listen_kind(kind) }},freebind={{ 'true' if freebind else 'false'}}})
{%- endmacro %}


{% macro net_listen_interface(interface, kind, freebind, port) -%}
net.listen(
{%- if interface.addr -%}
'{{ interface.addr }}',
{%- elif interface.if_name -%}
net['{{ interface.if_name }}'],
{%- endif -%}
{%- if interface.port -%}
{{ interface.port }},
{%- else -%}
{{ port }},
{%- endif -%}
{kind={{ listen_kind(kind) }},freebind={{ 'true' if freebind else 'false'}}})
{%- endmacro %}


{% macro network_listen(listen) -%}
{%- if listen.unix_socket -%}
{% for path in listen.unix_socket %}
{{ net_listen_unix_socket(path, listen.kind, listen.freebind) }}
{% endfor %}
{%- elif listen.interface -%}
{% for interface in listen.interface %}
{{ net_listen_interface(interface, listen.kind, listen.freebind, listen.port) }}
{% endfor %}
{%- endif -%}
{%- endmacro %}