From 433210f25291b10ba02260e68c5e0bfe32db0acd Mon Sep 17 00:00:00 2001 From: Shlomi Bitton Date: Sun, 4 Jul 2021 16:26:01 +0000 Subject: [PATCH 1/3] Add DHCP relay support for IPv6 Edit supervisord template to start DHCPv6 instance Align cfg unit test to new change Signed-off-by: Shlomi Bitton --- .../docker-dhcp-relay.supervisord.conf.j2 | 93 +++++++++++++++++-- .../py2/docker-dhcp-relay.supervisord.conf | 19 +++- .../py3/docker-dhcp-relay.supervisord.conf | 19 +++- 3 files changed, 111 insertions(+), 20 deletions(-) diff --git a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 index a1811226a885..ed9a2183c562 100644 --- a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 +++ b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 @@ -42,29 +42,42 @@ dependent_startup_wait_for=rsyslogd:running {# If our configuration has VLANs... #} {% if VLAN_INTERFACE %} {# Count how many VLANs require a DHCP relay agent... #} -{% set num_relays = { 'count': 0 } %} +{% set ipv4_num_relays = { 'count': 0 } %} +{% set ipv6_num_relays = { 'count': 0 } %} {% for vlan_name in VLAN_INTERFACE %} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} -{% set _dummy = num_relays.update({'count': num_relays.count + 1}) %} +{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %} +{% endif %} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% set _dummy = ipv6_num_relays.update({'count': ipv6_num_relays.count + 1}) %} {% endif %} {% endfor %} {# If one or more of the VLANs require a DHCP relay agent... #} -{% if num_relays.count > 0 %} +{% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %} [group:isc-dhcp-relay] programs= {%- set add_preceding_comma = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} +{# Append DHCPv4 agents #} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} {% if add_preceding_comma.flag %},{% endif %} {% set _dummy = add_preceding_comma.update({'flag': True}) %} -isc-dhcp-relay-{{ vlan_name }} +isc-dhcpv4-relay-{{ vlan_name }} +{%- endif %} +{# Append DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% if add_preceding_comma.flag %},{% endif %} +{% set _dummy = add_preceding_comma.update({'flag': True}) %} +isc-dhcpv6-relay-{{ vlan_name }} {%- endif %} {% endfor %} {# Create a program entry for each DHCP relay agent instance #} {% set relay_for_ipv4 = { 'flag': False } %} +{% set relay_for_ipv6 = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} +{# Append DHCPv4 agents #} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} {% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {% if dhcp_server | ipv4 %} @@ -73,7 +86,7 @@ isc-dhcp-relay-{{ vlan_name }} {% endfor %} {% if relay_for_ipv4.flag %} {% set _dummy = relay_for_ipv4.update({'flag': False}) %} -[program:isc-dhcp-relay-{{ vlan_name }}] +[program:isc-dhcpv4-relay-{{ vlan_name }}] {# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }} {#- Dual ToR Option #} @@ -102,6 +115,43 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=start:exited +{% endif %} +{% endif %} +{# Append DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{% if dhcpv6_server | ipv6 %} +{% set _dummy = relay_for_ipv6.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% if relay_for_ipv6.flag %} +{% set _dummy = relay_for_ipv6.update({'flag': False}) %} +[program:isc-dhcpv6-relay-{{ vlan_name }}] +{# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #} +command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l {{ vlan_name }} +{#- We treat all other interfaces as upstream interfaces (-u), as we only want to listen for replies #} +{%- for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{%- if dhcpv6_server | ipv6 %} +{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %} +{%- if prefix | ipv6 and name != vlan_name %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% for (name, prefix) in INTERFACE|pfx_filter %} +{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} +{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% endif -%} +{% endfor %} + +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + {% endif %} {% endif %} {% endfor %} @@ -109,26 +159,44 @@ dependent_startup_wait_for=start:exited [group:dhcpmon] programs= {%- set add_preceding_comma = { 'flag': False } %} +{% set monitor_instance = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} +{% set _dummy = monitor_instance.update({'flag': True}) %} +{%- endif %} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% set _dummy = monitor_instance.update({'flag': True}) %} +{%- endif %} +{% if monitor_instance.flag %} {% if add_preceding_comma.flag %},{% endif %} {% set _dummy = add_preceding_comma.update({'flag': True}) %} dhcpmon-{{ vlan_name }} +{%- set _dummy = monitor_instance.update({'flag': False}) %} {%- endif %} {% endfor %} {# Create a program entry for each DHCP MONitor instance #} {% set relay_for_ipv4 = { 'flag': False } %} +{% set relay_for_ipv6 = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} +{# Check DHCPv4 agents #} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} {% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {% if dhcp_server | ipv4 %} {% set _dummy = relay_for_ipv4.update({'flag': True}) %} {% endif %} {% endfor %} -{% if relay_for_ipv4.flag %} -{% set _dummy = relay_for_ipv4.update({'flag': False}) %} +{% endif %} +{# Check DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{% if dhcpv6_server | ipv6 %} +{% set _dummy = relay_for_ipv6.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% endif %} +{% if relay_for_ipv4.flag or relay_for_ipv6.flag %} [program:dhcpmon-{{ vlan_name }}] {# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} command=/usr/sbin/dhcpmon -id {{ vlan_name }} @@ -149,6 +217,8 @@ command=/usr/sbin/dhcpmon -id {{ vlan_name }} {% if prefix | ipv4 %} -im {{ name }}{% endif -%} {% endfor %} {% endif %} +{% if relay_for_ipv4.flag %} -4{% endif %} +{% if relay_for_ipv6.flag %} -6{% endif %} priority=4 autostart=false @@ -156,11 +226,14 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcp-relay-{{ vlan_name }}:running +dependent_startup_wait_for= +{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %} +{% if relay_for_ipv6.flag %}isc-dhcpv6-relay-{{ vlan_name }}:running{% endif %} -{% endif %} + +{% set _dummy = relay_for_ipv4.update({'flag': False}) %} +{% set _dummy = relay_for_ipv6.update({'flag': False}) %} {% endif %} {% endfor %} - {% endif %} {% endif %} diff --git a/src/sonic-config-engine/tests/sample_output/py2/docker-dhcp-relay.supervisord.conf b/src/sonic-config-engine/tests/sample_output/py2/docker-dhcp-relay.supervisord.conf index 3a1269c43533..35dfe5ea4b5d 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/docker-dhcp-relay.supervisord.conf +++ b/src/sonic-config-engine/tests/sample_output/py2/docker-dhcp-relay.supervisord.conf @@ -40,9 +40,9 @@ dependent_startup=true dependent_startup_wait_for=rsyslogd:running [group:isc-dhcp-relay] -programs=isc-dhcp-relay-Vlan1000 +programs=isc-dhcpv4-relay-Vlan1000,isc-dhcpv6-relay-Vlan1000 -[program:isc-dhcp-relay-Vlan1000] +[program:isc-dhcpv4-relay-Vlan1000] command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 192.0.0.1 192.0.0.2 priority=3 autostart=false @@ -52,19 +52,28 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=start:exited +[program:isc-dhcpv6-relay-Vlan1000] +command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l Vlan1000 -u fc02:2000::1%%PortChannel04 -u fc02:2000::1%%PortChannel03 -u fc02:2000::1%%PortChannel01 -u fc02:2000::1%%PortChannel02 -u fc02:2000::2%%PortChannel04 -u fc02:2000::2%%PortChannel03 -u fc02:2000::2%%PortChannel01 -u fc02:2000::2%%PortChannel02 +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + [group:dhcpmon] programs=dhcpmon-Vlan1000 [program:dhcpmon-Vlan1000] -command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 -im eth0 +command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 -im eth0 -4 -6 priority=4 autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcp-relay-Vlan1000:running - +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running isc-dhcpv6-relay-Vlan1000:running diff --git a/src/sonic-config-engine/tests/sample_output/py3/docker-dhcp-relay.supervisord.conf b/src/sonic-config-engine/tests/sample_output/py3/docker-dhcp-relay.supervisord.conf index e5e5462bde77..bc24433a14cf 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/docker-dhcp-relay.supervisord.conf +++ b/src/sonic-config-engine/tests/sample_output/py3/docker-dhcp-relay.supervisord.conf @@ -40,9 +40,9 @@ dependent_startup=true dependent_startup_wait_for=rsyslogd:running [group:isc-dhcp-relay] -programs=isc-dhcp-relay-Vlan1000 +programs=isc-dhcpv4-relay-Vlan1000,isc-dhcpv6-relay-Vlan1000 -[program:isc-dhcp-relay-Vlan1000] +[program:isc-dhcpv4-relay-Vlan1000] command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id Vlan1000 -iu Vlan2000 -iu PortChannel01 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 192.0.0.1 192.0.0.2 priority=3 autostart=false @@ -52,19 +52,28 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=start:exited +[program:isc-dhcpv6-relay-Vlan1000] +command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l Vlan1000 -u fc02:2000::1%%PortChannel01 -u fc02:2000::1%%PortChannel02 -u fc02:2000::1%%PortChannel03 -u fc02:2000::1%%PortChannel04 -u fc02:2000::2%%PortChannel01 -u fc02:2000::2%%PortChannel02 -u fc02:2000::2%%PortChannel03 -u fc02:2000::2%%PortChannel04 +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + [group:dhcpmon] programs=dhcpmon-Vlan1000 [program:dhcpmon-Vlan1000] -command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel01 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -im eth0 +command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel01 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -im eth0 -4 -6 priority=4 autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcp-relay-Vlan1000:running - +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running isc-dhcpv6-relay-Vlan1000:running From 4682999e06f6a2cf2884350b64df7077b4c92f80 Mon Sep 17 00:00:00 2001 From: Shlomi Bitton Date: Mon, 12 Jul 2021 19:15:50 +0000 Subject: [PATCH 2/3] Split docker-dhcp-relay.supervisord.conf.j2 template into several files for easier code maintenance --- dockers/docker-dhcp-relay/Dockerfile.j2 | 1 + .../docker-dhcp-relay/dhcp-relay.programs.j2 | 17 ++ .../docker-dhcp-relay/dhcpv4-relay.agents.j2 | 40 ++++ .../docker-dhcp-relay/dhcpv6-relay.agents.j2 | 37 ++++ .../dhcpv6-relay.monitors.j2 | 79 ++++++++ .../docker-dhcp-relay.supervisord.conf.j2 | 177 +----------------- 6 files changed, 178 insertions(+), 173 deletions(-) create mode 100644 dockers/docker-dhcp-relay/dhcp-relay.programs.j2 create mode 100644 dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 create mode 100644 dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 create mode 100644 dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 diff --git a/dockers/docker-dhcp-relay/Dockerfile.j2 b/dockers/docker-dhcp-relay/Dockerfile.j2 index 1100aa510742..5f6572d9d550 100644 --- a/dockers/docker-dhcp-relay/Dockerfile.j2 +++ b/dockers/docker-dhcp-relay/Dockerfile.j2 @@ -30,6 +30,7 @@ RUN apt-get clean -y && \ COPY ["docker_init.sh", "start.sh", "/usr/bin/"] COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"] +COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcpv6-relay.monitors.j2", "/usr/share/sonic/templates/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor"] diff --git a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 new file mode 100644 index 000000000000..a96e13e346ab --- /dev/null +++ b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 @@ -0,0 +1,17 @@ +[group:isc-dhcp-relay] +programs= +{%- set add_preceding_comma = { 'flag': False } %} +{% for vlan_name in VLAN_INTERFACE %} +{# Append DHCPv4 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} +{% if add_preceding_comma.flag %},{% endif %} +{% set _dummy = add_preceding_comma.update({'flag': True}) %} +isc-dhcpv4-relay-{{ vlan_name }} +{%- endif %} +{# Append DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% if add_preceding_comma.flag %},{% endif %} +{% set _dummy = add_preceding_comma.update({'flag': True}) %} +isc-dhcpv6-relay-{{ vlan_name }} +{%- endif %} +{% endfor %} \ No newline at end of file diff --git a/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 new file mode 100644 index 000000000000..bcad7af15d6e --- /dev/null +++ b/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 @@ -0,0 +1,40 @@ +{# Append DHCPv4 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} +{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} +{% if dhcp_server | ipv4 %} +{% set _dummy = relay_for_ipv4.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% if relay_for_ipv4.flag %} +{% set _dummy = relay_for_ipv4.update({'flag': False}) %} +[program:isc-dhcpv4-relay-{{ vlan_name }}] +{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} +command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }} +{#- Dual ToR Option #} +{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -U Loopback0 -dt{% endif -%} +{#- si option to use intf addr in relay #} +{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%} +{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} +{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%} +{% endfor %} +{% for (name, prefix) in INTERFACE|pfx_filter %} +{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} +{% endfor %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} +{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} +{% endfor %} +{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} +{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%} +{% endfor %} + +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + +{% endif %} +{% endif %} \ No newline at end of file diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 new file mode 100644 index 000000000000..ee9aca75ae98 --- /dev/null +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 @@ -0,0 +1,37 @@ +{# Append DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{% if dhcpv6_server | ipv6 %} +{% set _dummy = relay_for_ipv6.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% if relay_for_ipv6.flag %} +{% set _dummy = relay_for_ipv6.update({'flag': False}) %} +[program:isc-dhcpv6-relay-{{ vlan_name }}] +{# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #} +command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l {{ vlan_name }} +{#- We treat all other interfaces as upstream interfaces (-u), as we only want to listen for replies #} +{%- for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{%- if dhcpv6_server | ipv6 %} +{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %} +{%- if prefix | ipv6 and name != vlan_name %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% for (name, prefix) in INTERFACE|pfx_filter %} +{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} +{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} +{% endfor %} +{% endif -%} +{% endfor %} + +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + +{% endif %} +{% endif %} \ No newline at end of file diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 new file mode 100644 index 000000000000..b3517ebef5f8 --- /dev/null +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 @@ -0,0 +1,79 @@ +[group:dhcpmon] +programs= +{%- set add_preceding_comma = { 'flag': False } %} +{% set monitor_instance = { 'flag': False } %} +{% for vlan_name in VLAN_INTERFACE %} +{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} +{% set _dummy = monitor_instance.update({'flag': True}) %} +{%- endif %} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% set _dummy = monitor_instance.update({'flag': True}) %} +{%- endif %} +{% if monitor_instance.flag %} +{% if add_preceding_comma.flag %},{% endif %} +{% set _dummy = add_preceding_comma.update({'flag': True}) %} +dhcpmon-{{ vlan_name }} +{%- set _dummy = monitor_instance.update({'flag': False}) %} +{%- endif %} +{% endfor %} + + +{# Create a program entry for each DHCP MONitor instance #} +{% set relay_for_ipv4 = { 'flag': False } %} +{% set relay_for_ipv6 = { 'flag': False } %} +{% for vlan_name in VLAN_INTERFACE %} +{# Check DHCPv4 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} +{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} +{% if dhcp_server | ipv4 %} +{% set _dummy = relay_for_ipv4.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% endif %} +{# Check DHCPv6 agents #} +{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} +{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} +{% if dhcpv6_server | ipv6 %} +{% set _dummy = relay_for_ipv6.update({'flag': True}) %} +{% endif %} +{% endfor %} +{% endif %} +{% if relay_for_ipv4.flag or relay_for_ipv6.flag %} +[program:dhcpmon-{{ vlan_name }}] +{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} +command=/usr/sbin/dhcpmon -id {{ vlan_name }} +{#- Dual ToR Option #} +{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif -%} +{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} +{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%} +{% endfor %} +{% for (name, prefix) in INTERFACE|pfx_filter %} +{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} +{% endfor %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} +{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} +{% endfor %} +{% if MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} +{% if prefix | ipv4 %} -im {{ name }}{% endif -%} +{% endfor %} +{% endif %} +{% if relay_for_ipv4.flag %} -4{% endif %} +{% if relay_for_ipv6.flag %} -6{% endif %} + +priority=4 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for= +{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %} +{% if relay_for_ipv6.flag %}isc-dhcpv6-relay-{{ vlan_name }}:running{% endif %} + + +{% set _dummy = relay_for_ipv4.update({'flag': False}) %} +{% set _dummy = relay_for_ipv6.update({'flag': False}) %} +{% endif %} +{% endfor %} \ No newline at end of file diff --git a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 index ed9a2183c562..664e1f36c05e 100644 --- a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 +++ b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 @@ -54,186 +54,17 @@ dependent_startup_wait_for=rsyslogd:running {% endfor %} {# If one or more of the VLANs require a DHCP relay agent... #} {% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %} -[group:isc-dhcp-relay] -programs= -{%- set add_preceding_comma = { 'flag': False } %} -{% for vlan_name in VLAN_INTERFACE %} -{# Append DHCPv4 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} -{% if add_preceding_comma.flag %},{% endif %} -{% set _dummy = add_preceding_comma.update({'flag': True}) %} -isc-dhcpv4-relay-{{ vlan_name }} -{%- endif %} -{# Append DHCPv6 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} -{% if add_preceding_comma.flag %},{% endif %} -{% set _dummy = add_preceding_comma.update({'flag': True}) %} -isc-dhcpv6-relay-{{ vlan_name }} -{%- endif %} -{% endfor %} +{% include 'dhcp-relay.programs.j2' %} {# Create a program entry for each DHCP relay agent instance #} {% set relay_for_ipv4 = { 'flag': False } %} {% set relay_for_ipv6 = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} -{# Append DHCPv4 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} -{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} -{% if dhcp_server | ipv4 %} -{% set _dummy = relay_for_ipv4.update({'flag': True}) %} -{% endif %} -{% endfor %} -{% if relay_for_ipv4.flag %} -{% set _dummy = relay_for_ipv4.update({'flag': False}) %} -[program:isc-dhcpv4-relay-{{ vlan_name }}] -{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} -command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }} -{#- Dual ToR Option #} -{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -U Loopback0 -dt{% endif -%} -{#- si option to use intf addr in relay #} -{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%} -{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #} -{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%} -{% endfor %} -{% for (name, prefix) in INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} -{% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} -{% endfor %} -{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} -{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%} -{% endfor %} - -priority=3 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=start:exited - -{% endif %} -{% endif %} -{# Append DHCPv6 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} -{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} -{% if dhcpv6_server | ipv6 %} -{% set _dummy = relay_for_ipv6.update({'flag': True}) %} -{% endif %} -{% endfor %} -{% if relay_for_ipv6.flag %} -{% set _dummy = relay_for_ipv6.update({'flag': False}) %} -[program:isc-dhcpv6-relay-{{ vlan_name }}] -{# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #} -command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l {{ vlan_name }} -{#- We treat all other interfaces as upstream interfaces (-u), as we only want to listen for replies #} -{%- for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} -{%- if dhcpv6_server | ipv6 %} -{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{%- if prefix | ipv6 and name != vlan_name %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} -{% endfor %} -{% for (name, prefix) in INTERFACE|pfx_filter %} -{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} -{% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} -{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} -{% endfor %} -{% endif -%} -{% endfor %} - -priority=3 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=start:exited - -{% endif %} -{% endif %} -{% endfor %} - -[group:dhcpmon] -programs= -{%- set add_preceding_comma = { 'flag': False } %} -{% set monitor_instance = { 'flag': False } %} -{% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} -{% set _dummy = monitor_instance.update({'flag': True}) %} -{%- endif %} -{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} -{% set _dummy = monitor_instance.update({'flag': True}) %} -{%- endif %} -{% if monitor_instance.flag %} -{% if add_preceding_comma.flag %},{% endif %} -{% set _dummy = add_preceding_comma.update({'flag': True}) %} -dhcpmon-{{ vlan_name }} -{%- set _dummy = monitor_instance.update({'flag': False}) %} -{%- endif %} -{% endfor %} - - -{# Create a program entry for each DHCP MONitor instance #} -{% set relay_for_ipv4 = { 'flag': False } %} -{% set relay_for_ipv6 = { 'flag': False } %} -{% for vlan_name in VLAN_INTERFACE %} -{# Check DHCPv4 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %} -{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} -{% if dhcp_server | ipv4 %} -{% set _dummy = relay_for_ipv4.update({'flag': True}) %} -{% endif %} -{% endfor %} -{% endif %} -{# Check DHCPv6 agents #} -{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} -{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} -{% if dhcpv6_server | ipv6 %} -{% set _dummy = relay_for_ipv6.update({'flag': True}) %} -{% endif %} -{% endfor %} -{% endif %} -{% if relay_for_ipv4.flag or relay_for_ipv6.flag %} -[program:dhcpmon-{{ vlan_name }}] -{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} -command=/usr/sbin/dhcpmon -id {{ vlan_name }} -{#- Dual ToR Option #} -{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif -%} -{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #} -{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%} -{% endfor %} -{% for (name, prefix) in INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} +{% include 'dhcpv4-relay.agents.j2' %} +{% include 'dhcpv6-relay.agents.j2' %} {% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} -iu {{ name }}{% endif -%} -{% endfor %} -{% if MGMT_INTERFACE %} -{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} -im {{ name }}{% endif -%} -{% endfor %} -{% endif %} -{% if relay_for_ipv4.flag %} -4{% endif %} -{% if relay_for_ipv6.flag %} -6{% endif %} -priority=4 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for= -{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %} -{% if relay_for_ipv6.flag %}isc-dhcpv6-relay-{{ vlan_name }}:running{% endif %} - - -{% set _dummy = relay_for_ipv4.update({'flag': False}) %} -{% set _dummy = relay_for_ipv6.update({'flag': False}) %} -{% endif %} -{% endfor %} +{% include 'dhcpv6-relay.monitors.j2' %} {% endif %} {% endif %} From 4a744dfa6085a1c83e0258bc82f680b9dd052248 Mon Sep 17 00:00:00 2001 From: Shlomi Bitton Date: Wed, 14 Jul 2021 06:53:30 +0000 Subject: [PATCH 3/3] Add EOL for needed files --- dockers/docker-dhcp-relay/dhcp-relay.programs.j2 | 2 +- dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 | 2 +- dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 | 2 +- dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 index a96e13e346ab..d6c0d805a4cc 100644 --- a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 +++ b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 @@ -14,4 +14,4 @@ isc-dhcpv4-relay-{{ vlan_name }} {% set _dummy = add_preceding_comma.update({'flag': True}) %} isc-dhcpv6-relay-{{ vlan_name }} {%- endif %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 index bcad7af15d6e..bf756ff63817 100644 --- a/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 +++ b/dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2 @@ -37,4 +37,4 @@ dependent_startup=true dependent_startup_wait_for=start:exited {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 index ee9aca75ae98..2d95b383c093 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 @@ -34,4 +34,4 @@ dependent_startup=true dependent_startup_wait_for=start:exited {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 index b3517ebef5f8..8bb9e5ad8136 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 @@ -76,4 +76,4 @@ dependent_startup_wait_for= {% set _dummy = relay_for_ipv4.update({'flag': False}) %} {% set _dummy = relay_for_ipv6.update({'flag': False}) %} {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %}