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

View File

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

View File

@ -1,20 +1,23 @@
{# Append DHCPv6 agents #} {# Append DHCPv6 agent #}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %} {% set relay_for_ipv6 = { 'flag': False } %}
{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %} [program:isc-dhcpv6-relay-{{ v6_vlan_list|join("-") }}]
{% if dhcpv6_server | ipv6 %} command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt
{% set _dummy = relay_for_ipv6.update({'flag': True}) %} {#- We get all DHCPv6 servers only once #}
{% endif %} {%- set dhcpv6_server_list = [] %}
{% endfor %} {%- for vlan_name in v6_vlan_list %}
{% 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'] %} {%- 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 %} {%- if dhcpv6_server | ipv6 %}
{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {%- 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 %} {% endfor %}
{% for (name, prefix) in INTERFACE|pfx_filter %} {% for (name, prefix) in INTERFACE|pfx_filter %}
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} {% 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 %} {% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%} {% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
{% endfor %} {% endfor %}
{% endif -%} {% endif %}
{% endfor %} {% endfor %}
priority=3 priority=3
@ -33,5 +36,3 @@ stderr_logfile=syslog
dependent_startup=true dependent_startup=true
dependent_startup_wait_for=start:exited dependent_startup_wait_for=start:exited
{% endif %}
{% endif %}

View File

@ -70,7 +70,7 @@ stderr_logfile=syslog
dependent_startup=true dependent_startup=true
dependent_startup_wait_for= dependent_startup_wait_for=
{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %} {%- 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}) %} {% set _dummy = relay_for_ipv4.update({'flag': False}) %}

View File

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

View File

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

View File

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