Skip to content

Commit 552684f

Browse files
authored
[dhcp_relay] Add support for DHCP client(s) on one VLAN and DHCP server(s) on another (#2946)
1 parent 2e9b18d commit 552684f

12 files changed

+924
-30
lines changed

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

+20-15
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,33 @@ stderr_logfile=syslog
3232
{% if num_relays.count > 0 %}
3333
[group:isc-dhcp-relay]
3434
programs=
35-
{%- set add_preceding_comma = { 'flag': False } -%}
36-
{%- for vlan_name in VLAN -%}
37-
{%- if VLAN[vlan_name]['dhcp_servers'] -%}
38-
{%- if add_preceding_comma.flag %},{% endif -%}
39-
{%- set _dummy = add_preceding_comma.update({'flag': True}) -%}
35+
{%- set add_preceding_comma = { 'flag': False } %}
36+
{% for vlan_name in VLAN %}
37+
{% if VLAN[vlan_name]['dhcp_servers'] %}
38+
{% if add_preceding_comma.flag %},{% endif %}
39+
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
4040
isc-dhcp-relay-{{ vlan_name }}
4141
{%- endif %}
4242
{% endfor %}
4343

4444

4545
{# Create a program entry for each DHCP relay agent instance #}
46-
{% for vlan_name in VLAN -%}
47-
{%- if VLAN[vlan_name]['dhcp_servers'] -%}
46+
{% for vlan_name in VLAN %}
47+
{% if VLAN[vlan_name]['dhcp_servers'] %}
4848
[program:isc-dhcp-relay-{{ vlan_name }}]
49-
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -i {{ vlan_name }}
50-
{%- for (name, prefix) in INTERFACE -%}
51-
{%- if prefix | ipv4 %} -i {{ name }}{% endif -%}
52-
{%- endfor -%}
53-
{%- for (name, prefix) in PORTCHANNEL_INTERFACE -%}
54-
{%- if prefix | ipv4 %} -i {{ name }}{% endif -%}
55-
{%- endfor -%}
56-
{%- for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {{ dhcp_server }}{% endfor %}
49+
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
50+
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}
51+
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
52+
{% for (name, prefix) in VLAN_INTERFACE %}
53+
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
54+
{% endfor %}
55+
{% for (name, prefix) in INTERFACE %}
56+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
57+
{% endfor %}
58+
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
59+
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
60+
{% endfor %}
61+
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {{ dhcp_server }}{% endfor %}
5762

5863
priority=3
5964
autostart=false

rules/docker-dhcp-relay.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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_COMMON) $(ISC_DHCP_RELAY) $(REDIS_TOOLS)
9+
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(REDIS_TOOLS)
1010
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
1111
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)
1212

rules/isc-dhcp.mk

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# isc-dhcp packages
22

3-
ISC_DHCP_VERSION = 4.3.5-3.1
3+
ISC_DHCP_VERSION = 4.3.5-2
44

55
export ISC_DHCP_VERSION
66

7-
ISC_DHCP_COMMON = isc-dhcp-common_$(ISC_DHCP_VERSION)_amd64.deb
8-
$(ISC_DHCP_COMMON)_SRC_PATH = $(SRC_PATH)/isc-dhcp
9-
SONIC_MAKE_DEBS += $(ISC_DHCP_COMMON)
10-
117
ISC_DHCP_RELAY = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb
12-
$(eval $(call add_derived_package,$(ISC_DHCP_COMMON),$(ISC_DHCP_RELAY)))
8+
$(ISC_DHCP_RELAY)_SRC_PATH = $(SRC_PATH)/isc-dhcp
9+
SONIC_MAKE_DEBS += $(ISC_DHCP_RELAY)
1310

14-
SONIC_STRETCH_DEBS += $(ISC_DHCP_COMMON) $(ISC_DHCP_RELAY)
11+
SONIC_STRETCH_DEBS += $(ISC_DHCP_RELAY)

src/isc-dhcp/Makefile

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
SHELL = /bin/bash
33
.SHELLFLAGS += -e
44

5-
MAIN_TARGET = isc-dhcp-common_$(ISC_DHCP_VERSION)_amd64.deb
6-
DERIVED_TARGETS = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb
5+
MAIN_TARGET = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb
76

