summaryrefslogtreecommitdiff
path: root/data/templates/dhcp-server/dhcpd.conf.tmpl
blob: a2d5cb24299f48f8b0374c9e9df699251e31d3b3 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
### Autogenerated by dhcp_server.py ###

# For options please consult the following website:
# https://www.isc.org/wp-content/uploads/2017/08/dhcp43options.html
#
# log-facility local7;
{% if hostfile_update is defined %}
on release {
    set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
    set ClientIp = binary-to-ascii(10, 8, ".",leased-address);
    set ClientMac = binary-to-ascii(16, 8, ":",substring(hardware, 1, 6));
    set ClientDomain = pick-first-value(config-option domain-name, "..YYZ!");
    execute("/usr/libexec/vyos/system/on-dhcp-event.sh", "release", ClientName, ClientIp, ClientMac, ClientDomain);
}
on expiry {
    set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
    set ClientIp = binary-to-ascii(10, 8, ".",leased-address);
    set ClientMac = binary-to-ascii(16, 8, ":",substring(hardware, 1, 6));
    set ClientDomain = pick-first-value(config-option domain-name, "..YYZ!");
    execute("/usr/libexec/vyos/system/on-dhcp-event.sh", "release", ClientName, ClientIp, ClientMac, ClientDomain);
}
{% endif %}

{{ 'use-host-decl-names on;' if host_decl_name is defined }}
ddns-update-style {{ 'interim' if dynamic_dns_update is defined else 'none' }};
option rfc3442-static-route code 121 = array of integer 8;
option windows-static-route code 249 = array of integer 8;
option wpad-url code 252 = text;

{% if global_parameters is defined and global_parameters is not none %}
# The following {{ global_parameters | length }} line(s) have been added as
# global-parameters in the CLI and have not been validated !!!
{%   for parameter in global_parameters %}
{{ parameter }}
{%   endfor %}

{% endif %}
{% if failover is defined and failover is not none %}
# DHCP failover configuration
failover peer "{{ failover.name }}" {
{%   if failover.status == 'primary' %}
    primary;
    mclt 1800;
    split 128;
{%   elif failover.status == 'secondary' %}
    secondary;
{%   endif %}
    address {{ failover.source_address }};
    port 520;
    peer address {{ failover.remote }};
    peer port 520;
    max-response-delay 30;
    max-unacked-updates 10;
    load balance max seconds 3;
}
{% endif %}
{% if listen_address is defined and listen_address is not none %}

# DHCP server serving relay subnet, we need a connector to the real world
{%   for address in listen_address %}
# Connected subnet statement for listen-address {{ address }}
subnet {{ address | network_from_ipv4 }} netmask {{ address | netmask_from_ipv4 }} { }
{%   endfor %}
{% endif %}

