Skip to content

Commit

Permalink
[dhcp_relay] Add support for DHCP client(s) on one VLAN and DHCP serv…
Browse files Browse the repository at this point in the history
…er(s) on another (#2946)
  • Loading branch information
jleveque authored Jun 3, 2019
1 parent 2e9b18d commit 552684f
Show file tree
Hide file tree
Showing 12 changed files with 924 additions and 30 deletions.
35 changes: 20 additions & 15 deletions dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ stderr_logfile=syslog
{% if num_relays.count > 0 %}
[group:isc-dhcp-relay]
programs=
{%- set add_preceding_comma = { 'flag': False } -%}
{%- for vlan_name in VLAN -%}
{%- if VLAN[vlan_name]['dhcp_servers'] -%}
{%- if add_preceding_comma.flag %},{% endif -%}
{%- set _dummy = add_preceding_comma.update({'flag': True}) -%}
{%- set add_preceding_comma = { 'flag': False } %}
{% for vlan_name in VLAN %}
{% if VLAN[vlan_name]['dhcp_servers'] %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
isc-dhcp-relay-{{ vlan_name }}
{%- endif %}
{% endfor %}


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

priority=3
autostart=false
Expand Down
2 changes: 1 addition & 1 deletion rules/docker-dhcp-relay.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOCKER_DHCP_RELAY_DBG = $(DOCKER_DHCP_RELAY_STEM)-$(DBG_IMAGE_MARK).gz

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

$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_COMMON) $(ISC_DHCP_RELAY) $(REDIS_TOOLS)
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(REDIS_TOOLS)
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)

Expand Down
11 changes: 4 additions & 7 deletions rules/isc-dhcp.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# isc-dhcp packages

ISC_DHCP_VERSION = 4.3.5-3.1
ISC_DHCP_VERSION = 4.3.5-2

export ISC_DHCP_VERSION

ISC_DHCP_COMMON = isc-dhcp-common_$(ISC_DHCP_VERSION)_amd64.deb
$(ISC_DHCP_COMMON)_SRC_PATH = $(SRC_PATH)/isc-dhcp
SONIC_MAKE_DEBS += $(ISC_DHCP_COMMON)

ISC_DHCP_RELAY = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb
$(eval $(call add_derived_package,$(ISC_DHCP_COMMON),$(ISC_DHCP_RELAY)))
$(ISC_DHCP_RELAY)_SRC_PATH = $(SRC_PATH)/isc-dhcp
SONIC_MAKE_DEBS += $(ISC_DHCP_RELAY)

SONIC_STRETCH_DEBS += $(ISC_DHCP_COMMON) $(ISC_DHCP_RELAY)
SONIC_STRETCH_DEBS += $(ISC_DHCP_RELAY)
7 changes: 2 additions & 5 deletions src/isc-dhcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
SHELL = /bin/bash
.SHELLFLAGS += -e

MAIN_TARGET = isc-dhcp-common_$(ISC_DHCP_VERSION)_amd64.deb
DERIVED_TARGETS = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb
MAIN_TARGET = isc-dhcp-relay_$(ISC_DHCP_VERSION)_amd64.deb

$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
# Remove any stale files
Expand All @@ -27,6 +26,4 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
popd

# Move the newly-built .deb packages to the destination directory
mv $* $(DERIVED_TARGETS) $(DEST)/

$(addprefix $(DEST)/, $(DERIVED_TARGETS)): $(DEST)/% : $(DEST)/$(MAIN_TARGET)
mv $* $(DEST)/
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 5c64cb06e3ac50a1cbca85669625fe16439064ad Mon Sep 17 00:00:00 2001
From: Joe LeVeque <[email protected]>
Date: Fri, 17 May 2019 21:49:00 +0000
Subject: [PATCH 1/3] Add --enable-use-sockets to configure flags in
debian/rules

---
debian/rules | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/debian/rules b/debian/rules
index 114606b..9919237 100755
--- a/debian/rules
+++ b/debian/rules
@@ -23,7 +23,7 @@ CFLAGS+=-D_PATH_DHCLIENT_CONF='\"/etc/dhcp/dhclient.conf\"'
CFLAGS+=-D_PATH_DHCLIENT_DB='\"$(LEASE_PATH)/dhclient.leases\"'
CFLAGS+=-D_PATH_DHCLIENT6_DB='\"$(LEASE_PATH)/dhclient6.leases\"'

