Line 0
Link Here
|
|
|
1 |
From 6af39d63aa9323b4b8c39efe24ae0c88c949a901 Mon Sep 17 00:00:00 2001 |
2 |
From: Miroslav Lichvar <mlichvar@redhat.com> |
3 |
Date: Mon, 3 Dec 2018 15:51:54 +0100 |
4 |
Subject: ntp: don't use IP_SENDSRCADDR on bound socket |
5 |
|
6 |
On FreeBSD, sendmsg() fails when IP_SENDSRCADDR specifies a source |
7 |
address on a socket that is bound to the address. This prevents a server |
8 |
configured with the bindaddress directive from responding to clients. |
9 |
|
10 |
Add a new variable to check whether the server IPv4 socket is not bound |
11 |
before setting the source address. |
12 |
--- ntp_io.c.orig 2018-09-19 14:38:15 UTC |
13 |
+++ ntp_io.c |
14 |
@@ -105,6 +105,9 @@ static int separate_client_sockets; |
15 |
disabled */ |
16 |
static int permanent_server_sockets; |
17 |
|
18 |
+/* Flag indicating the server IPv4 socket is bound to an address */ |
19 |
+static int bound_server_sock_fd4; |
20 |
+ |
21 |
/* Flag indicating that we have been initialised */ |
22 |
static int initialised=0; |
23 |
|
24 |
@@ -168,6 +171,9 @@ prepare_socket(int family, int port_number, int client |
25 |
my_addr.in4.sin_port = htons(port_number); |
26 |
my_addr_len = sizeof (my_addr.in4); |
27 |
|
28 |
+ if (!client_only) |
29 |
+ bound_server_sock_fd4 = my_addr.in4.sin_addr.s_addr != htonl(INADDR_ANY); |
30 |
+ |
31 |
break; |
32 |
#ifdef FEAT_IPV6 |
33 |
case AF_INET6: |
34 |
@@ -821,8 +827,8 @@ NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address |
35 |
msg.msg_flags = 0; |
36 |
cmsglen = 0; |
37 |
|
38 |
- if (local_addr->ip_addr.family == IPADDR_INET4) { |
39 |
#ifdef HAVE_IN_PKTINFO |
40 |
+ if (local_addr->ip_addr.family == IPADDR_INET4) { |
41 |
struct in_pktinfo *ipi; |
42 |
|
43 |
cmsg = CMSG_FIRSTHDR(&msg); |
44 |
@@ -837,7 +843,11 @@ NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address |
45 |
ipi->ipi_spec_dst.s_addr = htonl(local_addr->ip_addr.addr.in4); |
46 |
if (local_addr->if_index != INVALID_IF_INDEX) |
47 |
ipi->ipi_ifindex = local_addr->if_index; |
48 |
+ } |
49 |
#elif defined(IP_SENDSRCADDR) |
50 |
+ /* Specify the IPv4 source address only if the socket is not bound */ |
51 |
+ if (local_addr->ip_addr.family == IPADDR_INET4 && |
52 |
+ local_addr->sock_fd == server_sock_fd4 && !bound_server_sock_fd4) { |
53 |
struct in_addr *addr; |
54 |
|
55 |
cmsg = CMSG_FIRSTHDR(&msg); |
56 |
@@ -850,8 +860,8 @@ NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address |
57 |
|
58 |
addr = (struct in_addr *)CMSG_DATA(cmsg); |
59 |
addr->s_addr = htonl(local_addr->ip_addr.addr.in4); |
60 |
-#endif |
61 |
} |
62 |
+#endif |
63 |
|
64 |
#ifdef HAVE_IN6_PKTINFO |
65 |
if (local_addr->ip_addr.family == IPADDR_INET6) { |