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