# Shared network configration(s)
{% if shared_network_name is defined and shared_network_name is not none %}
{%   for network, network_config in shared_network_name.items() if network_config.disable is not defined %}
shared-network {{ network | replace('_','-') }} {
{%     if network_config.authoritative is defined %}
    authoritative;
{%     endif %}
{%     if network_config.name_server is defined and network_config.name_server is not none %}
    option domain-name-servers {{ network_config.name_server | join(', ') }};
{%     endif %}
{%     if network_config.domain_name is defined and network_config.domain_name is not none %}
    option domain-name "{{ network_config.domain_name }}";
{%     endif %}
{%     if network_config.ping_check is defined %}
    ping-check true;
{%     endif %}
{%     if network_config.shared_network_parameters is defined and network_config.shared_network_parameters is not none %}
    # The following {{ network_config.shared_network_parameters | length }} line(s)
    # were added as shared-network-parameters in the CLI and have not been validated
{%       for parameter in network_config.shared_network_parameters %}
    {{ parameter }}
{%       endfor %}
{%     endif %}
{%     if network_config.subnet is defined and network_config.subnet is not none %}
{%       for subnet, subnet_config in network_config.subnet.items() %}
    subnet {{ subnet | address_from_cidr }} netmask {{ subnet | netmask_from_cidr }} {
{%         if subnet_config.name_server is defined and subnet_config.name_server is not none %}
        option domain-name-servers {{ subnet_config.name_server | join(', ') }};
{%         endif %}
{%         if subnet_config.domain_search is defined and subnet_config.domain_search is not none %}
        option domain-search "{{ subnet_config.domain_search | join('", "') }}";
{%         endif %}
{%         if subnet_config.ntp_server is defined and subnet_config.ntp_server is not none %}
        option ntp-servers {{ subnet_config.ntp_server | join(', ') }};
{%         endif %}
{%         if subnet_config.pop_server is defined and subnet_config.pop_server is not none %}
        option pop-server {{ subnet_config.pop_server | join(', ') }};
{%         endif %}
{%         if subnet_config.smtp_server is defined and subnet_config.smtp_server is not none %}
        option smtp-server {{ subnet_config.smtp_server | join(', ') }};
{%         endif %}
{%         if subnet_config.time_server is defined and subnet_config.time_server is not none %}
        option time-servers {{ subnet_config.time_server | join(', ') }};
{%         endif %}
{%         if subnet_config.wins_server is defined and subnet_config.wins_server is not none %}
        option netbios-name-servers {{ subnet_config.wins_server | join(', ') }};
{%         endif %}
{%         if subnet_config.static_route is defined and subnet_config.static_route is not none %}
{%           set static_default_route = '' %}
{%           if subnet_config.default_router and subnet_config.default_router is not none %}
{%             set static_default_route = ', ' + '0.0.0.0/0' | isc_static_route(subnet_config.default_router) %}
{%           endif %}
{%           if subnet_config.static_route is defined and subnet_config.static_route is not none %}
{%           set rfc3442_routes = [] %}
{%           for route, route_options in subnet_config.static_route.items() %}
{%             set rfc3442_routes = rfc3442_routes.append(route | isc_static_route(route_options.next_hop)) %}
{%           endfor %}
        option rfc3442-static-route {{ rfc3442_routes | join(', ') }}{{ static_default_route }};
        option windows-static-route {{ rfc3442_routes | join(', ') }};
{%           endif %}
{%         endif %}
{%         if subnet_config.ip_forwarding is defined %}
        option ip-forwarding true;
{%         endif %}
{%         if subnet_config.default_router and subnet_config.default_router is not none %}
        option routers {{ subnet_config.default_router }};
{%         endif %}
{%         if subnet_config.server_identifier is defined and subnet_config.server_identifier is not none %}
        option dhcp-server-identifier {{ subnet_config.server_identifier }};
{%         endif %}
{%         if subnet_config.domain_name is defined and subnet_config.domain_name is not none %}
        option domain-name "{{ subnet_config.domain_name }}";
{%         endif %}
{%         if subnet_config.subnet_parameters is defined and subnet_config.subnet_parameters is not none %}
        # The following {{ subnet_config.subnet_parameters | length }} line(s) were added as
        # subnet-parameters in the CLI and have not been validated!!!
{%           for parameter in subnet_config.subnet_parameters %}
        {{ parameter }}
{%           endfor %}
{%         endif %}
{%         if subnet_config.tftp_server_name is defined and subnet_config.tftp_server_name is not none %}
        option tftp-server-name "{{ subnet_config.tftp_server_name }}";
{%         endif %}
{%         if subnet_config.bootfile_name is defined and subnet_config.bootfile_name is not none %}
        option bootfile-name "{{ subnet_config.bootfile_name }}";
        filename "{{ subnet_config.bootfile_name }}";
{%         endif %}
{%         if subnet_config.bootfile_server is defined and subnet_config.bootfile_server is not none %}
        next-server {{ subnet_config.bootfile_server }};
{%         endif %}
{%         if subnet_config.time_offset is defined and subnet_config.time_offset is not none %}
        option time-offset {{ subnet_config.time_offset }};
{%         endif %}
{%         if subnet_config.wpad_url is defined and subnet_config.wpad_url is not none %}
        option wpad-url "{{ subnet_config.wpad_url }}";
{%         endif %}
{%         if subnet_config.client_prefix_length is defined and subnet_config.client_prefix_length is not none %}
        option subnet-mask {{ subnet_config.client_prefix_length }};
{%         endif %}
{%         if subnet_config.lease is defined and subnet_config.lease is not none %}
        default-lease-time {{ subnet_config.lease }};
        max-lease-time {{ subnet_config.lease }};
{%         endif %}
{%         if network_config.ping_check is not defined and subnet_config.ping_check is defined %}
        ping-check true;
{%         endif %}
{%         if subnet_config.static_mapping is defined and subnet_config.static_mapping is not none %}
{%           for host, host_config in subnet_config.static_mapping.items() if host_config.disable is not defined %}
        host {{ host | replace('_','-') if host_decl_name is defined else network | replace('_','-') + '_' + host | replace('_','-') }} {
{%             if host_config.ip_address is defined and host_config.ip_address is not none %}
            fixed-address {{ host_config.ip_address }};
{%             endif %}
            hardware ethernet {{ host_config.mac_address }};
{%             if host_config.static_mapping_parameters is defined and host_config.static_mapping_parameters is not none %}
            # The following {{ host_config.static_mapping_parameters | length }} line(s) were added
            # as static-mapping-parameters in the CLI and have not been validated
{%               for parameter in host_config.static_mapping_parameters %}
            {{ parameter }}
{%               endfor %}
{%             endif %}
        }
{%           endfor %}
{%         endif %}
{%         if subnet_config.range is defined and subnet_config.range is not none %}
{#           pool configuration can only be used if there follows a range option #}
        pool {
{%         endif %}
{%         if subnet_config.enable_failover is defined %}
            failover peer "{{ failover.name }}";
            deny dynamic bootp clients;
{%         endif %}
{%           if subnet_config.range is defined and subnet_config.range is not none %}
{%             for range, range_options in subnet_config.range.items() %}
            range {{ range_options.start }} {{ range_options.stop }};
{%             endfor %}
{%           endif %}
{%         if subnet_config.range is defined and subnet_config.range is not none %}
{#           pool configuration can only be used if there follows a range option #}
        }
{%         endif %}
    }
{%       endfor %}
{%     endif %}
    on commit {
        set shared-networkname = "{{ network | replace('_','-') }}";
{%     if hostfile_update is defined %}
        set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
        set ClientIp = binary-to-ascii(10, 8, ".", leased-address);
        set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
        set ClientDomain = pick-first-value(config-option domain-name, "..YYZ!");
        execute("/usr/libexec/vyos/system/on-dhcp-event.sh", "commit", ClientName, ClientIp, ClientMac, ClientDomain);
{%     endif %}
    }
}

{%   endfor %}
{% endif %}