nts: follow bind*device settings for NTS-KE sockets

Bind the server and client NTS-KE sockets to the specified device.
This commit is contained in:
Miroslav Lichvar 2020-07-13 14:16:42 +02:00
parent 55a90c3735
commit c10b66b579
2 changed files with 7 additions and 4 deletions

View file

@ -308,7 +308,7 @@ int
NKC_Start(NKC_Instance inst)
{
IPSockAddr local_addr;
char label[512];
char label[512], *iface;
int sock_fd;
assert(!NKC_IsActive(inst));
@ -318,14 +318,15 @@ NKC_Start(NKC_Instance inst)
return 0;
}
/* Follow the bindacqaddress setting */
/* Follow the bindacqaddress and bindacqdevice settings */
CNF_GetBindAcquisitionAddress(inst->address.ip_addr.family, &local_addr.ip_addr);
if (local_addr.ip_addr.family != inst->address.ip_addr.family)
SCK_GetAnyLocalIPAddress(inst->address.ip_addr.family, &local_addr.ip_addr);
local_addr.port = 0;
iface = CNF_GetBindAcquisitionInterface();
sock_fd = SCK_OpenTcpSocket(&inst->address, &local_addr, NULL, 0);
sock_fd = SCK_OpenTcpSocket(&inst->address, &local_addr, iface, 0);
if (sock_fd < 0)
return 0;

View file

@ -256,19 +256,21 @@ static int
open_socket(int family, int port)
{
IPSockAddr local_addr;
char *iface;
int sock_fd;
if (!SCK_IsIpFamilyEnabled(family))
return INVALID_SOCK_FD;
CNF_GetBindAddress(family, &local_addr.ip_addr);
iface = CNF_GetBindNtpInterface();
if (local_addr.ip_addr.family != family)
SCK_GetAnyLocalIPAddress(family, &local_addr.ip_addr);
local_addr.port = port;
sock_fd = SCK_OpenTcpSocket(NULL, &local_addr, NULL, 0);
sock_fd = SCK_OpenTcpSocket(NULL, &local_addr, iface, 0);
if (sock_fd < 0) {
LOG(LOGS_ERR, "Could not open NTS-KE socket on %s", UTI_IPSockAddrToString(&local_addr));
return INVALID_SOCK_FD;