Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ target/
*.buildinfo

# Subdirectories in src
src/dhcpmon/debian/*
!src/dhcpmon/debian/changelog
!src/dhcpmon/debian/compat
!src/dhcpmon/debian/control
!src/dhcpmon/debian/rules
src/hiredis/*
!src/hiredis/Makefile
src/igb/*
Expand Down
48 changes: 48 additions & 0 deletions dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,53 @@ stderr_logfile=syslog

{% endif %}
{% endfor %}

[group:dhcpmon]
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}) %}
dhcpmon-{{ vlan_name }}
{%- endif %}
{% endfor %}


{# Create a program entry for each DHCP MONitor instance #}
{% set relay_for_ipv4 = { 'flag': False } %}
{% for vlan_name in VLAN %}
{% if VLAN[vlan_name]['dhcp_servers'] %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% if relay_for_ipv4.flag %}
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
[program:dhcpmon-{{ vlan_name }}]
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
command=/usr/sbin/dhcpmon -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 %}

priority=4
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

{% endif %}
{% endif %}
{% endfor %}

{% endif %}
{% endif %}
6 changes: 6 additions & 0 deletions dockers/docker-dhcp-relay/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ if [ $(supervisorctl status | grep -c "^isc-dhcp-relay:") -gt 0 ]; then
# Start all DHCP relay agent(s)
supervisorctl start isc-dhcp-relay:*
fi

# If our supervisor config has entries in the "dhcpmon" group...
if [ $(supervisorctl status | grep -c "^dhcpmon:") -gt 0 ]; then
# Start all DHCP Monitor daemon(s)
supervisorctl start dhcpmon:*
fi
8 changes: 8 additions & 0 deletions rules/dhcpmon.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SONiC DHCP MONitor package

SONIC_DHCPMON_VERSION = 1.0.0-0
SONIC_DHCPMON_PKG_NAME = dhcpmon

SONIC_DHCPMON = sonic-$(SONIC_DHCPMON_PKG_NAME)_$(SONIC_DHCPMON_VERSION)_amd64.deb
$(SONIC_DHCPMON)_SRC_PATH = $(SRC_PATH)/$(SONIC_DHCPMON_PKG_NAME)
SONIC_DPKG_DEBS += $(SONIC_DHCPMON)
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

$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_COMMON) $(ISC_DHCP_RELAY) $(REDIS_TOOLS)
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_COMMON) $(ISC_DHCP_RELAY) $(REDIS_TOOLS) $(SONIC_DHCPMON)
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE)_DBG_DEPENDS)
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_DBG)
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE)_DBG_IMAGE_PACKAGES)
Expand Down
4 changes: 3 additions & 1 deletion sonic-slave/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ RUN apt-get update && apt-get install -y \
# For sonic vs image build
dosfstools \
qemu-kvm \
libvirt-bin
libvirt-bin \
# For DHCP Monitor tool
libevent-dev

# For linux build
RUN apt-get -y build-dep linux
Expand Down
44 changes: 44 additions & 0 deletions src/dhcpmon/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
RM := rm -rf
DHCPMON_TARGET := dhcpmon
CP := cp
MKDIR := mkdir
CC := gcc
MV := mv

# All of the sources participating in the build are defined here
-include src/subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

# Add inputs and outputs from these tool invocations to the build variables

# All Target
all: sonic-dhcpmon

# Tool invocations
sonic-dhcpmon: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
$(CC) -o "$(DHCPMON_TARGET)" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '

# Other Targets
install:
$(MKDIR) -p $(DESTDIR)/usr/sbin
$(MV) $(DHCPMON_TARGET) $(DESTDIR)/usr/sbin

deinstall:
$(RM) $(DESTDIR)/usr/sbin/$(DHCPMON_TARGET)
$(RM) -rf $(DESTDIR)/usr/sbin

clean:
-$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) $(DHCPMON_TARGET)
-@echo ' '

.PHONY: all clean dependents
5 changes: 5 additions & 0 deletions src/dhcpmon/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sonic-dhcpmon (1.0.0-0) UNRELEASED; urgency=medium

* Initial release.

-- Tamer Ahmed <[email protected]> Mon, 09 Dec 2019 12:00:00 -0700
1 change: 1 addition & 0 deletions src/dhcpmon/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
15 changes: 15 additions & 0 deletions src/dhcpmon/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: sonic-dhcpmon
Section: devel
Priority: optional
Maintainer: Tamer Ahmed <[email protected]>
Build-Depends: debhelper (>= 8.0.0),
dh-systemd
Standards-Version: 3.9.3
Homepage: https://github.com/Azure/sonic-buildimage
XS-Go-Import-Path: github.com/Azure/sonic-buildimage

Package: sonic-dhcpmon
Architecture: any
Built-Using: ${misc:Built-Using}
Depends: libevent-2.0-5
Description: SONiC DHCP Monitor
3 changes: 3 additions & 0 deletions src/dhcpmon/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/make -f
%:
dh $@ --with systemd
4 changes: 4 additions & 0 deletions src/dhcpmon/objects.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USER_OBJS :=

LIBS := -levent

Loading