Skip to content

Commit e4b35ee

Browse files
shlomibittonCarl Keene
authored and
Carl Keene
committed
[dhcp_relay] DHCP relay support for IPv6 (sonic-net#7772)
Why I did it Currently SONiC use the 'isc-dhcp-relay' package to allow DHCP relay functionality on IPv4 networks only. This will allow the IPv6 functionality along the IPv4 type. How I did it Edit supervisord template to start DHCPv6 instances when configured to do so on Config DB. Align cfg unit test to the new change. Add DHCPv6 relay minigraph parsing support and a suitable t0 topology xml file for UT. How to verify it Configure DHCPv6 agents as described on the feature HLD: sonic-net/SONiC#765 Test it with real client/server with IPv6 or use the dedicated automatic test: sonic-net/sonic-mgmt#3565 Signed-off-by: Shlomi Bitton <[email protected]> * Split docker-dhcp-relay.supervisord.conf.j2 template into several files for easier code maintenance
1 parent f78aa4f commit e4b35ee

8 files changed

+214
-118
lines changed

dockers/docker-dhcp-relay/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN apt-get clean -y && \
3030

3131
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
3232
COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
33+
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcpv6-relay.monitors.j2", "/usr/share/sonic/templates/"]
3334
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
3435
COPY ["critical_processes", "/etc/supervisor"]
3536
COPY ["cli", "/cli/"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[group:isc-dhcp-relay]
2+
programs=
3+
{%- set add_preceding_comma = { 'flag': False } %}
4+
{% for vlan_name in VLAN_INTERFACE %}
5+
{# Append DHCPv4 agents #}
6+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
7+
{% if add_preceding_comma.flag %},{% endif %}
8+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
9+
isc-dhcpv4-relay-{{ vlan_name }}
10+
{%- endif %}
11+
{# Append DHCPv6 agents #}
12+
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
13+
{% if add_preceding_comma.flag %},{% endif %}
14+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
15+
isc-dhcpv6-relay-{{ vlan_name }}
16+
{%- endif %}
17+
{% endfor %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{# Append DHCPv4 agents #}
2+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
3+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
4+
{% if dhcp_server | ipv4 %}
5+
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
6+
{% endif %}
7+
{% endfor %}
8+
{% if relay_for_ipv4.flag %}
9+
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
10+
[program:isc-dhcpv4-relay-{{ vlan_name }}]
11+
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
12+
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}
13+
{#- Dual ToR Option #}
14+
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -U Loopback0 -dt{% endif -%}
15+
{#- si option to use intf addr in relay #}
16+
{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%}
17+
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
18+
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
19+
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
20+
{% endfor %}
21+
{% for (name, prefix) in INTERFACE|pfx_filter %}
22+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
23+
{% endfor %}
24+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
25+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
26+
{% endfor %}
27+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
28+
{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%}
29+
{% endfor %}
30+
31+
priority=3
32+
autostart=false
33+
autorestart=false
34+
stdout_logfile=syslog
35+
stderr_logfile=syslog
36+
dependent_startup=true
37+
dependent_startup_wait_for=start:exited
38+
39+
{% endif %}
40+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{# Append DHCPv6 agents #}
2+
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
3+
{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
4+
{% if dhcpv6_server | ipv6 %}
5+
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
6+
{% endif %}
7+
{% endfor %}
8+
{% if relay_for_ipv6.flag %}
9+
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
10+
[program:isc-dhcpv6-relay-{{ vlan_name }}]
11+
{# We treat this VLAN as a downstream interface (-l), as we only want to listen for requests #}
12+
command=/usr/sbin/dhcrelay -d -6 --name-alias-map-file /tmp/port-name-alias-map.txt -l {{ vlan_name }}
13+
{#- We treat all other interfaces as upstream interfaces (-u), as we only want to listen for replies #}
14+
{%- for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
15+
{%- if dhcpv6_server | ipv6 %}
16+
{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
17+
{%- if prefix | ipv6 and name != vlan_name %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
18+
{% endfor %}
19+
{% for (name, prefix) in INTERFACE|pfx_filter %}
20+
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
21+
{% endfor %}
22+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
23+
{% if prefix | ipv6 %} -u {{ dhcpv6_server }}%%{{ name }} {% endif -%}
24+
{% endfor %}
25+
{% endif -%}
26+
{% endfor %}
27+
28+
priority=3
29+
autostart=false
30+
autorestart=false
31+
stdout_logfile=syslog
32+
stderr_logfile=syslog
33+
dependent_startup=true
34+
dependent_startup_wait_for=start:exited
35+
36+
{% endif %}
37+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[group:dhcpmon]
2+
programs=
3+
{%- set add_preceding_comma = { 'flag': False } %}
4+
{% set monitor_instance = { 'flag': False } %}
5+
{% for vlan_name in VLAN_INTERFACE %}
6+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
7+
{% set _dummy = monitor_instance.update({'flag': True}) %}
8+
{%- endif %}
9+
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
10+
{% set _dummy = monitor_instance.update({'flag': True}) %}
11+
{%- endif %}
12+
{% if monitor_instance.flag %}
13+
{% if add_preceding_comma.flag %},{% endif %}
14+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
15+
dhcpmon-{{ vlan_name }}
16+
{%- set _dummy = monitor_instance.update({'flag': False}) %}
17+
{%- endif %}
18+
{% endfor %}
19+
20+
21+
{# Create a program entry for each DHCP MONitor instance #}
22+
{% set relay_for_ipv4 = { 'flag': False } %}
23+
{% set relay_for_ipv6 = { 'flag': False } %}
24+
{% for vlan_name in VLAN_INTERFACE %}
25+
{# Check DHCPv4 agents #}
26+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
27+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
28+
{% if dhcp_server | ipv4 %}
29+
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
30+
{% endif %}
31+
{% endfor %}
32+
{% endif %}
33+
{# Check DHCPv6 agents #}
34+
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
35+
{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
36+
{% if dhcpv6_server | ipv6 %}
37+
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
38+
{% endif %}
39+
{% endfor %}
40+
{% endif %}
41+
{% if relay_for_ipv4.flag or relay_for_ipv6.flag %}
42+
[program:dhcpmon-{{ vlan_name }}]
43+
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
44+
command=/usr/sbin/dhcpmon -id {{ vlan_name }}
45+
{#- Dual ToR Option #}
46+
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif -%}
47+
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
48+
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
49+
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
50+
{% endfor %}
51+
{% for (name, prefix) in INTERFACE|pfx_filter %}
52+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
53+
{% endfor %}
54+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
55+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
56+
{% endfor %}
57+
{% if MGMT_INTERFACE %}
58+
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
59+
{% if prefix | ipv4 %} -im {{ name }}{% endif -%}
60+
{% endfor %}
61+
{% endif %}
62+
{% if relay_for_ipv4.flag %} -4{% endif %}
63+
{% if relay_for_ipv6.flag %} -6{% endif %}
64+
65+
priority=4
66+
autostart=false
67+
autorestart=false
68+
stdout_logfile=syslog
69+
stderr_logfile=syslog
70+
dependent_startup=true
71+
dependent_startup_wait_for=
72+
{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %}
73+
{% if relay_for_ipv6.flag %}isc-dhcpv6-relay-{{ vlan_name }}:running{% endif %}
74+
75+
76+
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
77+
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
78+
{% endif %}
79+
{% endfor %}

dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2

+12-108
Original file line numberDiff line numberDiff line change
@@ -42,125 +42,29 @@ dependent_startup_wait_for=rsyslogd:running
4242
{# If our configuration has VLANs... #}
4343
{% if VLAN_INTERFACE %}
4444
{# Count how many VLANs require a DHCP relay agent... #}
45-
{% set num_relays = { 'count': 0 } %}
45+
{% set ipv4_num_relays = { 'count': 0 } %}
46+
{% set ipv6_num_relays = { 'count': 0 } %}
4647
{% for vlan_name in VLAN_INTERFACE %}
4748
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
48-
{% set _dummy = num_relays.update({'count': num_relays.count + 1}) %}
49+
{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %}
50+
{% endif %}
51+
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
52+
{% set _dummy = ipv6_num_relays.update({'count': ipv6_num_relays.count + 1}) %}
4953
{% endif %}
5054
{% endfor %}
5155
{# If one or more of the VLANs require a DHCP relay agent... #}
52-
{% if num_relays.count > 0 %}
53-
[group:isc-dhcp-relay]
54-
programs=
55-
{%- set add_preceding_comma = { 'flag': False } %}
56-
{% for vlan_name in VLAN_INTERFACE %}
57-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
58-
{% if add_preceding_comma.flag %},{% endif %}
59-
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
60-
isc-dhcp-relay-{{ vlan_name }}
61-
{%- endif %}
62-
{% endfor %}
56+
{% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %}
57+
{% include 'dhcp-relay.programs.j2' %}
6358

6459

6560
{# Create a program entry for each DHCP relay agent instance #}
6661
{% set relay_for_ipv4 = { 'flag': False } %}
62+
{% set relay_for_ipv6 = { 'flag': False } %}
6763
{% for vlan_name in VLAN_INTERFACE %}
68-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
69-
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
70-
{% if dhcp_server | ipv4 %}
71-
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
72-
{% endif %}
73-
{% endfor %}
74-
{% if relay_for_ipv4.flag %}
75-
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
76-
[program:isc-dhcp-relay-{{ vlan_name }}]
77-
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
78-
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}
79-
{#- Dual ToR Option #}
80-
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -U Loopback0 -dt{% endif -%}
81-
{#- si option to use intf addr in relay #}
82-
{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%}
83-
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
84-
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
85-
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
86-
{% endfor %}
87-
{% for (name, prefix) in INTERFACE|pfx_filter %}
88-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
89-
{% endfor %}
90-
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
91-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
92-
{% endfor %}
93-
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
94-
{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%}
95-
{% endfor %}
96-
97-
priority=3
98-
autostart=false
99-
autorestart=false
100-
stdout_logfile=syslog
101-
stderr_logfile=syslog
102-
dependent_startup=true
103-
dependent_startup_wait_for=start:exited
104-
105-
{% endif %}
106-
{% endif %}
107-
{% endfor %}
108-
109-
[group:dhcpmon]
110-
programs=
111-
{%- set add_preceding_comma = { 'flag': False } %}
112-
{% for vlan_name in VLAN_INTERFACE %}
113-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
114-
{% if add_preceding_comma.flag %},{% endif %}
115-
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
116-
dhcpmon-{{ vlan_name }}
117-
{%- endif %}
118-
{% endfor %}
119-
120-
121-
{# Create a program entry for each DHCP MONitor instance #}
122-
{% set relay_for_ipv4 = { 'flag': False } %}
123-
{% for vlan_name in VLAN_INTERFACE %}
124-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
125-
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
126-
{% if dhcp_server | ipv4 %}
127-
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
128-
{% endif %}
129-
{% endfor %}
130-
{% if relay_for_ipv4.flag %}
131-
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
132-
[program:dhcpmon-{{ vlan_name }}]
133-
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
134-
command=/usr/sbin/dhcpmon -id {{ vlan_name }}
135-
{#- Dual ToR Option #}
136-
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif -%}
137-
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
138-
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
139-
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
140-
{% endfor %}
141-
{% for (name, prefix) in INTERFACE|pfx_filter %}
142-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
143-
{% endfor %}
144-
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
145-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
146-
{% endfor %}
147-
{% if MGMT_INTERFACE %}
148-
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
149-
{% if prefix | ipv4 %} -im {{ name }}{% endif -%}
150-
{% endfor %}
151-
{% endif %}
152-
153-
priority=4
154-
autostart=false
155-
autorestart=false
156-
stdout_logfile=syslog
157-
stderr_logfile=syslog
158-
dependent_startup=true
159-
dependent_startup_wait_for=isc-dhcp-relay-{{ vlan_name }}:running
160-
161-
{% endif %}
162-
{% endif %}
64+
{% include 'dhcpv4-relay.agents.j2' %}
65+
{% include 'dhcpv6-relay.agents.j2' %}
16366
{% endfor %}
16467

68+
{% include 'dhcpv6-relay.monitors.j2' %}
16569
{% endif %}
16670
{% endif %}

src/sonic-config-engine/tests/sample_output/py2/docker-dhcp-relay.supervisord.conf

+14-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ dependent_startup=true
4040
dependent_startup_wait_for=rsyslogd:running
4141

4242
[group:isc-dhcp-relay]
43-
programs=isc-dhcp-relay-Vlan1000
43+
programs=isc-dhcpv4-relay-Vlan1000,isc-dhcpv6-relay-Vlan1000
4444

45-
[program:isc-dhcp-relay-Vlan1000]
45+
[program:isc-dhcpv4-relay-Vlan1000]
4646
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
4747
priority=3
4848
autostart=false
@@ -52,19 +52,28 @@ stderr_logfile=syslog
5252
dependent_startup=true
5353
dependent_startup_wait_for=start:exited
5454

55+
[program:isc-dhcpv6-relay-Vlan1000]
56+
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
57+
priority=3
58+
autostart=false
59+
autorestart=false
60+
stdout_logfile=syslog
61+
stderr_logfile=syslog
62+
dependent_startup=true
63+
dependent_startup_wait_for=start:exited
64+
5565

5666
[group:dhcpmon]
5767
programs=dhcpmon-Vlan1000
5868

5969
[program:dhcpmon-Vlan1000]
60-
command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 -im eth0
70+
command=/usr/sbin/dhcpmon -id Vlan1000 -iu Vlan2000 -iu PortChannel02 -iu PortChannel03 -iu PortChannel04 -iu PortChannel01 -im eth0 -4 -6
6171
priority=4
6272
autostart=false
6373
autorestart=false
6474
stdout_logfile=syslog
6575
stderr_logfile=syslog
6676
dependent_startup=true
67-
dependent_startup_wait_for=isc-dhcp-relay-Vlan1000:running
68-
77+
dependent_startup_wait_for=isc-dhcpv4-relay-Vlan1000:running isc-dhcpv6-relay-Vlan1000:running
6978

7079

0 commit comments

Comments
 (0)