87
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
98
# Remove any stale files
@@ -27,6 +26,4 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
2726
popd
2827

2928
# Move the newly-built .deb packages to the destination directory
30-
mv $* $(DERIVED_TARGETS) $(DEST)/
31-
32-
$(addprefix $(DEST)/, $(DERIVED_TARGETS)): $(DEST)/% : $(DEST)/$(MAIN_TARGET)
29+
mv $* $(DEST)/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 5c64cb06e3ac50a1cbca85669625fe16439064ad Mon Sep 17 00:00:00 2001
2+
From: Joe LeVeque <[email protected]>
3+
Date: Fri, 17 May 2019 21:49:00 +0000
4+
Subject: [PATCH 1/3] Add --enable-use-sockets to configure flags in
5+
debian/rules
6+
7+
---
8+
debian/rules | 2 +-
9+
1 file changed, 1 insertion(+), 1 deletion(-)
10+
11+
diff --git a/debian/rules b/debian/rules
12+
index 114606b..9919237 100755
13+
--- a/debian/rules
14+
+++ b/debian/rules
15+
@@ -23,7 +23,7 @@ CFLAGS+=-D_PATH_DHCLIENT_CONF='\"/etc/dhcp/dhclient.conf\"'
16+
CFLAGS+=-D_PATH_DHCLIENT_DB='\"$(LEASE_PATH)/dhclient.leases\"'
17+
CFLAGS+=-D_PATH_DHCLIENT6_DB='\"$(LEASE_PATH)/dhclient6.leases\"'
18+
19+
-CONFFLAGS=--prefix=/usr --enable-log-pid --enable-paranoia
20+
+CONFFLAGS=--prefix=/usr --enable-log-pid --enable-paranoia --enable-use-sockets
21+
22+
# cross-architecture building
23+
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
24+
--
25+
2.17.1
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
From 6620d4778fe36c89ce2e95d6932338cefc90df7d Mon Sep 17 00:00:00 2001
2+
From: Joe LeVeque <[email protected]>
3+
Date: Fri, 17 May 2019 21:53:52 +0000
4+
Subject: [PATCH 2/3] Bugfix: Ensure HAVE_SO_BINDTODEVICE has a chance to be
5+
defined before it is referenced
6+
7+
---
8+
includes/osdep.h | 239 ++++++++++++++++++++++++-----------------------
9+
1 file changed, 120 insertions(+), 119 deletions(-)
10+
11+
diff --git a/includes/osdep.h b/includes/osdep.h
12+
index cfae90b..f07c43c 100644
13+
--- a/includes/osdep.h
14+
+++ b/includes/osdep.h
15+
@@ -48,37 +48,6 @@
16+
#define BYTE_ORDER DHCP_BYTE_ORDER
17+
#endif /* BYTE_ORDER */
18+
19+
-/* Porting::
20+
-
21+
- If you add a new network API, you must add a check for it below: */
22+
-
23+
-#if !defined (USE_SOCKETS) && \
24+
- !defined (USE_SOCKET_SEND) && \
25+
- !defined (USE_SOCKET_RECEIVE) && \
26+
- !defined (USE_RAW_SOCKETS) && \
27+
- !defined (USE_RAW_SEND) && \
28+
- !defined (USE_SOCKET_RECEIVE) && \
29+
- !defined (USE_BPF) && \
30+
- !defined (USE_BPF_SEND) && \
31+
- !defined (USE_BPF_RECEIVE) && \
32+
- !defined (USE_LPF) && \
33+
- !defined (USE_LPF_SEND) && \
34+
- !defined (USE_LPF_RECEIVE) && \
35+
- !defined (USE_NIT) && \
36+
- !defined (USE_NIT_SEND) && \
37+
- !defined (USE_NIT_RECEIVE) && \
38+
- !defined (USE_DLPI_SEND) && \
39+
- !defined (USE_DLPI_RECEIVE)
40+
-/* Determine default socket API to USE. */
41+
-# if defined(HAVE_BPF)
42+
-# define USE_BPF 1
43+
-# elif defined(HAVE_LPF)
44+
-# define USE_LPF 1
45+
-# elif defined(HAVE_DLPI)
46+
-# define USE_DLPI 1
47+
-# endif
48+
-#endif
49+
-
50+
#if !defined (TIME_MAX)
51+
# define TIME_MAX 2147483647
52+
#endif
53+
@@ -91,94 +60,6 @@
54+
# define vsnprintf isc_print_vsnprintf
55+
#endif
56+
57+
-/* Porting::
58+
-
59+
- If you add a new network API, and have it set up so that it can be
60+
- used for sending or receiving, but doesn't have to be used for both,
61+
- then set up an ifdef like the ones below: */
62+
-
63+
-#ifdef USE_SOCKETS
64+
-# define USE_SOCKET_SEND
65+
-# define USE_SOCKET_RECEIVE
66+
-# if defined(HAVE_DLPI) && !defined(sun) && !defined(USE_V4_PKTINFO)
67+
-# define USE_DLPI_HWADDR
68+
-# elif defined(HAVE_LPF)
69+
-# define USE_LPF_HWADDR
70+
-# elif defined(HAVE_BPF)
71+
-# define USE_BPF_HWADDR
72+
-# endif
73+
-#endif
74+
-
75+
-#ifdef USE_RAW_SOCKETS
76+
-# define USE_RAW_SEND
77+
-# define USE_SOCKET_RECEIVE
78+
-#endif
79+
-
80+
-#ifdef USE_BPF
81+
-# define USE_BPF_SEND
82+
-# define USE_BPF_RECEIVE
83+
-#endif
84+
-
85+
-#ifdef USE_LPF
86+
-# define USE_LPF_SEND
87+
-# define USE_LPF_RECEIVE
88+
-#endif
89+
-
90+
-#ifdef USE_NIT
91+
-# define USE_NIT_SEND
92+
-# define USE_NIT_RECEIVE
93+
-#endif
94+
-
95+
-#ifdef USE_DLPI
96+
-# define USE_DLPI_SEND
97+
-# define USE_DLPI_RECEIVE
98+
-#endif
99+
-
100+
-#ifdef USE_UPF
101+
-# define USE_UPF_SEND
102+
-# define USE_UPF_RECEIVE
103+
-#endif
104+
-
105+
-/* Porting::
106+
-
107+
- If you add support for sending packets directly out an interface,
108+
- and your support does not do ARP or routing, you must use a fallback
109+
- mechanism to deal with packets that need to be sent to routers.
110+
- Currently, all low-level packet interfaces use BSD sockets as a
111+
- fallback. */
112+
-
113+
-#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
114+
- defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \
115+
- defined (USE_LPF_SEND) || \
116+
- (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE))
117+
-# define USE_SOCKET_FALLBACK
118+
-# define USE_FALLBACK
119+
-#endif
120+
-
121+
-/* Porting::
122+
-
123+
- If you add support for sending packets directly out an interface
124+
- and need to be able to assemble packets, add the USE_XXX_SEND
125+
- definition for your interface to the list tested below. */
126+
-
127+
-#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
128+
- defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
129+
- defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
130+
-# define PACKET_ASSEMBLY
131+
-#endif
132+
-
133+
-/* Porting::
134+
-
135+
- If you add support for receiving packets directly from an interface
136+
- and need to be able to decode raw packets, add the USE_XXX_RECEIVE
137+
- definition for your interface to the list tested below. */
138+
-
139+
-#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
140+
- defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
141+
- defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE)
142+
-# define PACKET_DECODING
143+
-#endif
144+
-
145+
/* If we don't have a DLPI packet filter, we have to filter in userland.
146+
Probably not worth doing, actually. */
147+
#if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD)
148+
@@ -288,4 +169,124 @@
149+
# define STDERR_FILENO 2
150+
#endif
151+
152+
+/* Porting::
153+
+
154+
+ If you add a new network API, you must add a check for it below: */
155+
+
156+
+#if !defined (USE_SOCKETS) && \
157+
+ !defined (USE_SOCKET_SEND) && \
158+
+ !defined (USE_SOCKET_RECEIVE) && \
159+
+ !defined (USE_RAW_SOCKETS) && \
160+
+ !defined (USE_RAW_SEND) && \
161+
+ !defined (USE_SOCKET_RECEIVE) && \
162+
+ !defined (USE_BPF) && \
163+
+ !defined (USE_BPF_SEND) && \
164+
+ !defined (USE_BPF_RECEIVE) && \
165+
+ !defined (USE_LPF) && \
166+
+ !defined (USE_LPF_SEND) && \
167+
+ !defined (USE_LPF_RECEIVE) && \
168+
+ !defined (USE_NIT) && \
169+
+ !defined (USE_NIT_SEND) && \
170+
+ !defined (USE_NIT_RECEIVE) && \
171+
+ !defined (USE_DLPI_SEND) && \
172+
+ !defined (USE_DLPI_RECEIVE)
173+
+/* Determine default socket API to USE. */
174+
+# if defined(HAVE_BPF)
175+
+# define USE_BPF 1
176+
+# elif defined(HAVE_LPF)
177+
+# define USE_LPF 1
178+
+# elif defined(HAVE_DLPI)
179+
+# define USE_DLPI 1
180+
+# endif
181+
+#endif
182+
+
183+
+/* Porting::
184+
+
185+
+ If you add a new network API, and have it set up so that it can be
186+
+ used for sending or receiving, but doesn't have to be used for both,
187+
+ then set up an ifdef like the ones below: */
188+
+
189+
+#ifdef USE_SOCKETS
190+
+# define USE_SOCKET_SEND
191+
+# define USE_SOCKET_RECEIVE
192+
+# if defined(HAVE_DLPI) && !defined(sun) && !defined(USE_V4_PKTINFO)
193+
+# define USE_DLPI_HWADDR
194+
+# elif defined(HAVE_LPF)
195+
+# define USE_LPF_HWADDR
196+
+# elif defined(HAVE_BPF)
197+
+# define USE_BPF_HWADDR
198+
+# endif
199+
+#endif
200+
+
201+
+#ifdef USE_RAW_SOCKETS
202+
+# define USE_RAW_SEND
203+
+# define USE_SOCKET_RECEIVE
204+
+#endif
205+
+
206+
+#ifdef USE_BPF
207+
+# define USE_BPF_SEND
208+
+# define USE_BPF_RECEIVE
209+
+#endif
210+
+
211+
+#ifdef USE_LPF
212+
+# define USE_LPF_SEND
213+
+# define USE_LPF_RECEIVE
214+
+#endif
215+
+
216+
+#ifdef USE_NIT
217+
+# define USE_NIT_SEND
218+
+# define USE_NIT_RECEIVE
219+
+#endif
220+
+
221+
+#ifdef USE_DLPI
222+
+# define USE_DLPI_SEND
223+
+# define USE_DLPI_RECEIVE
224+
+#endif
225+
+
226+
+#ifdef USE_UPF
227+
+# define USE_UPF_SEND
228+
+# define USE_UPF_RECEIVE
229+
+#endif
230+
+
231+
+/* Porting::
232+
+
233+
+ If you add support for sending packets directly out an interface,
234+
+ and your support does not do ARP or routing, you must use a fallback
235+
+ mechanism to deal with packets that need to be sent to routers.
236+
+ Currently, all low-level packet interfaces use BSD sockets as a
237+
+ fallback. */
238+
+
239+
+#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
240+
+ defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \
241+
+ defined (USE_LPF_SEND) || \
242+
+ (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE))
243+
+# define USE_SOCKET_FALLBACK
244+
+# define USE_FALLBACK
245+
+#endif
246+
+
247+
+/* Porting::
248+
+
249+
+ If you add support for sending packets directly out an interface
250+
+ and need to be able to assemble packets, add the USE_XXX_SEND
251+
+ definition for your interface to the list tested below. */
252+
+
253+
+#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
254+
+ defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
255+
+ defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
256+
+# define PACKET_ASSEMBLY
257+
+#endif
258+
+
259+
+/* Porting::
260+
+
261+
+ If you add support for receiving packets directly from an interface
262+
+ and need to be able to decode raw packets, add the USE_XXX_RECEIVE
263+
+ definition for your interface to the list tested below. */
264+
+
265+
+#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
266+
+ defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
267+
+ defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE)
268+
+# define PACKET_DECODING
269+
+#endif
270+
+
271+
+
272+
#endif /* __ISC_DHCP_OSDEP_H__ */
273+
--
274+
2.17.1
275+

0 commit comments

Comments
 (0)