Skip to content

Commit

Permalink
Add dhcpv6 option check
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyyeh committed Apr 6, 2022
1 parent 5c7aa50 commit d719413
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/dhcp6relay/src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,21 +609,44 @@ void callback(evutil_socket_t fd, short event, void *arg) {
current_position = tmp;

auto msg = parse_dhcpv6_hdr(current_position);
auto option_position = current_position + sizeof(struct dhcpv6_msg);

counters[msg->msg_type]++;
std::string counterVlan = counter_table;
update_counter(config->db, counterVlan.append(config->interface), msg->msg_type);

if(msg->msg_type != DHCPv6_MESSAGE_TYPE_RELAY_FORW) {
while (option_position - message_buffer < len) {
auto option = parse_dhcpv6_opt(option_position, &tmp);
option_position = tmp;
if(ntohs(option->option_code) > 56) { // DHCPv6 option code greater than 56 are currently unassigned
syslog(LOG_INFO, "DHCPv6 option is invalid or contains malformed payload\n");
return;
}
}
}

switch (msg->msg_type) {
case DHCPv6_MESSAGE_TYPE_RELAY_FORW:
{
relay_relay_forw(config->local_sock, current_position, ntohs(udp_header->len) - sizeof(udphdr), ip_header, config);
break;
}
default:
case DHCPv6_MESSAGE_TYPE_SOLICIT:
case DHCPv6_MESSAGE_TYPE_REQUEST:
case DHCPv6_MESSAGE_TYPE_RENEW:
case DHCPv6_MESSAGE_TYPE_REBIND:
case DHCPv6_MESSAGE_TYPE_RELEASE:
case DHCPv6_MESSAGE_TYPE_DECLINE:
{
relay_client(config->local_sock, current_position, ntohs(udp_header->len) - sizeof(udphdr), ip_header, ether_header, config);
break;
}
default:
{
syslog(LOG_INFO, "DHCPv6 client message received was not relayed\n");
break;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/dhcp6relay/src/relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct relay_config {

struct dhcpv6_msg {
uint8_t msg_type;
uint8_t xid[3];
};

struct PACKED dhcpv6_relay_msg {
Expand Down

0 comments on commit d719413

Please sign in to comment.