socket: add function to check supported family
Don't log error when an IPv6 socket cannot be opened and chronyd was built without IPv6 support. Reported-by: Lonnie Abelbeck <lonnie@abelbeck.com>
This commit is contained in:
parent
bfcd8ecc56
commit
dd0679ad45
4 changed files with 24 additions and 1 deletions
2
cmdmon.c
2
cmdmon.c
|
@ -159,7 +159,7 @@ open_socket(int family)
|
||||||
case IPADDR_INET4:
|
case IPADDR_INET4:
|
||||||
case IPADDR_INET6:
|
case IPADDR_INET6:
|
||||||
port = CNF_GetCommandPort();
|
port = CNF_GetCommandPort();
|
||||||
if (port == 0)
|
if (port == 0 || !SCK_IsFamilySupported(family))
|
||||||
return INVALID_SOCK_FD;
|
return INVALID_SOCK_FD;
|
||||||
|
|
||||||
CNF_GetBindCommandAddress(family, &local_addr.ip_addr);
|
CNF_GetBindCommandAddress(family, &local_addr.ip_addr);
|
||||||
|
|
3
ntp_io.c
3
ntp_io.c
|
@ -86,6 +86,9 @@ open_socket(int family, int local_port, int client_only, IPSockAddr *remote_addr
|
||||||
int sock_fd, sock_flags, events = SCH_FILE_INPUT;
|
int sock_fd, sock_flags, events = SCH_FILE_INPUT;
|
||||||
IPSockAddr local_addr;
|
IPSockAddr local_addr;
|
||||||
|
|
||||||
|
if (!SCK_IsFamilySupported(family))
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
|
||||||
if (!client_only)
|
if (!client_only)
|
||||||
CNF_GetBindAddress(family, &local_addr.ip_addr);
|
CNF_GetBindAddress(family, &local_addr.ip_addr);
|
||||||
else
|
else
|
||||||
|
|
17
socket.c
17
socket.c
|
@ -1115,6 +1115,23 @@ SCK_Finalise(void)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
SCK_IsFamilySupported(int family)
|
||||||
|
{
|
||||||
|
switch (family) {
|
||||||
|
case IPADDR_INET4:
|
||||||
|
return 1;
|
||||||
|
case IPADDR_INET6:
|
||||||
|
#ifdef FEAT_IPV6
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr)
|
SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr)
|
||||||
{
|
{
|
||||||
|
|
3
socket.h
3
socket.h
|
@ -82,6 +82,9 @@ extern void SCK_Initialise(void);
|
||||||
/* Finalisation function */
|
/* Finalisation function */
|
||||||
extern void SCK_Finalise(void);
|
extern void SCK_Finalise(void);
|
||||||
|
|
||||||
|
/* Check if support for the IP family was enabled in the build */
|
||||||
|
extern int SCK_IsFamilySupported(int family);
|
||||||
|
|
||||||
/* Get the 0.0.0.0/::0 or 127.0.0.1/::1 address */
|
/* Get the 0.0.0.0/::0 or 127.0.0.1/::1 address */
|
||||||
extern void SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr);
|
extern void SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr);
|
||||||
extern void SCK_GetLoopbackIPAddress(int family, IPAddr *local_addr);
|
extern void SCK_GetLoopbackIPAddress(int family, IPAddr *local_addr);
|
||||||
|
|
Loading…
Reference in a new issue