Skip to content

Commit 757130c

Browse files
authored
[201911] Add dhcp6relay as dhcprelay submodule (#12052)
1 parent 7769540 commit 757130c

21 files changed

+312
-124
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@
8383
[submodule "src/sonic-ztp"]
8484
path = src/sonic-ztp
8585
url = https://github.com/sonic-net/sonic-ztp
86+
[submodule "src/dhcprelay"]
87+
path = src/dhcprelay
88+
url = https://github.com/sonic-net/sonic-dhcp-relay.git
89+
branch = 201911

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,63 @@
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 monitor_instance.flag %}
10+
{% if add_preceding_comma.flag %},{% endif %}
11+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
12+
dhcpmon-{{ vlan_name }}
13+
{%- set _dummy = monitor_instance.update({'flag': False}) %}
14+
{%- endif %}
15+
{% endfor %}
16+
17+
18+
{# Create a program entry for each DHCP MONitor instance #}
19+
{% set relay_for_ipv4 = { 'flag': False } %}
20+
{% for vlan_name in VLAN_INTERFACE %}
21+
{# Check DHCPv4 agents #}
22+
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
23+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
24+
{% if dhcp_server | ipv4 %}
25+
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
26+
{% endif %}
27+
{% endfor %}
28+
{% endif %}
29+
{% if relay_for_ipv4.flag %}
30+
[program:dhcpmon-{{ vlan_name }}]
31+
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
32+
command=/usr/sbin/dhcpmon -id {{ vlan_name }}
33+
{#- Dual ToR Option #}
34+
{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif -%}
35+
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
36+
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
37+
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
38+
{% endfor %}
39+
{% for (name, prefix) in INTERFACE|pfx_filter %}
40+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
41+
{% endfor %}
42+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
43+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
44+
{% endfor %}
45+
{% if MGMT_INTERFACE %}
46+
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
47+
{% if prefix | ipv4 %} -im {{ name }}{% endif -%}
48+
{% endfor %}
49+
{% endif %}
50+
51+
priority=4
52+
autostart=false
53+
autorestart=false
54+
stdout_logfile=syslog
55+
stderr_logfile=syslog
56+
dependent_startup=true
57+
dependent_startup_wait_for=
58+
{%- if relay_for_ipv4.flag %}isc-dhcpv4-relay-{{ vlan_name }}:running {% endif %}
59+
60+
61+
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
62+
{% endif %}
63+
{% 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,24 @@
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+
priority=3
15+
autostart=false
16+
autorestart=false
17+
stdout_logfile=syslog
18+
stderr_logfile=syslog
19+
dependent_startup=true
20+
dependent_startup_wait_for=start:exited
21+
22+
{% endif %}
23+
{% endif %}
24+
{% 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/dhcprelay.mk

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SONiC DHCPV6 RELAY Package
2+
3+
SONIC_DHCPRELAY_VERSION = 1.0.0-0
4+
SONIC_DHCPRELAY_PKG_NAME = dhcp6relay
5+
6+
SONIC_DHCPRELAY = sonic-$(SONIC_DHCPRELAY_PKG_NAME)_$(SONIC_DHCPRELAY_VERSION)_$(CONFIGURED_ARCH).deb
7+
$(SONIC_DHCPRELAY)_DEPENDS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV)
8+
$(SONIC_DHCPRELAY)_SRC_PATH = $(SRC_PATH)/dhcprelay
9+
SONIC_DPKG_DEBS += $(SONIC_DHCPRELAY)
10+
11+
SONIC_DHCPRELAY_DBG = sonic-$(SONIC_DHCPRELAY_PKG_NAME)-dbgsym_$(SONIC_DHCPRELAY_VERSION)_amd64.deb
12+
$(eval $(call add_derived_package,$(SONIC_DHCPRELAY),$(SONIC_DHCPRELAY_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) $(LIBSWSSCOMMON) $(SONIC_DHCPMON) $(SONIC_DHCPRELAY)
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_DHCPRELAY_DBG)
1212

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

sonic-slave-stretch/Dockerfile.j2

+8-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,14 @@ RUN apt-get update && apt-get install -y \
301301
xxd \
302302
# For DHCP Monitor tool
303303
libexplain-dev \
304-
libevent-dev
304+
libevent-dev \
305+
# For dhcp6relay
306+
libboost-dev \
307+
libboost-system-dev \
308+
libboost-thread-dev \
309+
libboost-atomic-dev \
310+
libboost-chrono-dev \
311+
libboost-date-time-dev
305312

306313
## Config dpkg
307314
## install the configuration file if it’s currently missing

src/dhcprelay

Submodule dhcprelay added at 04a2d41

0 commit comments

Comments
 (0)