Skip to content

Commit 01a8af1

Browse files
committed
Replace isc-dhcp with DHCPv6 Relay in dhcp_relay docker (sonic-net#8884)
1 parent 35b5578 commit 01a8af1

34 files changed

+1941
-153
lines changed

dockers/docker-dhcp-relay/Dockerfile.j2

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

2727
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
2828
COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
29+
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcp-relay.monitors.j2", "/usr/share/sonic/templates/"]
2930
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
3031
COPY ["critical_processes", "/etc/supervisor"]
3132

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
group:isc-dhcp-relay
1+
group:dhcp-relay
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 DHCP_RELAY and vlan_name in DHCP_RELAY and DHCP_RELAY[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 DHCP_RELAY and vlan_name in DHCP_RELAY and DHCP_RELAY[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+
63+
priority=4
64+
autostart=false
65+
autorestart=false
66+
stdout_logfile=syslog
67+
stderr_logfile=syslog
68+
dependent_startup=true
69+
dependent_startup_wait_for=
70+
{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %}
71+
72+
73+
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
74+
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
75+
{% endif %}
76+
{% endfor %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[group:dhcp-relay]
2+
programs=
3+
{%- set relay_for_ipv6 = { 'flag': False } %}
4+
{%- set add_preceding_comma = { 'flag': False } %}
5+
{% for vlan_name in VLAN_INTERFACE %}
6+
{# Append DHCPv4 agents #}
7+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
8+
{% if add_preceding_comma.flag %},{% endif %}
9+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
10+
isc-dhcpv4-relay-{{ vlan_name }}
11+
{%- endif %}
12+
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and DHCP_RELAY[vlan_name]['dhcpv6_servers']|length > 0 %}
13+
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
14+
{%- endif %}
15+
{% endfor %}
16+
{# Append DHCPv6 agents #}
17+
{% if relay_for_ipv6.flag %}
18+
{% if add_preceding_comma.flag %},{% endif %}
19+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
20+
dhcp6relay
21+
{% endif %}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
11+
[program:isc-dhcpv4-relay-{{ vlan_name }}]
12+
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
13+
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}
14+
{#- Dual ToR Option #}
15+
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -U Loopback0 -dt{% endif -%}
16+
{#- si option to use intf addr in relay #}
17+
{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%}
18+
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
19+
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
20+
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
21+
{% endfor %}
22+
{% for (name, prefix) in INTERFACE|pfx_filter %}
23+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
24+
{% endfor %}
25+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
26+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
27+
{% endfor %}
28+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
29+
{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%}
30+
{% endfor %}
31+
32+
priority=3
33+
autostart=false
34+
autorestart=false
35+
stdout_logfile=syslog
36+
stderr_logfile=syslog
37+
dependent_startup=true
38+
dependent_startup_wait_for=start:exited
39+
40+
{% endif %}
41+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{# Append DHCPv6 agents #}
2+
{# Create a program entry for each DHCPv6 relay agent instance #}
3+
{% for vlan_name in VLAN_INTERFACE %}
4+
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and 'dhcpv6_servers' in DHCP_RELAY[vlan_name] %}
5+
{% for dhcpv6_server in DHCP_RELAY[vlan_name]['dhcpv6_servers'] %}
6+
{% if dhcpv6_server | ipv6 %}
7+
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
8+
{% endif %}
9+
{% endfor %}
10+
{% if relay_for_ipv6.flag %}
11+
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
12+
[program:dhcp6relay]
13+
command=/usr/sbin/dhcp6relay
14+
15+
priority=3
16+
autostart=false
17+
autorestart=false
18+
stdout_logfile=syslog
19+
stderr_logfile=syslog
20+
21+
{% endif %}
22+
{% endif %}
23+
{% endfor %}

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

+12-107
Original file line numberDiff line numberDiff line change
@@ -41,122 +41,27 @@ dependent_startup_wait_for=rsyslogd:running
4141

4242
{# If our configuration has VLANs... #}
4343
{% if VLAN_INTERFACE %}
44-
{# Count how many VLANs require a DHCP relay agent... #}
45-
{% set num_relays = { 'count': 0 } %}
44+
{% set ipv4_num_relays = { 'count': 0 } %}
45+
{% set ipv6_num_relays = { 'count': 0 } %}
4646
{% for vlan_name in VLAN_INTERFACE %}
4747
{% 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-
{% endif %}
50-
{% endfor %}
51-
{# 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 %}
63-
64-
65-
{# Create a program entry for each DHCP relay agent instance #}
66-
{% set relay_for_ipv4 = { 'flag': False } %}
67-
{% 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-
{#- si option to use intf addr in relay #}
80-
{% if DEVICE_METADATA['localhost']['deployment_id'] == '8' %} -si{% endif -%}
81-
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
82-
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
83-
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
84-
{% endfor %}
85-
{% for (name, prefix) in INTERFACE|pfx_filter %}
86-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
87-
{% endfor %}
88-
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
89-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
90-
{% endfor %}
91-
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
92-
{%- if dhcp_server | ipv4 %} {{ dhcp_server }}{% endif -%}
93-
{% endfor %}
94-
95-
priority=3
96-
autostart=false
97-
autorestart=false
98-
stdout_logfile=syslog
99-
stderr_logfile=syslog
100-
dependent_startup=true
101-
dependent_startup_wait_for=start:exited
102-
48+
{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %}
10349
{% endif %}
50+
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and 'dhcpv6_servers' in DHCP_RELAY[vlan_name] %}
51+
{% set _dummy = ipv6_num_relays.update({'count': ipv6_num_relays.count + 1}) %}
10452
{% endif %}
10553
{% endfor %}
54+
{# If one or more of the VLANs require a DHCP relay agent... #}
55+
{% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %}
56+
{% include 'dhcp-relay.programs.j2' %}
10657

107-
[group:dhcpmon]
108-
programs=
109-
{%- set add_preceding_comma = { 'flag': False } %}
110-
{% for vlan_name in VLAN_INTERFACE %}
111-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
112-
{% if add_preceding_comma.flag %},{% endif %}
113-
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
114-
dhcpmon-{{ vlan_name }}
115-
{%- endif %}
116-
{% endfor %}
117-
118-
119-
{# Create a program entry for each DHCP MONitor instance #}
12058
{% set relay_for_ipv4 = { 'flag': False } %}
59+
{% set relay_for_ipv6 = { 'flag': False } %}
12160
{% for vlan_name in VLAN_INTERFACE %}
122-
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
123-
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
124-
{% if dhcp_server | ipv4 %}
125-
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
126-
{% endif %}
127-
{% endfor %}
128-
{% if relay_for_ipv4.flag %}
129-
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
130-
[program:dhcpmon-{{ vlan_name }}]
131-
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
132-
command=/usr/sbin/dhcpmon -id {{ vlan_name }}
133-
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
134-
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
135-
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
136-
{% endfor %}
137-
{% for (name, prefix) in INTERFACE|pfx_filter %}
138-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
139-
{% endfor %}
140-
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
141-
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
142-
{% endfor %}
143-
{% if MGMT_INTERFACE %}
144-
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
145-
{% if prefix | ipv4 %} -im {{ name }}{% endif -%}
146-
{% endfor %}
147-
{% endif %}
148-
149-
priority=4
150-
autostart=false
151-
autorestart=false
152-
stdout_logfile=syslog
153-
stderr_logfile=syslog
154-
dependent_startup=true
155-
dependent_startup_wait_for=isc-dhcp-relay-{{ vlan_name }}:running
156-
157-
{% endif %}
158-
{% endif %}
61+
{% include 'dhcpv4-relay.agents.j2' %}
15962
{% endfor %}
16063

64+
{% include 'dhcpv6-relay.agents.j2' %}
65+
{% include 'dhcp-relay.monitors.j2' %}
16166
{% endif %}
16267
{% endif %}

dockers/docker-dhcp-relay/start.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# If our supervisor config has entries in the "isc-dhcp-relay" group...
4-
if [ $(supervisorctl status | grep -c "^isc-dhcp-relay:") -gt 0 ]; then
4+
if [ $(supervisorctl status | grep -c "^dhcp-relay:") -gt 0 ]; then
55
# Wait for all interfaces to come up and be assigned IPv4 addresses before
66
# starting the DHCP relay agent(s). If an interface the relay should listen
77
# on is down, the relay agent will not start. If an interface the relay

dockers/docker-dhcp-relay/wait_for_intf.sh.j2

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ wait_until_iface_ready {{ name }} {{ prefix }}
3838
wait_until_iface_ready {{ name }} {{ prefix }}
3939
{% endif %}
4040
{% endfor %}
41+
42+
# Wait 10 seconds for the rest of interfaces to get added/populated.
43+
# dhcrelay listens on each of the interfaces (in addition to the port
44+
# channels and vlan interfaces)
45+
sleep 10

rules/dhcp6relay.mk

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SONiC DHCPV6 RELAY Package
2+
3+
SONIC_DHCP6RELAY_VERSION = 1.0.0-0
4+
SONIC_DHCP6RELAY_PKG_NAME = dhcp6relay
5+
6+
SONIC_DHCP6RELAY = sonic-$(SONIC_DHCP6RELAY_PKG_NAME)_$(SONIC_DHCP6RELAY_VERSION)_$(CONFIGURED_ARCH).deb
7+
$(SONIC_DHCP6RELAY)_DEPENDS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV)
8+
$(SONIC_DHCP6RELAY)_SRC_PATH = $(SRC_PATH)/$(SONIC_DHCP6RELAY_PKG_NAME)
9+
SONIC_DPKG_DEBS += $(SONIC_DHCP6RELAY)
10+
11+
SONIC_DHCP6RELAY_DBG = sonic-$(SONIC_DHCP6RELAY_PKG_NAME)-dbg_$(SONIC_DHCP6RELAY_VERSION)_amd64.deb
12+
$(eval $(call add_derived_package,$(SONIC_DHCP6RELAY),$(SONIC_DHCP6RELAY_DBG)))

rules/docker-dhcp-relay.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ DOCKER_DHCP_RELAY_DBG = $(DOCKER_DHCP_RELAY_STEM)-$(DBG_IMAGE_MARK).gz
66

77
$(DOCKER_DHCP_RELAY)_PATH = $(DOCKERS_PATH)/$(DOCKER_DHCP_RELAY_STEM)
88

9-
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(REDIS_TOOLS) $(SONIC_DHCPMON)
9+
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(REDIS_TOOLS) $(SONIC_DHCPMON) $(SONIC_DHCP6RELAY) $(LIBSWSSCOMMON)
1010
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
11-
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG)
11+
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) $(SONIC_DHCP6RELAY_DBG)
1212

1313
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)
1414

sonic-dhcp-relay

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit e2cd5851ddd9b6496b59b72e75aaba8e4d7f284d

src/dhcp6relay/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
debian/*
2+
!debian/changelog
3+
!debian/compat
4+
!debian/control
5+
!debian/rules

0 commit comments

Comments
 (0)