From 7c5f0ff316838fa9b15d7ca3f732e5abebd17bbf Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Mon, 15 Mar 2021 14:43:50 -0700 Subject: [PATCH] Start DHCP Relay When Helpers IPs Are Available (#6961) (#7059) It is possible to have DHCP relay configuration with no servers/ helpers which result in DHCP container to crash. This PR fixes this issue by not starting DHCP relay for vlans with no DHCP helpers. resolves: #6931 closes: #6931 Do not add program group for dhcp relay with not dhcp helpers Unit test --- .../docker-dhcp-relay.supervisord.conf.j2 | 10 +++++----- .../tests/sample_output/bgpd_frr.conf | 5 ++++- .../tests/sample_output/bgpd_quagga.conf | 1 + .../docker-dhcp-relay.supervisord.conf | 4 ++-- .../tests/sample_output/frr.conf | 5 ++++- .../tests/sample_output/ipinip.json | 2 +- .../tests/sample_output/wait_for_intf.sh | 1 + .../tests/t0-sample-graph.xml | 19 +++++++++++++++++++ 8 files changed, 37 insertions(+), 10 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 d3fc6ec4a7..93966d1ece 100644 --- a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 +++ b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 @@ -43,7 +43,7 @@ dependent_startup_wait_for=rsyslogd:running {# Count how many VLANs require a DHCP relay agent... #} {% set num_relays = { 'count': 0 } %} {% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %} +{% 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}) %} {% endif %} {% endfor %} @@ -53,7 +53,7 @@ dependent_startup_wait_for=rsyslogd:running programs= {%- set add_preceding_comma = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %} +{% 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 }} @@ -64,7 +64,7 @@ isc-dhcp-relay-{{ vlan_name }} {# Create a program entry for each DHCP relay agent instance #} {% set relay_for_ipv4 = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %} +{% 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}) %} @@ -107,7 +107,7 @@ dependent_startup_wait_for=start:exited programs= {%- set add_preceding_comma = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %} +{% 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}) %} dhcpmon-{{ vlan_name }} @@ -118,7 +118,7 @@ dhcpmon-{{ vlan_name }} {# Create a program entry for each DHCP MONitor instance #} {% set relay_for_ipv4 = { 'flag': False } %} {% for vlan_name in VLAN_INTERFACE %} -{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %} +{% 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}) %} diff --git a/src/sonic-config-engine/tests/sample_output/bgpd_frr.conf b/src/sonic-config-engine/tests/sample_output/bgpd_frr.conf index 60fd3ded84..797c95e963 100644 --- a/src/sonic-config-engine/tests/sample_output/bgpd_frr.conf +++ b/src/sonic-config-engine/tests/sample_output/bgpd_frr.conf @@ -33,7 +33,9 @@ ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.1/27 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.200.1/27 +! +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.0.1/27 ! ! ! @@ -56,6 +58,7 @@ router bgp 65100 network fc00:1::32/64 exit-address-family ! + network 192.168.200.1/27 network 192.168.0.1/27 ! ! diff --git a/src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf b/src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf index f75d9de9a3..f5a4b22f0e 100644 --- a/src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf +++ b/src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf @@ -27,6 +27,7 @@ router bgp 65100 network fc00:1::32/64 exit-address-family network 10.1.0.32/32 + network 192.168.200.1/27 network 192.168.0.1/27 neighbor 10.0.0.59 remote-as 64600 neighbor 10.0.0.59 description ARISTA02T1 diff --git a/src/sonic-config-engine/tests/sample_output/docker-dhcp-relay.supervisord.conf b/src/sonic-config-engine/tests/sample_output/docker-dhcp-relay.supervisord.conf index be52694b78..2602cfca64 100644 --- a/src/sonic-config-engine/tests/sample_output/docker-dhcp-relay.supervisord.conf +++ b/src/sonic-config-engine/tests/sample_output/docker-dhcp-relay.supervisord.conf @@ -42,7 +42,7 @@ dependent_startup_wait_for=rsyslogd:running programs=isc-dhcp-relay-Vlan1000 [program:isc-dhcp-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 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 PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 192.0.0.1 192.0.0.2 priority=3 autostart=false autorestart=false @@ -56,7 +56,7 @@ dependent_startup_wait_for=start:exited programs=dhcpmon-Vlan1000 [program:dhcpmon-Vlan1000] -command=/usr/sbin/dhcpmon -id Vlan1000 -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 priority=4 autostart=false autorestart=false diff --git a/src/sonic-config-engine/tests/sample_output/frr.conf b/src/sonic-config-engine/tests/sample_output/frr.conf index 08777924d1..8e84f31ee9 100644 --- a/src/sonic-config-engine/tests/sample_output/frr.conf +++ b/src/sonic-config-engine/tests/sample_output/frr.conf @@ -51,7 +51,9 @@ ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.1/27 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.200.1/27 +! +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.0.1/27 ! ! ! @@ -74,6 +76,7 @@ router bgp 65100 network fc00:1::32/64 exit-address-family ! + network 192.168.200.1/27 network 192.168.0.1/27 ! ! diff --git a/src/sonic-config-engine/tests/sample_output/ipinip.json b/src/sonic-config-engine/tests/sample_output/ipinip.json index c93564de77..a33bb2d313 100644 --- a/src/sonic-config-engine/tests/sample_output/ipinip.json +++ b/src/sonic-config-engine/tests/sample_output/ipinip.json @@ -2,7 +2,7 @@ { "TUNNEL_DECAP_TABLE:IPINIP_TUNNEL" : { "tunnel_type":"IPINIP", - "dst_ip":"10.1.0.32,10.0.0.58,10.0.0.60,10.0.0.62,10.0.0.56,192.168.0.1", + "dst_ip":"10.1.0.32,10.0.0.58,10.0.0.60,10.0.0.62,10.0.0.56,192.168.200.1,192.168.0.1", "dscp_mode":"pipe", "ecn_mode":"copy_from_outer", "ttl_mode":"pipe" diff --git a/src/sonic-config-engine/tests/sample_output/wait_for_intf.sh b/src/sonic-config-engine/tests/sample_output/wait_for_intf.sh index 2af5cee2f0..4852f6167b 100644 --- a/src/sonic-config-engine/tests/sample_output/wait_for_intf.sh +++ b/src/sonic-config-engine/tests/sample_output/wait_for_intf.sh @@ -23,6 +23,7 @@ function wait_until_iface_ready # Wait for all interfaces with IPv4 addresses to be up and ready +wait_until_iface_ready Vlan2000 192.168.200.1/27 wait_until_iface_ready Vlan1000 192.168.0.1/27 wait_until_iface_ready PortChannel02 10.0.0.58/31 wait_until_iface_ready PortChannel03 10.0.0.60/31 diff --git a/src/sonic-config-engine/tests/t0-sample-graph.xml b/src/sonic-config-engine/tests/t0-sample-graph.xml index d3d0a7f93d..9f416d008d 100644 --- a/src/sonic-config-engine/tests/t0-sample-graph.xml +++ b/src/sonic-config-engine/tests/t0-sample-graph.xml @@ -246,6 +246,20 @@ + + Vlan2000 + fortyGigE0/112;fortyGigE0/116;fortyGigE0/120 + False + 0.0.0.0/0 + + + + 2000 + 2000 + 192.168.200.0/27 + + + Vlan99 fortyGigE0/100 @@ -321,6 +335,11 @@ Vlan1000 192.168.0.1/27 + + + Vlan2000 + 192.168.200.1/27 +