From a4b15d8ba429c2799d3927f8dca376745af08c1a Mon Sep 17 00:00:00 2001 From: jcaiMR <111116206+jcaiMR@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:18:28 +0800 Subject: [PATCH] fix relay-reply dhcpv6 packet counter issue (#29) fix Advertise packets counted as Unknown --- src/relay.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/relay.cpp b/src/relay.cpp index 2b71399..64390a9 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -567,9 +567,6 @@ void relay_relay_forw(int sock, const uint8_t *msg, int32_t len, const ip6_hdr * auto dhcp_relay_header = parse_dhcpv6_relay(msg); current_position += sizeof(struct dhcpv6_relay_msg); - auto position = current_position + sizeof(struct dhcpv6_option); - auto dhcpv6msg = parse_dhcpv6_hdr(position); - while ((current_position - msg) < len) { auto option = parse_dhcpv6_opt(current_position, &tmp); current_position = tmp; @@ -577,11 +574,13 @@ void relay_relay_forw(int sock, const uint8_t *msg, int32_t len, const ip6_hdr * break; } switch (ntohs(option->option_code)) { - case OPTION_RELAY_MSG: - memcpy(current_buffer_position, ((uint8_t *)option) + sizeof(struct dhcpv6_option), ntohs(option->option_length)); + case OPTION_RELAY_MSG: { + uint8_t *dhcpv6_position = ((uint8_t *)option) + sizeof(struct dhcpv6_option); + type = parse_dhcpv6_hdr(dhcpv6_position)->msg_type; + memcpy(current_buffer_position, dhcpv6_position, ntohs(option->option_length)); current_buffer_position += ntohs(option->option_length); - type = dhcpv6msg->msg_type; break; + } default: break; }