-CONFFLAGS=--prefix=/usr --enable-log-pid --enable-paranoia
+CONFFLAGS=--prefix=/usr --enable-log-pid --enable-paranoia --enable-use-sockets

# cross-architecture building
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
--
2.17.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
From 6620d4778fe36c89ce2e95d6932338cefc90df7d Mon Sep 17 00:00:00 2001
From: Joe LeVeque <[email protected]>
Date: Fri, 17 May 2019 21:53:52 +0000
Subject: [PATCH 2/3] Bugfix: Ensure HAVE_SO_BINDTODEVICE has a chance to be
defined before it is referenced

---
includes/osdep.h | 239 ++++++++++++++++++++++++-----------------------
1 file changed, 120 insertions(+), 119 deletions(-)

diff --git a/includes/osdep.h b/includes/osdep.h
index cfae90b..f07c43c 100644
--- a/includes/osdep.h
+++ b/includes/osdep.h
@@ -48,37 +48,6 @@
#define BYTE_ORDER DHCP_BYTE_ORDER
#endif /* BYTE_ORDER */

-/* Porting::
-
- If you add a new network API, you must add a check for it below: */
-
-#if !defined (USE_SOCKETS) && \
- !defined (USE_SOCKET_SEND) && \
- !defined (USE_SOCKET_RECEIVE) && \
- !defined (USE_RAW_SOCKETS) && \
- !defined (USE_RAW_SEND) && \
- !defined (USE_SOCKET_RECEIVE) && \
- !defined (USE_BPF) && \
- !defined (USE_BPF_SEND) && \
- !defined (USE_BPF_RECEIVE) && \
- !defined (USE_LPF) && \
- !defined (USE_LPF_SEND) && \
- !defined (USE_LPF_RECEIVE) && \
- !defined (USE_NIT) && \
- !defined (USE_NIT_SEND) && \
- !defined (USE_NIT_RECEIVE) && \
- !defined (USE_DLPI_SEND) && \
- !defined (USE_DLPI_RECEIVE)
-/* Determine default socket API to USE. */
-# if defined(HAVE_BPF)
-# define USE_BPF 1
-# elif defined(HAVE_LPF)
-# define USE_LPF 1
-# elif defined(HAVE_DLPI)
-# define USE_DLPI 1
-# endif
-#endif
-
#if !defined (TIME_MAX)
# define TIME_MAX 2147483647
#endif
@@ -91,94 +60,6 @@
# define vsnprintf isc_print_vsnprintf
#endif

-/* Porting::
-
- If you add a new network API, and have it set up so that it can be
- used for sending or receiving, but doesn't have to be used for both,
- then set up an ifdef like the ones below: */
-
-#ifdef USE_SOCKETS
-# define USE_SOCKET_SEND
-# define USE_SOCKET_RECEIVE
-# if defined(HAVE_DLPI) && !defined(sun) && !defined(USE_V4_PKTINFO)
-# define USE_DLPI_HWADDR
-# elif defined(HAVE_LPF)
-# define USE_LPF_HWADDR
-# elif defined(HAVE_BPF)
-# define USE_BPF_HWADDR
-# endif
-#endif
-
-#ifdef USE_RAW_SOCKETS
-# define USE_RAW_SEND
-# define USE_SOCKET_RECEIVE
-#endif
-
-#ifdef USE_BPF
-# define USE_BPF_SEND
-# define USE_BPF_RECEIVE
-#endif
-
-#ifdef USE_LPF
-# define USE_LPF_SEND
-# define USE_LPF_RECEIVE
-#endif
-
-#ifdef USE_NIT
-# define USE_NIT_SEND
-# define USE_NIT_RECEIVE
-#endif
-
-#ifdef USE_DLPI
-# define USE_DLPI_SEND
-# define USE_DLPI_RECEIVE
-#endif
-
-#ifdef USE_UPF
-# define USE_UPF_SEND
-# define USE_UPF_RECEIVE
-#endif
-
-/* Porting::
-
- If you add support for sending packets directly out an interface,
- and your support does not do ARP or routing, you must use a fallback
- mechanism to deal with packets that need to be sent to routers.
- Currently, all low-level packet interfaces use BSD sockets as a
- fallback. */
-
-#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
- defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \
- defined (USE_LPF_SEND) || \
- (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE))
-# define USE_SOCKET_FALLBACK
-# define USE_FALLBACK
-#endif
-
-/* Porting::
-
- If you add support for sending packets directly out an interface
- and need to be able to assemble packets, add the USE_XXX_SEND
- definition for your interface to the list tested below. */
-
-#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
- defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
- defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
-# define PACKET_ASSEMBLY
-#endif
-
-/* Porting::
-
- If you add support for receiving packets directly from an interface
- and need to be able to decode raw packets, add the USE_XXX_RECEIVE
- definition for your interface to the list tested below. */
-
-#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
- defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
- defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE)
-# define PACKET_DECODING
-#endif
-
/* If we don't have a DLPI packet filter, we have to filter in userland.
Probably not worth doing, actually. */
#if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD)
@@ -288,4 +169,124 @@
# define STDERR_FILENO 2
#endif

