mirror of
https://gitlab.com/chrony/chrony.git
synced 2026-01-20 21:00:20 -05:00
ntp: pass SCK_Message to extract_udp_data()
Modify the message length directly in extract_udp_data() to make the caller's code more clear.
This commit is contained in:
@@ -634,12 +634,11 @@ process_sw_timestamp(struct timespec *sw_ts, NTP_Local_Timestamp *local_ts)
|
|||||||
with optional VLAN tags. */
|
with optional VLAN tags. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_udp_data(unsigned char *msg, NTP_Remote_Address *remote_addr, int len)
|
extract_udp_data(SCK_Message *message)
|
||||||
{
|
{
|
||||||
unsigned char *msg_start = msg;
|
NTP_Remote_Address *remote_addr = &message->remote_addr.ip;
|
||||||
|
unsigned char *msg = message->data;
|
||||||
remote_addr->ip_addr.family = IPADDR_UNSPEC;
|
int len = message->length;
|
||||||
remote_addr->port = 0;
|
|
||||||
|
|
||||||
/* Skip MACs */
|
/* Skip MACs */
|
||||||
if (len < 12)
|
if (len < 12)
|
||||||
@@ -715,9 +714,11 @@ extract_udp_data(unsigned char *msg, NTP_Remote_Address *remote_addr, int len)
|
|||||||
|
|
||||||
/* Move the message to fix alignment of its fields */
|
/* Move the message to fix alignment of its fields */
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
memmove(msg_start, msg, len);
|
memmove(message->data, msg, len);
|
||||||
|
|
||||||
return len;
|
message->length = len;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -769,11 +770,15 @@ NIO_Linux_ProcessMessage(SCK_Message *message, NTP_Local_Address *local_addr,
|
|||||||
extract the UDP data and also the destination address with port as there
|
extract the UDP data and also the destination address with port as there
|
||||||
currently doesn't seem to be a better way to get them both. */
|
currently doesn't seem to be a better way to get them both. */
|
||||||
l2_length = message->length;
|
l2_length = message->length;
|
||||||
message->length = extract_udp_data(message->data, &message->remote_addr.ip, message->length);
|
|
||||||
|
|
||||||
DEBUG_LOG("Extracted message for %s fd=%d len=%d",
|
if (extract_udp_data(message)) {
|
||||||
UTI_IPSockAddrToString(&message->remote_addr.ip),
|
DEBUG_LOG("Extracted message for %s fd=%d len=%d",
|
||||||
local_addr->sock_fd, message->length);
|
UTI_IPSockAddrToString(&message->remote_addr.ip),
|
||||||
|
local_addr->sock_fd, message->length);
|
||||||
|
} else {
|
||||||
|
DEBUG_LOG("Could not extract message");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Update assumed position of UDP data at layer 2 for next received packet */
|
/* Update assumed position of UDP data at layer 2 for next received packet */
|
||||||
if (iface && message->length) {
|
if (iface && message->length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user