Skip to content

Commit b906861

Browse files
author
Juha Heiskanen
committed
Fixed DHCP relay bugs
1 parent d74d5ff commit b906861

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

source/DHCPv6_client/dhcpv6_client_service.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "ns_list.h"
2424
#include "common_functions.h"
2525

26-
26+
#ifdef HAVE_DHCPV6
2727
#include "dhcp_service_api.h"
2828
#include "dhcpv6_client_api.h"
2929
#include "libDHCPv6/libDHCPv6.h"
@@ -335,3 +335,5 @@ void dhcpv6_client_set_address(int8_t interface_id, dhcpv6_client_server_data_t
335335
address_entry->state_timer = renewTimer;
336336
address_entry->cb = dhcpv6_renew;
337337
}
338+
339+
#endif

source/libDHCPv6/dhcp_service_api.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ void recv_dhcp_server_msg(void *cb_res)
316316
memcpy(msg_tr_ptr->addr.address,relay_msg.peer_address , 16);
317317
msg_ptr = relay_msg.relay_options.msg_ptr;
318318
msg_len = relay_msg.relay_options.len;
319+
msg_type = *msg_ptr;
319320

320321

321322
} else if (msg_type == DHCPV6_RELAY_REPLY) {
@@ -383,7 +384,7 @@ void recv_dhcp_relay_msg(void *cb_res)
383384
msg_iov[0].iov_len = 34;
384385
msg_iov[1].iov_base = ns_dyn_mem_temporary_alloc(sckt_data->d_len);
385386
msg_iov[1].iov_len = sckt_data->d_len;
386-
if (msg_iov[2].iov_base == NULL ) {
387+
if (msg_iov[1].iov_base == NULL ) {
387388
// read actual message
388389
tr_error("Out of resources");
389390
goto cleanup;
@@ -426,7 +427,7 @@ void recv_dhcp_relay_msg(void *cb_res)
426427
//Copy DST address
427428
memcpy(src_address.address, relay_msg.peer_address, 16);
428429
src_address.type = ADDRESS_IPV6;
429-
src_address.identifier = DHCPV6_SERVER_PORT;
430+
src_address.identifier = DHCPV6_CLIENT_PORT;
430431
msghdr.msg_iov = &msg_iov[0];
431432
msghdr.msg_iovlen = 1;
432433
msg_iov[0].iov_base = relay_msg.relay_options.msg_ptr;
@@ -545,7 +546,7 @@ uint16_t dhcp_service_init(int8_t interface_id, dhcp_instance_type_e instance_ty
545546
if (dhcp_service->dhcp_server_socket >= 0) {
546547
tr_error("dhcp Relay agent can't open because server open already");
547548
}
548-
dhcp_service->dhcp_relay_socket = socket_open(SOCKET_UDP, DHCPV6_SERVER_PORT, recv_dhcp_server_msg);
549+
dhcp_service->dhcp_relay_socket = socket_open(SOCKET_UDP, DHCPV6_SERVER_PORT, recv_dhcp_relay_msg);
549550
}
550551

551552
if (instance_type == DHCP_INSTANCE_CLIENT && dhcp_service->dhcp_client_socket < 0) {
@@ -654,7 +655,7 @@ void dhcp_service_delete(uint16_t instance)
654655
}
655656
}
656657

657-
if ((server_instances == 0 || relay_instances == 0) && dhcp_service->dhcp_server_socket > -1) {
658+
if ((server_instances == 0 && relay_instances == 0) && dhcp_service->dhcp_server_socket > -1) {
658659
socket_close(dhcp_service->dhcp_server_socket);
659660
dhcp_service->dhcp_server_socket = -1;
660661
}

source/libDHCPv6/libDHCPv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ bool libdhcpv6_relay_msg_read(uint8_t *ptr, uint16_t length, dhcpv6_relay_msg_t
826826
relay_msg->peer_address = ptr + 16;
827827
ptr += 32;
828828
//Discover
829-
if (libdhcpv6_message_option_discover(ptr, length - 34, DHCPV6_OPTION_RELAY, &relay_msg->relay_options) <= 0) {
829+
if (libdhcpv6_message_option_discover(ptr, length - 34, DHCPV6_OPTION_RELAY, &relay_msg->relay_options) != 0) {
830830
return false;
831831
}
832832

0 commit comments

Comments
 (0)