+/* Porting::
+
+ If you add a new network API, you must add a check for it below: */
+
+#if !defined (USE_SOCKETS) && \
+ !defined (USE_SOCKET_SEND) && \
+ !defined (USE_SOCKET_RECEIVE) && \
+ !defined (USE_RAW_SOCKETS) && \
+ !defined (USE_RAW_SEND) && \
+ !defined (USE_SOCKET_RECEIVE) && \
+ !defined (USE_BPF) && \
+ !defined (USE_BPF_SEND) && \
+ !defined (USE_BPF_RECEIVE) && \
+ !defined (USE_LPF) && \
+ !defined (USE_LPF_SEND) && \
+ !defined (USE_LPF_RECEIVE) && \
+ !defined (USE_NIT) && \
+ !defined (USE_NIT_SEND) && \
+ !defined (USE_NIT_RECEIVE) && \
+ !defined (USE_DLPI_SEND) && \
+ !defined (USE_DLPI_RECEIVE)
+/* Determine default socket API to USE. */
+# if defined(HAVE_BPF)
+# define USE_BPF 1
+# elif defined(HAVE_LPF)
+# define USE_LPF 1
+# elif defined(HAVE_DLPI)
+# define USE_DLPI 1
+# endif
+#endif
+
+/* Porting::
+
+ If you add a new network API, and have it set up so that it can be
+ used for sending or receiving, but doesn't have to be used for both,
+ then set up an ifdef like the ones below: */
+
+#ifdef USE_SOCKETS
+# define USE_SOCKET_SEND
+# define USE_SOCKET_RECEIVE
+# if defined(HAVE_DLPI) && !defined(sun) && !defined(USE_V4_PKTINFO)
+# define USE_DLPI_HWADDR
+# elif defined(HAVE_LPF)
+# define USE_LPF_HWADDR
+# elif defined(HAVE_BPF)
+# define USE_BPF_HWADDR
+# endif
+#endif
+
+#ifdef USE_RAW_SOCKETS
+# define USE_RAW_SEND
+# define USE_SOCKET_RECEIVE
+#endif
+
+#ifdef USE_BPF
+# define USE_BPF_SEND
+# define USE_BPF_RECEIVE
+#endif
+
+#ifdef USE_LPF
+# define USE_LPF_SEND
+# define USE_LPF_RECEIVE
+#endif
+
+#ifdef USE_NIT
+# define USE_NIT_SEND
+# define USE_NIT_RECEIVE
+#endif
+
+#ifdef USE_DLPI
+# define USE_DLPI_SEND
+# define USE_DLPI_RECEIVE
+#endif
+
+#ifdef USE_UPF
+# define USE_UPF_SEND
+# define USE_UPF_RECEIVE
+#endif
+
+/* Porting::
+
+ If you add support for sending packets directly out an interface,
+ and your support does not do ARP or routing, you must use a fallback
+ mechanism to deal with packets that need to be sent to routers.
+ Currently, all low-level packet interfaces use BSD sockets as a
+ fallback. */
+
+#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
+ defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \
+ defined (USE_LPF_SEND) || \
+ (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE))
+# define USE_SOCKET_FALLBACK
+# define USE_FALLBACK
+#endif
+
+/* Porting::
+
+ If you add support for sending packets directly out an interface
+ and need to be able to assemble packets, add the USE_XXX_SEND
+ definition for your interface to the list tested below. */
+
+#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
+ defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
+ defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
+# define PACKET_ASSEMBLY
+#endif
+
+/* Porting::
+
+ If you add support for receiving packets directly from an interface
+ and need to be able to decode raw packets, add the USE_XXX_RECEIVE
+ definition for your interface to the list tested below. */
+
+#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
+ defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
+ defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE)
+# define PACKET_DECODING
+#endif
+
+
#endif /* __ISC_DHCP_OSDEP_H__ */
--
2.17.1

Loading

0 comments on commit 552684f

Please sign in to comment.