[DHCPv6 relay] [202106] Fix DHCPv6 design to support multiple VLANS (#9163)

- Why I did it
If multiple Vlans are configured to have DHCPv6 relay, only one relay instance is able to capture DHCP packets received from upstream, this is as a result of kernel design to operate this way (SO_REUSEPORT).
DHCPv6 transmit unicast packets to clients, only multicast packets can be captured on multiple application listening on the same UDP port.
This issue causing only one Vlan interface to get packets from servers.

- How I did it
Change the design to neglect Vlan isolation and run only one relay instance serving all Vlans with all configured DHCP servers.

- How to verify it
Run DHCPv6 relay test with 2 Vlans configured do have a DHCP relay.

Signed-off-by: Shlomi Bitton <shlomibi@nvidia.com>
This commit is contained in:
shlomibitton 2021-11-18 19:40:48 +02:00 committed by GitHub
parent e0209f745a
commit 1ebe52847a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 30 deletions

View File

@ -1,17 +1,23 @@
[group:isc-dhcp-relay]
programs=
{%- set add_preceding_comma = { 'flag': False } %}
{% for vlan_name in VLAN_INTERFACE %}
{# Append DHCPv4 agents #}
{% if ipv4_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 %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
isc-dhcpv4-relay-{{ vlan_name }}
{%- endif %}
{# Append DHCPv6 agents #}
{% endfor %}
{% endif %}
{# Append DHCPv6 agent #}
{% if ipv6_num_relays.count > 0 %}
{% for vlan_name in VLAN_INTERFACE %}
{% 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 }}
{% set _dummy = v6_vlan_list.append( vlan_name ) %}
{%- endif %}
{% endfor %}
{% if add_preceding_comma.flag %},{% endif %}
isc-dhcpv6-relay-{{ v6_vlan_list|join("-") }}
{% endif %}

View File

@ -1,4 +1,6 @@
{# Append DHCPv4 agents #}
{% set relay_for_ipv4 = { '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 %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
@ -38,3 +40,4 @@ dependent_startup_wait_for=start:exited
{% endif %}
{% endif %}
{% endfor %}

View File

@ -1,20 +1,23 @@
{# 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 #}
{# Append DHCPv6 agent #}
{% set relay_for_ipv6 = { 'flag': False } %}
[program:isc-dhcpv6-relay-{{ v6_vlan_list|join("-") }}]
command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt
{#- We get all DHCPv6 servers only once #}
{%- set dhcpv6_server_list = [] %}
{%- for vlan_name in v6_vlan_list %}
{%- for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
{%- if dhcpv6_server | ipv6 and dhcpv6_server not in dhcpv6_server_list %}
{%- set _dummy = dhcpv6_server_list.append( dhcpv6_server ) %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{#- We treat each VLAN as a downstream interface (-l), as we only want to listen for requests #}
{%- for vlan_name in v6_vlan_list %} -l {{ vlan_name }}{% endfor -%}
{#- We treat all other interfaces as upstream interfaces (-u), as we only want to listen for replies #}
{%- for dhcpv6_server in dhcpv6_server_list %}
{%- if dhcpv6_server | ipv6 %}
{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{%- if prefix | ipv6 and name != vlan_name %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
{%- if prefix | ipv6 and name not in v6_vlan_list%} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
{% endfor %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
@ -22,7 +25,7 @@ command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
{% endfor %}
{% endif -%}
{% endif %}
{% endfor %}
priority=3
@ -33,5 +36,3 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited
{% endif %}
{% endif %}

View File

@ -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 %}isc-dhcpv6-relay-{{ v6_vlan_list|join("-") }}:running{% endif %}
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}

View File

@ -39,9 +39,11 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running
{% block dhcp_relay_block %}
{# If our configuration has VLANs... #}
{% if VLAN_INTERFACE %}
{# Count how many VLANs require a DHCP relay agent... #}
{% set v6_vlan_list = [] %}
{% set ipv4_num_relays = { 'count': 0 } %}
{% set ipv6_num_relays = { 'count': 0 } %}
{% for vlan_name in VLAN_INTERFACE %}
@ -56,15 +58,15 @@ dependent_startup_wait_for=rsyslogd:running
{% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %}
{% 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 %}
{% if ipv4_num_relays.count > 0 %}
{% include 'dhcpv4-relay.agents.j2' %}
{% endif %}
{% if ipv6_num_relays.count > 0 %}
{% include 'dhcpv6-relay.agents.j2' %}
{% endfor %}
{% endif %}
{% include 'dhcpv6-relay.monitors.j2' %}
{% endif %}
{% endif %}
{% endblock %}

View File

@ -62,7 +62,6 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited
[group:dhcpmon]
programs=dhcpmon-Vlan1000

View File

@ -62,7 +62,6 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited
[group:dhcpmon]
programs=dhcpmon-Vlan1000