Skip to content

Commit

Permalink
Add dhcpmon rule dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jul 11, 2022
1 parent 667f668 commit 1bccfe6
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 24 deletions.
1 change: 1 addition & 0 deletions rules/dhcpmon.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SONIC_DHCPMON_VERSION = 1.0.0-0
SONIC_DHCPMON_PKG_NAME = dhcpmon

SONIC_DHCPMON = sonic-$(SONIC_DHCPMON_PKG_NAME)_$(SONIC_DHCPMON_VERSION)_$(CONFIGURED_ARCH).deb
$(SONIC_DHCPMON)_DEPENDS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV)
$(SONIC_DHCPMON)_SRC_PATH = $(SRC_PATH)/$(SONIC_DHCPMON_PKG_NAME)
SONIC_DPKG_DEBS += $(SONIC_DHCPMON)

Expand Down
2 changes: 1 addition & 1 deletion src/dhcpmon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all: sonic-dhcpmon
# Tool invocations
sonic-dhcpmon: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
@echo 'Invoking: G++ C Linker'
$(CC) -o "$(DHCPMON_TARGET)" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
Expand Down
2 changes: 1 addition & 1 deletion src/dhcpmon/objects.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USER_OBJS :=

LIBS := -levent -lexplain -lswsscommon -pthread -lboost_thread -lboost_system
LIBS := -levent -lexplain -lswsscommon -pthread -lboost_thread -lboost_system -lhiredis

15 changes: 4 additions & 11 deletions src/dhcpmon/src/dhcp_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <netpacket/packet.h>
#include "subscriberstatetable.h"
#include "select.h"
#include <iostream>

#include "dhcp_device.h"

Expand Down Expand Up @@ -56,7 +55,6 @@ constexpr auto DEFAULT_TIMEOUT_MSEC = 1000;
swss::Select swssSelect;
std::shared_ptr<swss::DBConnector> stateDbPtr = std::make_shared<swss::DBConnector> ("STATE_DB", 0);
swss::SubscriberStateTable muxTable(stateDbPtr.get(), "HW_MUX_CABLE_TABLE");

swss::DBConnector configDb("CONFIG_DB", 0);

/** Berkeley Packet Filter program for "udp and (port 67 or port 68)".
Expand Down Expand Up @@ -253,13 +251,14 @@ static void read_callback_dual_tor(int fd, short event, void *arg)

bool standby = false;
swss::Selectable *selectable;
swssSelect.addSelectable(&muxTable);
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
if (ret == swss::Select::ERROR) {
syslog(LOG_WARNING, "Select: returned ERROR");
}

while ((event == EV_READ) &&
((buffer_sz = recvfrom(fd, context->buffer, context->snaplen, MSG_DONTWAIT, (struct sockaddr *)&sll, &slen) > 0))) {
((buffer_sz = recvfrom(fd, context->buffer, context->snaplen, MSG_DONTWAIT, (struct sockaddr *)&sll, &slen)) > 0)) {
std::string member_table = std::string("VLAN_MEMBER|") + context->intf + "|";
char interfaceName;
char *interface = if_indextoname(sll.sll_ifindex, &interfaceName);
Expand All @@ -268,14 +267,14 @@ static void read_callback_dual_tor(int fd, short event, void *arg)
std::deque<swss::KeyOpFieldsValuesTuple> entries;
muxTable.pops(entries);
for (auto &entry: entries) {
std::string vlan = kfvKey(entry);
std::string intf_key = kfvKey(entry);
std::string operation = kfvOp(entry);
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);

for (auto &fieldValue: fieldValues) {
std::string f = fvField(fieldValue);
std::string v = fvValue(fieldValue);
if(f == "state" && v == "standby") {
if(intf_key == interface && f == "state" && v == "standby") {
standby = true;
break;
}
Expand Down Expand Up @@ -695,12 +694,6 @@ int dhcp_device_start_capture(dhcp_device_context_t *context,
break;
}

int enable = 1;
if (setsockopt(context->sock, SOL_SOCKET, IP_PKTINFO, &enable, sizeof(int)) != 0) {
syslog(LOG_ALERT, "setsockopt: failed to set IP_PKTINFO with '%s'\n", strerror(errno));
break;
}

if (dual_tor_sock)
ev = event_new(base, context->sock, EV_READ | EV_PERSIST, read_callback_dual_tor, context);
else
Expand Down
1 change: 0 additions & 1 deletion src/dhcpmon/src/dhcp_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ typedef struct
uint8_t is_uplink; /** north interface? */
char intf[IF_NAMESIZE]; /** device (interface) name */
uint8_t *buffer; /** buffer used to read socket data */
struct msghdr msg;
size_t snaplen; /** snap length or buffer size */
uint64_t counters[DHCP_COUNTERS_COUNT][DHCP_DIR_COUNT][DHCP_MESSAGE_TYPE_COUNT];
/** current/snapshot counters of DHCP packets */
Expand Down
9 changes: 2 additions & 7 deletions src/dhcpmon/src/dhcp_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ typedef struct
} dhcp_mon_state_t;

/** window_interval_sec monitoring window for dhcp relay health checks */
static int window_interval_sec = 5;
static int window_interval_sec = 18;
/** dhcp_unhealthy_max_count max count of consecutive unhealthy statuses before reporting to syslog */
static int dhcp_unhealthy_max_count = 1;
static int dhcp_unhealthy_max_count = 10;
/** libevent base struct */
static struct event_base *base;
/** libevent timeout event struct */
Expand Down Expand Up @@ -102,13 +102,8 @@ static void check_dhcp_relay_health(dhcp_mon_state_t *state_data)
break;
case DHCP_MON_STATUS_HEALTHY:
state_data->count = 0;
syslog(LOG_ALERT, state_data->msg, state_data->count * window_interval_sec, context->intf);
dhcp_devman_print_status(context, DHCP_COUNTERS_SNAPSHOT);
dhcp_devman_print_status(context, DHCP_COUNTERS_CURRENT);
break;
case DHCP_MON_STATUS_INDETERMINATE:
dhcp_devman_print_status(context, DHCP_COUNTERS_SNAPSHOT);
dhcp_devman_print_status(context, DHCP_COUNTERS_CURRENT);
if (state_data->count) {
state_data->count++;
}
Expand Down
3 changes: 2 additions & 1 deletion src/dhcpmon/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static const uint32_t dhcpmon_default_health_check_window = 18;
* with DHCP relay */
static const uint32_t dhcpmon_default_unhealthy_max_count = 10;

bool dual_tor_sock = false;

/**
* @code usage(prog);
*
Expand Down Expand Up @@ -115,7 +117,6 @@ int main(int argc, char **argv)
int max_unhealthy_count = dhcpmon_default_unhealthy_max_count;
size_t snaplen = dhcpmon_default_snaplen;
int make_daemon = 0;
int dual_tor_sock = false;

setlogmask(LOG_UPTO(LOG_INFO));
openlog(basename(argv[0]), LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON);
Expand Down
4 changes: 2 additions & 2 deletions src/dhcpmon/src/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ C_DEPS += \


# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.cpp
src/%.o: src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
$(CC) -O3 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
$(CC) -O3 -g3 -Wall -I$(PWD)/../sonic-swss-common/common -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '

0 comments on commit 1bccfe6

Please sign in to comment.