From c78e915f5a14cf3e159306d55902ff626ab9e6f8 Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Tue, 3 Aug 2021 21:00:05 +0000 Subject: [PATCH 1/9] Incorporate DHCP Relay Agent into dhcp-relay docker --- dockers/docker-dhcp-relay/dhcp-relay.programs.j2 | 2 +- dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 | 4 ++-- dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 | 2 +- rules/docker-dhcp-relay.mk | 2 +- .../sample_output/py2/docker-dhcp-relay.supervisord.conf | 9 ++++----- .../sample_output/py3/docker-dhcp-relay.supervisord.conf | 8 ++++---- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 index d6c0d805a4cc..24e6bff3a5ed 100644 --- a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 +++ b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 @@ -12,6 +12,6 @@ isc-dhcpv4-relay-{{ vlan_name }} {% 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 }} +dhcp6relay-{{ vlan_name }} {%- endif %} {% endfor %} diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 index 2d95b383c093..ca021c96e67e 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 @@ -7,9 +7,9 @@ {% endfor %} {% if relay_for_ipv6.flag %} {% set _dummy = relay_for_ipv6.update({'flag': False}) %} -[program:isc-dhcpv6-relay-{{ vlan_name }}] +[program:dhcp6relay-{{ 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 }} +command=/usr/sbin/dhcp6relay {#- 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 %} diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 index 8bb9e5ad8136..a620a9032f5d 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 @@ -70,7 +70,7 @@ 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 %} +{% if relay_for_ipv6.flag %}dhcp6relay-{{ vlan_name }}:running{% endif %} {% set _dummy = relay_for_ipv4.update({'flag': False}) %} diff --git a/rules/docker-dhcp-relay.mk b/rules/docker-dhcp-relay.mk index a8b33c5bc74c..c3232e6da27a 100644 --- a/rules/docker-dhcp-relay.mk +++ b/rules/docker-dhcp-relay.mk @@ -6,7 +6,7 @@ DOCKER_DHCP_RELAY_DBG = $(DOCKER_DHCP_RELAY_STEM)-$(DBG_IMAGE_MARK).gz $(DOCKER_DHCP_RELAY)_PATH = $(DOCKERS_PATH)/$(DOCKER_DHCP_RELAY_STEM) -$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(SONIC_DHCPMON) +$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(SONIC_DHCPMON) $(SONIC_DHCP6RELAY) $(LIBSWSSCOMMON) $(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS) $(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) 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 35dfe5ea4b5d..c1f2f23dc890 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,7 +40,7 @@ dependent_startup=true dependent_startup_wait_for=rsyslogd:running [group:isc-dhcp-relay] -programs=isc-dhcpv4-relay-Vlan1000,isc-dhcpv6-relay-Vlan1000 +programs=isc-dhcpv4-relay-Vlan1000, dhcp6relay-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 @@ -52,8 +52,8 @@ 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 +[program:dhcp6relay-Vlan1000] +command=/usr/sbin/dhcp6relay priority=3 autostart=false autorestart=false @@ -74,6 +74,5 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running isc-dhcpv6-relay-Vlan1000:running - +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay-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 bc24433a14cf..0634a580b8fa 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,7 +40,7 @@ dependent_startup=true dependent_startup_wait_for=rsyslogd:running [group:isc-dhcp-relay] -programs=isc-dhcpv4-relay-Vlan1000,isc-dhcpv6-relay-Vlan1000 +programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay-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 @@ -52,8 +52,8 @@ 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 +[program:dhcp6relay-Vlan1000] +command=/usr/sbin/dhcp6relay priority=3 autostart=false autorestart=false @@ -74,6 +74,6 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running isc-dhcpv6-relay-Vlan1000:running +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay-Vlan1000:running From 82aebe0e72ea8b4ed7456c7eb1070638da95a9dc Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Tue, 3 Aug 2021 21:40:05 +0000 Subject: [PATCH 2/9] Updated docker files --- rules/dhcp6relay.dep | 9 +++++++++ rules/dhcp6relay.mk | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rules/dhcp6relay.dep create mode 100644 rules/dhcp6relay.mk diff --git a/rules/dhcp6relay.dep b/rules/dhcp6relay.dep new file mode 100644 index 000000000000..be82d326fe21 --- /dev/null +++ b/rules/dhcp6relay.dep @@ -0,0 +1,9 @@ + +SPATH := $($(SONIC_DHCP6RELAY)_SRC_PATH) +DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/dhcp6relay.mk rules/dhcp6relay.dep +DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) +DEP_FILES += $(shell git ls-files $(SPATH)) + +$(SONIC_DHCP6RELAY)_CACHE_MODE := GIT_CONTENT_SHA +$(SONIC_DHCP6RELAY)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(SONIC_DHCP6RELAY)_DEP_FILES := $(DEP_FILES) diff --git a/rules/dhcp6relay.mk b/rules/dhcp6relay.mk new file mode 100644 index 000000000000..d9ff506d8a27 --- /dev/null +++ b/rules/dhcp6relay.mk @@ -0,0 +1,10 @@ +# SONiC DHCPV6 RELAY Package + +SONIC_DHCP6RELAY_VERSION = 1.0.0-0 +SONIC_DHCP6RELAY_PKG_NAME = dhcp6relay + +SONIC_DHCP6RELAY = sonic-$(SONIC_DHCP6RELAY_PKG_NAME)_$(SONIC_DHCP6RELAY_VERSION)_$(CONFIGURED_ARCH).deb +$(SONIC_DHCP6RELAY)_DEPENDS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV) +$(DOCKER_DHCP_RELAY)_INSTALL_DEBS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV) +$(SONIC_DHCP6RELAY)_SRC_PATH = $(SRC_PATH)/$(SONIC_DHCP6RELAY_PKG_NAME) +SONIC_DPKG_DEBS += $(SONIC_DHCP6RELAY) From d4296186425242087b7a12f9cfbe01ad724ed541 Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Tue, 31 Aug 2021 01:53:26 +0000 Subject: [PATCH 3/9] Updated dhcp-relay docker files --- dockers/docker-dhcp-relay/critical_processes | 2 +- dockers/docker-dhcp-relay/dhcp-relay.programs.j2 | 4 ++-- dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 | 16 +--------------- .../docker-dhcp-relay/dhcpv6-relay.monitors.j2 | 2 +- .../py2/docker-dhcp-relay.supervisord.conf | 9 +++++---- .../py3/docker-dhcp-relay.supervisord.conf | 10 +++++----- 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/dockers/docker-dhcp-relay/critical_processes b/dockers/docker-dhcp-relay/critical_processes index 855851bf2d68..43bf6af2794f 100644 --- a/dockers/docker-dhcp-relay/critical_processes +++ b/dockers/docker-dhcp-relay/critical_processes @@ -1 +1 @@ -group:isc-dhcp-relay +group:dhcp-relay diff --git a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 index 24e6bff3a5ed..9cb0c03876d6 100644 --- a/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 +++ b/dockers/docker-dhcp-relay/dhcp-relay.programs.j2 @@ -1,4 +1,4 @@ -[group:isc-dhcp-relay] +[group:dhcp-relay] programs= {%- set add_preceding_comma = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} @@ -12,6 +12,6 @@ isc-dhcpv4-relay-{{ vlan_name }} {% 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}) %} -dhcp6relay-{{ vlan_name }} +dhcp6relay {%- endif %} {% endfor %} diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 index ca021c96e67e..e41c75dba017 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 @@ -7,23 +7,9 @@ {% endfor %} {% if relay_for_ipv6.flag %} {% set _dummy = relay_for_ipv6.update({'flag': False}) %} -[program:dhcp6relay-{{ vlan_name }}] +[program:dhcp6relay] {# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #} command=/usr/sbin/dhcp6relay -{#- 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 diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 index a620a9032f5d..73ca9a77c88c 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 @@ -70,7 +70,7 @@ 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 %}dhcp6relay-{{ vlan_name }}:running{% endif %} +{%- if relay_for_ipv6.flag %}dhcp6relay:running{% endif %} {% set _dummy = relay_for_ipv4.update({'flag': False}) %} 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 c1f2f23dc890..aa5b8a218960 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 @@ -39,8 +39,8 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=rsyslogd:running -[group:isc-dhcp-relay] -programs=isc-dhcpv4-relay-Vlan1000, dhcp6relay-Vlan1000 +[group:dhcp-relay] +programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay [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 @@ -52,8 +52,9 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=start:exited -[program:dhcp6relay-Vlan1000] +[program:dhcp6relay] command=/usr/sbin/dhcp6relay + priority=3 autostart=false autorestart=false @@ -74,5 +75,5 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay-Vlan1000:running +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay: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 0634a580b8fa..c6cb495ae0c0 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 @@ -39,8 +39,8 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=rsyslogd:running -[group:isc-dhcp-relay] -programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay-Vlan1000 +[group:dhcp-relay] +programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay [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 @@ -52,8 +52,9 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=start:exited -[program:dhcp6relay-Vlan1000] +[program:dhcp6relay] command=/usr/sbin/dhcp6relay + priority=3 autostart=false autorestart=false @@ -74,6 +75,5 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay-Vlan1000:running - +dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay:running From 02260705119d04431ad4933a960db023d2ac087e Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Tue, 31 Aug 2021 06:35:05 +0000 Subject: [PATCH 4/9] Fixed sample output --- .../sample_output/py2/docker-dhcp-relay.supervisord.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 aa5b8a218960..c6cb495ae0c0 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 @@ -43,7 +43,7 @@ dependent_startup_wait_for=rsyslogd:running programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay [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 +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 autorestart=false @@ -68,7 +68,7 @@ dependent_startup_wait_for=start:exited programs=dhcpmon-Vlan1000 [program:dhcpmon-Vlan1000] -command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 -im eth0 -4 -6 +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 From e8ead2b5ca62130e8c6d38c34aad0291cbb541b1 Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Tue, 31 Aug 2021 08:22:15 +0000 Subject: [PATCH 5/9] Add endlines --- dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 | 1 - .../tests/sample_output/py2/docker-dhcp-relay.supervisord.conf | 1 + .../tests/sample_output/py3/docker-dhcp-relay.supervisord.conf | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 index e41c75dba017..218c95320edc 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2 @@ -8,7 +8,6 @@ {% if relay_for_ipv6.flag %} {% set _dummy = relay_for_ipv6.update({'flag': False}) %} [program:dhcp6relay] -{# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #} command=/usr/sbin/dhcp6relay priority=3 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 c6cb495ae0c0..521899b939f4 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 @@ -77,3 +77,4 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay: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 c6cb495ae0c0..521899b939f4 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 @@ -77,3 +77,4 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running dhcp6relay:running + From 6c6996aacf70d950eb270d990c58f1451688f3ab Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Wed, 1 Sep 2021 17:36:41 +0000 Subject: [PATCH 6/9] Updated output files --- dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 | 2 +- .../sample_output/py2/docker-dhcp-relay.supervisord.conf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 index 73ca9a77c88c..9f2d0f01b59f 100644 --- a/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 +++ b/dockers/docker-dhcp-relay/dhcpv6-relay.monitors.j2 @@ -70,7 +70,7 @@ 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 %}dhcp6relay:running{% endif %} +{% if relay_for_ipv6.flag %}dhcp6relay:running{% endif %} {% set _dummy = relay_for_ipv4.update({'flag': False}) %} 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 521899b939f4..a9004e2b00f5 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 @@ -43,7 +43,7 @@ dependent_startup_wait_for=rsyslogd:running programs=isc-dhcpv4-relay-Vlan1000,dhcp6relay [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 +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 autorestart=false @@ -68,7 +68,7 @@ dependent_startup_wait_for=start:exited programs=dhcpmon-Vlan1000 [program:dhcpmon-Vlan1000] -command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel01 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -im eth0 -4 -6 +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 From 95ab141dff4bf64f46096b3b9f6e538292a9d9f9 Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Wed, 15 Sep 2021 21:37:18 +0000 Subject: [PATCH 7/9] Update dhcp6relay --- src/dhcp6relay/src/relay.cpp | 14 ++++++-------- src/dhcp6relay/src/relay.h | 8 +++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/dhcp6relay/src/relay.cpp b/src/dhcp6relay/src/relay.cpp index d9c7114a7937..d305582343f1 100644 --- a/src/dhcp6relay/src/relay.cpp +++ b/src/dhcp6relay/src/relay.cpp @@ -325,12 +325,12 @@ int sock_open(int ifindex, const struct sock_fprog *fprog) * * @return none */ -void prepare_relay_config(relay_config *interface_config, int local_sock, int filter) { +void prepare_relay_config(relay_config *interface_config, int *local_sock, int filter) { struct ifaddrs *ifa, *ifa_tmp; sockaddr_in6 non_link_local; sockaddr_in6 link_local; - interface_config->local_sock = local_sock; + interface_config->local_sock = *local_sock; interface_config->filter = filter; for(auto server: interface_config->servers) { @@ -376,22 +376,20 @@ void prepare_relay_config(relay_config *interface_config, int local_sock, int fi } /** - * @code prepare_socket(int *local_sock, relay_config *config); + * @code prepare_socket(int *local_sock); * * @brief prepare L3 socket for sending * * @param local_sock pointer to socket to be prepared - * @param config relay config that contains strings of server and interface addresses * * @return none */ -void prepare_socket(int *local_sock, relay_config *config, int index) { +void prepare_socket(int *local_sock) { int flag = 1; sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr = in6addr_any; - addr.sin6_scope_id = index; addr.sin6_port = htons(RELAY_PORT); if ((*local_sock = socket(AF_INET6, SOCK_DGRAM, 0)) == -1) { @@ -679,11 +677,11 @@ void loop_relay(std::vector *vlans, swss::DBConnector *db) { filter = sock_open(index, ðer_relay_fprog); - prepare_socket(&local_sock, &config, index); + prepare_socket(&local_sock); sockets.push_back(filter); sockets.push_back(local_sock); - prepare_relay_config(&config, local_sock, filter); + prepare_relay_config(&config, &local_sock, filter); evutil_make_listen_socket_reuseable(filter); evutil_make_socket_nonblocking(filter); diff --git a/src/dhcp6relay/src/relay.h b/src/dhcp6relay/src/relay.h index eb97f06cd690..e974ecab4337 100644 --- a/src/dhcp6relay/src/relay.h +++ b/src/dhcp6relay/src/relay.h @@ -91,17 +91,15 @@ struct linklayer_addr_option { int sock_open(int ifindex, const struct sock_fprog *fprog); /** - * @code prepare_socket(int *local_sock, arg_config *config); + * @code prepare_socket(int *local_sock); * * @brief prepare L3 socket for sending * * @param local_sock pointer to socket to be prepared - * @param config argument config that contains strings of server and interface addresses - * @param index interface id * * @return none */ -void prepare_socket(int *local_sock, relay_config *config, int index); +void prepare_socket(int *local_sock); /** * @code prepare_relay_config(relay_config *interface_config, int local_sock, int filter); @@ -114,7 +112,7 @@ void prepare_socket(int *local_sock, relay_config *config, int index); * * @return none */ -void prepare_relay_config(relay_config *interface_config, int local_sock, int filter); +void prepare_relay_config(relay_config *interface_config, int *local_sock, int filter); /** * @code relay_forward(uint8_t *buffer, const struct dhcpv6_msg *msg, uint16_t msg_length); From 9bff5293fc2ef649e8d79e707bff68f92a4284f6 Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Thu, 16 Sep 2021 22:16:50 +0000 Subject: [PATCH 8/9] Make option 79 on by default, change the order of relay message and option in DHCPv6 message --- src/dhcp6relay/src/configInterface.cpp | 8 +++----- src/dhcp6relay/src/relay.cpp | 13 ++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/dhcp6relay/src/configInterface.cpp b/src/dhcp6relay/src/configInterface.cpp index db2c67656a76..95ba7029ce0e 100644 --- a/src/dhcp6relay/src/configInterface.cpp +++ b/src/dhcp6relay/src/configInterface.cpp @@ -117,6 +117,7 @@ void processRelayNotification(std::deque &entries, std::vector fieldValues = kfvFieldsValues(entry); relay_config intf; + intf.is_option_79 = true; intf.interface = vlan; for (auto &fieldValue: fieldValues) { std::string f = fvField(fieldValue); @@ -130,11 +131,8 @@ void processRelayNotification(std::deque &entries, } syslog(LOG_DEBUG, "key: %s, Operation: %s, f: %s, v: %s", vlan.c_str(), operation.c_str(), f.c_str(), v.c_str()); } - if(f == "dhcpv6_option|rfc6939_support") { - if(v == "true") - intf.is_option_79 = true; - else if(v == "false") - intf.is_option_79 = false; + if(f == "dhcpv6_option|rfc6939_support" && v == "false") { + intf.is_option_79 = false; } } vlans->push_back(intf); diff --git a/src/dhcp6relay/src/relay.cpp b/src/dhcp6relay/src/relay.cpp index d305582343f1..f17e00da6156 100644 --- a/src/dhcp6relay/src/relay.cpp +++ b/src/dhcp6relay/src/relay.cpp @@ -432,11 +432,6 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h memcpy(current_buffer_position, &new_message, sizeof(dhcpv6_relay_msg)); current_buffer_position += sizeof(dhcpv6_relay_msg); - - auto dhcp_message_length = len; - relay_forward(current_buffer_position, parse_dhcpv6_hdr(msg), dhcp_message_length); - current_buffer_position += dhcp_message_length + sizeof(dhcpv6_option); - if(config->is_option_79) { linklayer_addr_option option79; option79.link_layer_type = htons(1); @@ -445,10 +440,14 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h memcpy(current_buffer_position, &option79, sizeof(linklayer_addr_option)); current_buffer_position += sizeof(linklayer_addr_option); + + memcpy(current_buffer_position, ðer_hdr->ether_shost, sizeof(ether_hdr->ether_shost)); + current_buffer_position += sizeof(ether_hdr->ether_shost); } - memcpy(current_buffer_position, ðer_hdr->ether_shost, sizeof(ether_hdr->ether_shost)); - current_buffer_position += sizeof(ether_hdr->ether_shost); + auto dhcp_message_length = len; + relay_forward(current_buffer_position, parse_dhcpv6_hdr(msg), dhcp_message_length); + current_buffer_position += dhcp_message_length + sizeof(dhcpv6_option); for(auto server: config->servers_sock) { send_udp(sock, buffer, server, current_buffer_position - buffer); From 9da09421cd1e25d102afd82043675a6b984b64ec Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Wed, 22 Sep 2021 10:02:48 +0000 Subject: [PATCH 9/9] Updated code comments and counter --- src/dhcp6relay/src/configInterface.cpp | 8 ++++---- src/dhcp6relay/src/configInterface.h | 8 ++++---- src/dhcp6relay/src/main.cpp | 2 +- src/dhcp6relay/src/relay.cpp | 24 ++++++++++++++++++------ src/dhcp6relay/src/relay.h | 1 - 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/dhcp6relay/src/configInterface.cpp b/src/dhcp6relay/src/configInterface.cpp index 95ba7029ce0e..0af4f49a285f 100644 --- a/src/dhcp6relay/src/configInterface.cpp +++ b/src/dhcp6relay/src/configInterface.cpp @@ -13,13 +13,13 @@ swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP_RELAY"); swss::Select swssSelect; /** - * @code void deinitialize_swss() + * @code void initialize_swss() * * @brief initialize DB tables and start SWSS listening thread * * @return none */ -void initialize_swss(std::vector *vlans, swss::DBConnector *db) +void initialize_swss(std::vector *vlans) { try { swssSelect.addSelectable(&ipHelpersTable); @@ -85,7 +85,7 @@ void handleSwssNotification(std::vector *vlans) * @brief handles DHCPv6 relay configuration change notification * * @param ipHelpersTable DHCP table - * @param context list of vlans/argument config that contains strings of server and option + * @param vlans list of vlans/argument config that contains strings of server and option * * @return none */ @@ -103,7 +103,7 @@ void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::ve * @brief process DHCPv6 relay servers and options configuration change notification * * @param entries queue of std::tuple> entries in DHCP table - * @param context list of vlans/argument config that contains strings of server and option + * @param vlans list of vlans/argument config that contains strings of server and option * * @return none */ diff --git a/src/dhcp6relay/src/configInterface.h b/src/dhcp6relay/src/configInterface.h index dfd5eb668e0e..20b0912c5cef 100644 --- a/src/dhcp6relay/src/configInterface.h +++ b/src/dhcp6relay/src/configInterface.h @@ -4,13 +4,13 @@ #include "relay.h" /** - * @code void deinitialize_swss() + * @code void initialize_swss() * * @brief initialize DB tables and start SWSS listening thread * * @return none */ -void initialize_swss(std::vector *vlans, swss::DBConnector *db); +void initialize_swss(std::vector *vlans); /** * @code void deinitialize_swss() @@ -35,7 +35,7 @@ void get_dhcp(std::vector *vlans); * * @brief main thread for handling SWSS notification * - * @param context list of vlans/argument config that contains strings of server and option + * @param vlans list of vlans/argument config that contains strings of server and option * * @return none */ @@ -47,7 +47,7 @@ void handleSwssNotification(std::vector *vlans); * @brief handles DHCPv6 relay configuration change notification * * @param ipHelpersTable DHCP table - * @param context list of vlans/argument config that contains strings of server and option + * @param vlans list of vlans/argument config that contains strings of server and option * * @return none */ diff --git a/src/dhcp6relay/src/main.cpp b/src/dhcp6relay/src/main.cpp index 860e4d1346d8..9f5bc74bcfa0 100644 --- a/src/dhcp6relay/src/main.cpp +++ b/src/dhcp6relay/src/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) { try { std::vector vlans; swss::DBConnector state_db("STATE_DB", 0); - initialize_swss(&vlans, &state_db); + initialize_swss(&vlans); loop_relay(&vlans, &state_db); } catch (std::exception &e) diff --git a/src/dhcp6relay/src/relay.cpp b/src/dhcp6relay/src/relay.cpp index f17e00da6156..e2eb8e4fac12 100644 --- a/src/dhcp6relay/src/relay.cpp +++ b/src/dhcp6relay/src/relay.cpp @@ -18,6 +18,7 @@ struct event *server_listen_event; struct event_base *base; struct event *ev_sigint; struct event *ev_sigterm; +static std::string counter_table = "DHCPv6_COUNTER_TABLE|"; /* DHCPv6 filter */ /* sudo tcpdump -dd "ip6 dst ff02::1:2 && udp dst port 547" */ @@ -543,11 +544,23 @@ void callback(evutil_socket_t fd, short event, void *arg) { auto msg = parse_dhcpv6_hdr(current_position); counters[msg->msg_type]++; - update_counter(config->db, config->counterVlan, msg->msg_type); + std::string counterVlan = counter_table; + update_counter(config->db, counterVlan.append(config->interface), msg->msg_type); relay_client(config->local_sock, current_position, ntohs(udp_header->len) - sizeof(udphdr), ip_header, ether_header, config); } +/** + * @code void server_callback(evutil_socket_t fd, short event, void *arg); + * + * @brief callback for libevent that is called everytime data is received at the server socket + * + * @param fd filter socket + * @param event libevent triggered event + * @param arg callback argument provided by user + * + * @return none + */ void server_callback(evutil_socket_t fd, short event, void *arg) { struct relay_config *config = (struct relay_config *)arg; sockaddr_in6 from; @@ -560,9 +573,9 @@ void server_callback(evutil_socket_t fd, short event, void *arg) { } auto msg = parse_dhcpv6_hdr(message_buffer); - counters[msg->msg_type]++; - update_counter(config->db, config->counterVlan, msg->msg_type); + std::string counterVlan = counter_table; + update_counter(config->db, counterVlan.append(config->interface), msg->msg_type); if (msg->msg_type == DHCPv6_MESSAGE_TYPE_RELAY_REPL) { relay_relay_reply(config->local_sock, message_buffer, data, config); } @@ -670,9 +683,8 @@ void loop_relay(std::vector *vlans, swss::DBConnector *db) { int index = if_nametoindex(ifname); config.db = db; - config.counterVlan = "DHCPv6_COUNTER_TABLE|"; - config.counterVlan.append(ifname); - initialize_counter(config.db, config.counterVlan); + std::string counterVlan = counter_table; + initialize_counter(config.db, counterVlan.append(config.interface)); filter = sock_open(index, ðer_relay_fprog); diff --git a/src/dhcp6relay/src/relay.h b/src/dhcp6relay/src/relay.h index e974ecab4337..ddd63559c66b 100644 --- a/src/dhcp6relay/src/relay.h +++ b/src/dhcp6relay/src/relay.h @@ -49,7 +49,6 @@ struct relay_config { std::vector servers; std::vector servers_sock; bool is_option_79; - std::string counterVlan; };