Skip to content

Commit cff540f

Browse files
committed
Revert "Fix dhcpmon bugs (sonic-net#9008)"
This reverts commit 14aca81.
1 parent 5c7aa50 commit cff540f

File tree

3 files changed

+8
-51
lines changed

3 files changed

+8
-51
lines changed

src/dhcpmon/src/dhcp_device.c

+8-37
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ static struct sock_fprog dhcp_sock_bfp = {
121121
*/
122122
static dhcp_device_context_t aggregate_dev = {0};
123123

124-
static dhcp_device_context_t *mgmt_intf = NULL;
125-
126124
/** Monitored DHCPv4 message type */
127125
static dhcpv4_message_type_t v4_monitored_msgs[] = {
128126
DHCPv4_MESSAGE_TYPE_DISCOVER,
@@ -178,11 +176,6 @@ static void handle_dhcp_option_53(dhcp_device_context_t *context,
178176
if ((context->giaddr_ip == giaddr && context->is_uplink && dir == DHCP_TX) ||
179177
(!context->is_uplink && dir == DHCP_RX && iphdr->ip_dst.s_addr == INADDR_BROADCAST)) {
180178
context->counters.v4counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option[2]]++;
181-
// If the packet recieved on the mgmt interface, we don't want to increment the aggregate device
182-
if (context == mgmt_intf)
183-
{
184-
break;
185-
}
186179
aggregate_dev.counters.v4counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option[2]]++;
187180
}
188181
break;
@@ -193,11 +186,6 @@ static void handle_dhcp_option_53(dhcp_device_context_t *context,
193186
if ((context->giaddr_ip == iphdr->ip_dst.s_addr && context->is_uplink && dir == DHCP_RX) ||
194187
(!context->is_uplink && dir == DHCP_TX)) {
195188
context->counters.v4counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option[2]]++;
196-
// If the packet recieved on the mgmt interface, we don't want to increment the aggregate device
197-
if (context == mgmt_intf)
198-
{
199-
break;
200-
}
201189
aggregate_dev.counters.v4counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option[2]]++;
202190
}
203191
break;
@@ -236,11 +224,6 @@ static void handle_dhcpv6_option(dhcp_device_context_t *context,
236224
case DHCPv6_MESSAGE_TYPE_RECONFIGURE:
237225
case DHCPv6_MESSAGE_TYPE_INFORMATION_REQUEST:
238226
context->counters.v6counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option]++;
239-
// If the packet recieved on the mgmt interface, we don't want to increment the aggregate device
240-
if (context == mgmt_intf)
241-
{
242-
break;
243-
}
244227
aggregate_dev.counters.v6counters[DHCP_COUNTERS_CURRENT][dir][dhcp_option]++;
245228
break;
246229
default:
@@ -326,7 +309,7 @@ static void read_callback(int fd, short event, void *arg)
326309
}
327310
}
328311
else if (!is_ipv4 && dhcpv6_enabled && (buffer_sz > UDPv6_START_OFFSET + sizeof(struct udphdr) + DHCPv6_TYPE_LENGTH)) {
329-
const u_char* dhcp_header = context->buffer + dhcp_option_offset;
312+
const u_char* dhcp_option = context->buffer + dhcp_option_offset;
330313
dhcp_packet_direction_t dir = (ethhdr->ether_shost[0] == context->mac[0] &&
331314
ethhdr->ether_shost[1] == context->mac[1] &&
332315
ethhdr->ether_shost[2] == context->mac[2] &&
@@ -336,25 +319,23 @@ static void read_callback(int fd, short event, void *arg)
336319
DHCP_TX : DHCP_RX;
337320
int offset = 0;
338321
uint16_t option = 0;
339-
uint16_t current_option_len = 0;
340322
// Get to inner DHCP header from encapsulated RELAY_FORWARD or RELAY_REPLY header
341-
while (dhcp_header[offset] == DHCPv6_MESSAGE_TYPE_RELAY_FORWARD || dhcp_header[offset] == DHCPv6_MESSAGE_TYPE_RELAY_REPLY)
323+
while (dhcp_option[offset] == DHCPv6_MESSAGE_TYPE_RELAY_FORWARD || dhcp_option[offset] == DHCPv6_MESSAGE_TYPE_RELAY_REPLY)
342324
{
343325
// Get to DHCPv6_OPTION_RELAY_MSG from all options
344326
offset += DHCPv6_RELAY_MSG_OPTIONS_OFFSET;
345-
option = htons(*((uint16_t*)(&(dhcp_header[offset]))));
327+
option = htons(*((uint16_t*)(&(dhcp_option[offset]))));
346328

347329
while (option != DHCPv6_OPTION_RELAY_MSG)
348330
{
331+
offset += DHCPv6_OPTION_LENGTH;
349332
// Add to offset the option length and get the next option ID
350-
current_option_len = htons(*((uint16_t*)(&(dhcp_header[offset + DHCPv6_OPTION_LENGTH]))));
351-
offset += DHCPv6_OPTION_LENGTH + DHCPv6_OPTION_LEN_LENGTH + current_option_len;
352-
option = htons(*((uint16_t*)(&(dhcp_header[offset]))));
333+
offset += htons(*((uint16_t*)(&(dhcp_option[offset]))));
334+
option = htons(*((uint16_t*)(&(dhcp_option[offset]))));
353335
}
354-
// Set the offset to DHCP-relay-message data
355336
offset += DHCPv6_OPTION_LENGTH + DHCPv6_OPTION_LEN_LENGTH;
356337
}
357-
handle_dhcpv6_option(context, dhcp_header[offset], dir);
338+
handle_dhcpv6_option(context, dhcp_option[offset], dir);
358339
} else {
359340
syslog(LOG_WARNING, "read_callback(%s): read length (%ld) is too small to capture DHCP options",
360341
context->intf, buffer_sz);
@@ -573,7 +554,7 @@ static dhcp_mon_status_t dhcp_device_check_health(dhcp_mon_check_t check_type,
573554
{
574555
dhcp_mon_status_t rv = DHCP_MON_STATUS_HEALTHY;
575556

576-
if (dhcp_device_is_dhcp_inactive(v4counters, v6counters, type)) {
557+
if (dhcp_device_is_dhcp_inactive(aggregate_dev.counters.v4counters, aggregate_dev.counters.v6counters, type)) {
577558
rv = DHCP_MON_STATUS_INDETERMINATE;
578559
} else if (check_type == DHCP_MON_CHECK_POSITIVE) {
579560
rv = dhcp_device_check_positive_health(v4counters, v6counters, type);
@@ -967,13 +948,3 @@ void dhcp_device_active_types(bool dhcpv4, bool dhcpv6)
967948
dhcpv4_enabled = dhcpv4;
968949
dhcpv6_enabled = dhcpv6;
969950
}
970-
971-
/**
972-
* @code dhcp_device_init_mgmt_intf(mgmt_intf_context);
973-
*
974-
* @brief assign context address of mgmt interface
975-
*/
976-
void dhcp_device_init_mgmt_intf(dhcp_device_context_t *mgmt_intf_context)
977-
{
978-
mgmt_intf = mgmt_intf_context;
979-
}

src/dhcpmon/src/dhcp_device.h

-11
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,4 @@ void dhcp_device_print_status(dhcp_device_context_t *context, dhcp_counters_type
255255
* @return none
256256
*/
257257
void dhcp_device_active_types(bool dhcpv4, bool dhcpv6);
258-
259-
/**
260-
* @code dhcp_device_init_mgmt_intf(mgmt_intf_context);
261-
*
262-
* @brief assign context address of mgmt interface
263-
*
264-
* @param mgmt_intf_context MGMT interface context struct address
265-
*
266-
* @return none
267-
*/
268-
void dhcp_device_init_mgmt_intf(dhcp_device_context_t *mgmt_intf_context);
269258
#endif /* DHCP_DEVICE_H_ */

src/dhcpmon/src/dhcp_devman.c

-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ int dhcp_devman_add_intf(const char *name, char intf_type)
148148
strncpy(agg_dev->intf + sizeof(AGG_DEV_PREFIX) - 1, name, sizeof(agg_dev->intf) - sizeof(AGG_DEV_PREFIX));
149149
agg_dev->intf[sizeof(agg_dev->intf) - 1] = '\0';
150150
}
151-
else if (rv == 0 && intf_type == 'm') {
152-
dhcp_device_init_mgmt_intf(dev->dev_context);
153-
}
154151

155152
LIST_INSERT_HEAD(&intfs, dev, entry);
156153
}

0 commit comments

Comments
 (0)