@@ -121,8 +121,6 @@ static struct sock_fprog dhcp_sock_bfp = {
121
121
*/
122
122
static dhcp_device_context_t aggregate_dev = {0 };
123
123
124
- static dhcp_device_context_t * mgmt_intf = NULL ;
125
-
126
124
/** Monitored DHCPv4 message type */
127
125
static dhcpv4_message_type_t v4_monitored_msgs [] = {
128
126
DHCPv4_MESSAGE_TYPE_DISCOVER ,
@@ -178,11 +176,6 @@ static void handle_dhcp_option_53(dhcp_device_context_t *context,
178
176
if ((context -> giaddr_ip == giaddr && context -> is_uplink && dir == DHCP_TX ) ||
179
177
(!context -> is_uplink && dir == DHCP_RX && iphdr -> ip_dst .s_addr == INADDR_BROADCAST )) {
180
178
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
- }
186
179
aggregate_dev .counters .v4counters [DHCP_COUNTERS_CURRENT ][dir ][dhcp_option [2 ]]++ ;
187
180
}
188
181
break ;
@@ -193,11 +186,6 @@ static void handle_dhcp_option_53(dhcp_device_context_t *context,
193
186
if ((context -> giaddr_ip == iphdr -> ip_dst .s_addr && context -> is_uplink && dir == DHCP_RX ) ||
194
187
(!context -> is_uplink && dir == DHCP_TX )) {
195
188
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
- }
201
189
aggregate_dev .counters .v4counters [DHCP_COUNTERS_CURRENT ][dir ][dhcp_option [2 ]]++ ;
202
190
}
203
191
break ;
@@ -236,11 +224,6 @@ static void handle_dhcpv6_option(dhcp_device_context_t *context,
236
224
case DHCPv6_MESSAGE_TYPE_RECONFIGURE :
237
225
case DHCPv6_MESSAGE_TYPE_INFORMATION_REQUEST :
238
226
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
- }
244
227
aggregate_dev .counters .v6counters [DHCP_COUNTERS_CURRENT ][dir ][dhcp_option ]++ ;
245
228
break ;
246
229
default :
@@ -326,7 +309,7 @@ static void read_callback(int fd, short event, void *arg)
326
309
}
327
310
}
328
311
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 ;
330
313
dhcp_packet_direction_t dir = (ethhdr -> ether_shost [0 ] == context -> mac [0 ] &&
331
314
ethhdr -> ether_shost [1 ] == context -> mac [1 ] &&
332
315
ethhdr -> ether_shost [2 ] == context -> mac [2 ] &&
@@ -336,25 +319,23 @@ static void read_callback(int fd, short event, void *arg)
336
319
DHCP_TX : DHCP_RX ;
337
320
int offset = 0 ;
338
321
uint16_t option = 0 ;
339
- uint16_t current_option_len = 0 ;
340
322
// 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 )
342
324
{
343
325
// Get to DHCPv6_OPTION_RELAY_MSG from all options
344
326
offset += DHCPv6_RELAY_MSG_OPTIONS_OFFSET ;
345
- option = htons (* ((uint16_t * )(& (dhcp_header [offset ]))));
327
+ option = htons (* ((uint16_t * )(& (dhcp_option [offset ]))));
346
328
347
329
while (option != DHCPv6_OPTION_RELAY_MSG )
348
330
{
331
+ offset += DHCPv6_OPTION_LENGTH ;
349
332
// 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 ]))));
353
335
}
354
- // Set the offset to DHCP-relay-message data
355
336
offset += DHCPv6_OPTION_LENGTH + DHCPv6_OPTION_LEN_LENGTH ;
356
337
}
357
- handle_dhcpv6_option (context , dhcp_header [offset ], dir );
338
+ handle_dhcpv6_option (context , dhcp_option [offset ], dir );
358
339
} else {
359
340
syslog (LOG_WARNING , "read_callback(%s): read length (%ld) is too small to capture DHCP options" ,
360
341
context -> intf , buffer_sz );
@@ -573,7 +554,7 @@ static dhcp_mon_status_t dhcp_device_check_health(dhcp_mon_check_t check_type,
573
554
{
574
555
dhcp_mon_status_t rv = DHCP_MON_STATUS_HEALTHY ;
575
556
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 )) {
577
558
rv = DHCP_MON_STATUS_INDETERMINATE ;
578
559
} else if (check_type == DHCP_MON_CHECK_POSITIVE ) {
579
560
rv = dhcp_device_check_positive_health (v4counters , v6counters , type );
@@ -967,13 +948,3 @@ void dhcp_device_active_types(bool dhcpv4, bool dhcpv6)
967
948
dhcpv4_enabled = dhcpv4 ;
968
949
dhcpv6_enabled = dhcpv6 ;
969
950
}
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
- }
0 commit comments