From 18df5946fbe01f2aa5c6cead66a3d7590c422a36 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sat, 29 Oct 2022 15:59:44 -0700 Subject: [PATCH] feat: add some non "options" prefixed options Adding option like filename and next-server for the match section. There is a bit of refactoring done as well that could be extended to avoid repeating the options stuff everywhere... It can be used in this kind of situation: ``` class "x32_uefi" { match if option clientarch = 00:06; filename "/tftpboot/bootia32.efi"; next-server 1.2.3.4; } ``` --- dhcpd/files/dhcpd.conf | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dhcpd/files/dhcpd.conf b/dhcpd/files/dhcpd.conf index a4078c9..8c63c4c 100644 --- a/dhcpd/files/dhcpd.conf +++ b/dhcpd/files/dhcpd.conf @@ -170,6 +170,20 @@ option {{ option|replace('_', '-') }} {{ quote }}{{ dhcpd.get(option) }}{{ quote {%- endif %} {%- endfor %} +{#- ### Option related macro ### #} +{%- macro print_option(option, value) %} + {%- if option == 'next-server' %} + next-server {{ value }}; + {%- endif %} + {%- if option == 'filename' %} + filename "{{ value }}"; + {%- endif %} + {%- if option in dhcpd.customized_options.keys() %} + {%- if dhcpd.customized_options[option]['type'] in types_to_quote %} {% set quote = dquote %} {%- endif %} + option {{ option|replace('_', '-') }} {{ quote }}{{ value }}{{ quote }}; + {%- endif %} +{%- endmacro %} + {%- for class, config in dhcpd.classes.items() %} {%- if 'comment' in config %} {%- for line in config.comment.splitlines() %} @@ -180,11 +194,8 @@ class "{{ class }}" { {%- if 'match' in config %} match {{ config.match }}; {%- endif %} - {%- for option in dhcpd.customized_options.keys() %} - {%- if option in config %} - {%- if dhcpd.customized_options[option]['type'] in types_to_quote %} {% set quote = dquote %} {%- endif %} - option {{ option|replace('_', '-') }} {{ quote }}{{ config.get(option) }}{{ quote }}; - {%- endif %} + {%- for option in config %} + {{- print_option(option, config.get(option)) }} {%- endfor %} } {%- endfor %}