Skip to content

Commit 7c759ca

Browse files
AnantKishorSharmacshivashgitashutosh-agrawalCopilotStormLiangMS
authored
[dhcp_relay] sonic dhcp relay agent for IPv4 (#22486)
Why I did it Currently SONiC uses the 'isc-dhcp-relay' package to allow DHCP relay functionality on IPv4 networks. With this PR we are adding sonic dhcp relay agent for IPv4 as described in this HLD(sonic-net/SONiC#1938) Work item tracking Microsoft ADO (number only): How I did it Edit supervisord template to start sonic DHCPv4 relay instance when configured to do so in Config DB. Align cfg unit test to the new change. How to verify it Configure sonic DHCPv4 agent as described in the feature HLD(sonic-net/SONiC#1938) Test it with real client/server with IPv4 or use the sonic-mgmt suite Signed-off-by: Ashutosh Agrawal <[email protected]> Co-authored-by: Shivashankar C R <[email protected]> Co-authored-by: Ashutosh Agrawal <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: StormLiangMS <[email protected]>
1 parent cf7dbe0 commit 7c759ca

19 files changed

+1470
-6
lines changed

dockers/docker-dhcp-relay/Dockerfile.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RUN apt-get update
1414

1515
RUN apt-get install -y libjsoncpp-dev \
1616
python3-dev \
17-
build-essential
17+
build-essential \
18+
libpcap-dev
1819

1920
RUN pip3 install psutil
2021

@@ -40,7 +41,7 @@ RUN apt-get remove -y build-essential \
4041

4142
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
4243
COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
43-
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcp-relay.monitors.j2", "/usr/share/sonic/templates/"]
44+
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv4-sonic-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcp-relay.monitors.j2", "/usr/share/sonic/templates/"]
4445
COPY ["critical_processes", "/etc/supervisor"]
4546
COPY ["cli", "/cli/"]
4647

dockers/docker-dhcp-relay/dhcp-relay.monitors.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ stdout_syslog=true
4949
stderr_logfile=NONE
5050
stderr_syslog=true
5151
dependent_startup=true
52+
{% if 'has_sonic_dhcpv4_relay' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['has_sonic_dhcpv4_relay'] == 'True' %}
53+
dependent_startup_wait_for=dhcp4relay:running
54+
{% else %}
5255
dependent_startup_wait_for=isc-dhcpv4-relay-{{ vlan_name }}:running
56+
{% endif %}
5357

5458
{% endfor %}

dockers/docker-dhcp-relay/dhcp-relay.programs.j2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[group:dhcp-relay]
22
programs=dhcprelayd
3+
{%- if 'has_sonic_dhcpv4_relay' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['has_sonic_dhcpv4_relay'] == 'True' %}
34
{%- set relay_for_ipv6 = { 'flag': False } %}
45
{%- set add_preceding_comma = { 'flag': True } %}
56
{% for vlan_name in VLAN_INTERFACE %}
@@ -12,4 +13,25 @@ programs=dhcprelayd
1213
{% if add_preceding_comma.flag %},{% endif %}
1314
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
1415
dhcp6relay
16+
{%- endif %}
17+
{# Create a program entry for sonic dhcpv4 relay agent #}
18+
{%- set add_preceding_comma = { 'flag': True } %}
19+
{# Append sonic DHCPv4 agent #}
20+
{% if add_preceding_comma.flag %},{% endif %}
21+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
22+
dhcp4relay
23+
{% else %}
24+
{%- set relay_for_ipv6 = { 'flag': False } %}
25+
{%- set add_preceding_comma = { 'flag': True } %}
26+
{% for vlan_name in VLAN_INTERFACE %}
27+
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and DHCP_RELAY[vlan_name]['dhcpv6_servers']|length > 0 %}
28+
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
29+
{%- endif %}
30+
{% endfor %}
31+
{# Append DHCPv6 agents #}
32+
{% if relay_for_ipv6.flag %}
33+
{% if add_preceding_comma.flag %},{% endif %}
34+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
35+
dhcp6relay
36+
{% endif %}
1537
{% endif %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{# Append DHCPv4 sonic agent #}
2+
[program:dhcp4relay]
3+
command=/usr/sbin/dhcp4relay{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %} -u Loopback0{% endif %}
4+
5+
priority=3
6+
autostart=false
7+
autorestart=false
8+
stdout_logfile=NONE
9+
stdout_syslog=true
10+
stderr_logfile=NONE
11+
stderr_syslog=true
12+
dependent_startup=true
13+
dependent_startup_wait_for=start:exited
14+
15+

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ dependent_startup_wait_for=rsyslogd:running
4848
{# Count how many VLANs require a DHCP relay agent... #}
4949
{% set ipv4_num_relays = { 'count': 0 } %}
5050
{% set ipv6_num_relays = { 'count': 0 } %}
51+
{% if 'has_sonic_dhcpv4_relay' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['has_sonic_dhcpv4_relay'] == 'True' %}
52+
{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %}
53+
{% endif %}
5154
{% for vlan_name in VLAN_INTERFACE %}
5255
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
5356
{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %}
@@ -63,6 +66,12 @@ dependent_startup_wait_for=rsyslogd:running
6366
{# Create a program entry for each DHCP relay agent instance #}
6467
{% set relay_for_ipv4 = { 'flag': False } %}
6568
{% set relay_for_ipv6 = { 'flag': False } %}
69+
{# Decide the dhcpv4 relay agent based on the feature config #}
70+
{% if 'has_sonic_dhcpv4_relay' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['has_sonic_dhcpv4_relay'] == 'True' %}
71+
{% include 'dhcpv4-sonic-relay.agents.j2' %}
72+
{% include 'dhcpv6-relay.agents.j2' %}
73+
{% include 'dhcp-relay.monitors.j2' %}
74+
{% else %}
6675
{% set added_vlan = []%}
6776
{% for (vlan_name, prefix) in VLAN_INTERFACE|pfx_filter %}
6877
{%- if prefix | ipv4 and vlan_name not in added_vlan %}
@@ -75,6 +84,11 @@ dependent_startup_wait_for=rsyslogd:running
7584
{% include 'dhcp-relay.monitors.j2' %}
7685
{% endif %}
7786
{% endif %}
87+
{% else %}
88+
{% if 'has_sonic_dhcpv4_relay' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['has_sonic_dhcpv4_relay'] == 'True' %}
89+
{% include 'dhcpv4-sonic-relay.agents.j2' %}
90+
{% endif %}
91+
{% endif %}
7892
[program:dhcprelayd]
7993
command=/usr/local/bin/dhcprelayd
8094
priority=3

rules/dhcp4relay.dep

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
SPATH := $($(SONIC_DHCP4RELAY)_SRC_PATH)
3+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/dhcp4relay.mk rules/dhcp4relay.dep
4+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
5+
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files --recurse-submodules))
6+
7+
$(SONIC_DHCP4RELAY)_CACHE_MODE := GIT_CONTENT_SHA
8+
$(SONIC_DHCP4RELAY)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
9+
$(SONIC_DHCP4RELAY)_DEP_FILES := $(DEP_FILES)
10+
$(SONIC_DHCP4RELAY)_SMDEP_FILES := $(SMDEP_FILES)
11+
$(SONIC_DHCP4RELAY)_SMDEP_PATHS := $(SPATH)

rules/dhcp4relay.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SONiC DHCPV4 RELAY Package
2+
3+
SONIC_DHCP4RELAY_VERSION = 1.0.0-0
4+
SONIC_DHCP4RELAY_PKG_NAME = dhcp4relay
5+
6+
SONIC_DHCP4RELAY = sonic-$(SONIC_DHCP4RELAY_PKG_NAME)_$(SONIC_DHCP4RELAY_VERSION)_$(CONFIGURED_ARCH).deb
7+
$(SONIC_DHCP4RELAY)_DEPENDS = $(LIBSWSSCOMMON) $(LIBSWSSCOMMON_DEV)
8+
$(SONIC_DHCP4RELAY)_SRC_PATH = $(SRC_PATH)/dhcprelay/dhcp4relay
9+
SONIC_DPKG_DEBS += $(SONIC_DHCP4RELAY)
10+
11+
SONIC_DHCP4RELAY_DBG = sonic-$(SONIC_DHCP4RELAY_PKG_NAME)-dbgsym_$(SONIC_DHCP4RELAY_VERSION)_$(CONFIGURED_ARCH).deb
12+
$(eval $(call add_derived_package,$(SONIC_DHCP4RELAY),$(SONIC_DHCP4RELAY_DBG)))

rules/docker-dhcp-relay.dep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
DPATH := $($(DOCKER_DHCP_RELAY)_PATH)
3-
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/docker-dhcp-relay.mk rules/docker-dhcp-relay.dep
3+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/docker-dhcp-relay.mk rules/docker-dhcp-relay.dep
44
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
55
DEP_FILES += $(shell git ls-files $(DPATH))
66

rules/docker-dhcp-relay.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ 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) $(SONIC_DHCPMON) $(SONIC_DHCPRELAY) $(LIBSWSSCOMMON)
9+
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(SONIC_DHCPMON) $(SONIC_DHCP4RELAY) $(SONIC_DHCPRELAY) $(LIBSWSSCOMMON)
1010

1111
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_DEPENDS)
12-
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) $(SONIC_DHCPRELAY_DBG) $(SONIC_DHCPMON_DBG)
12+
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) $(SONIC_DHCP4RELAY_DBG) $(SONIC_DHCPRELAY_DBG) $(SONIC_DHCPMON_DBG)
1313

1414
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_IMAGE_PACKAGES)
1515

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"VLAN_INTERFACE": {
3+
"Vlan1000|fc02:2000::2/24": {}
4+
},
5+
"FEATURE": {
6+
"dhcp_server": {
7+
"state": "disabled"
8+
},
9+
"dhcp_relay": {
10+
"auto_restart": "disabled",
11+
"check_up_status": "False",
12+
"delayed": "False",
13+
"has_global_scope": "True",
14+
"has_per_asic_scope": "False",
15+
"high_mem_alert": "disabled",
16+
"set_owner": "local",
17+
"state": "enabled",
18+
"support_syslog_rate_limit": "True"
19+
}
20+
21+
},
22+
"DEVICE_METADATA": {
23+
"localhost": {
24+
"has_sonic_dhcpv4_relay": "False"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)