|
|
@ -622,6 +622,8 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
|
|
|
|
* matching interface in the later bind().
|
|
|
|
* matching interface in the later bind().
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
struct ifaddrs *ifaddr, *ifa;
|
|
|
|
struct ifaddrs *ifaddr, *ifa;
|
|
|
|
|
|
|
|
bool have_interface = false;
|
|
|
|
|
|
|
|
|
|
|
|
if(getifaddrs(&ifaddr) < 0){
|
|
|
|
if(getifaddrs(&ifaddr) < 0){
|
|
|
|
net__print_error(MOSQ_LOG_ERR, "Error: %s");
|
|
|
|
net__print_error(MOSQ_LOG_ERR, "Error: %s");
|
|
|
|
return MOSQ_ERR_ERRNO;
|
|
|
|
return MOSQ_ERR_ERRNO;
|
|
|
@ -632,16 +634,17 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!strcasecmp(listener->bind_interface, ifa->ifa_name)
|
|
|
|
if(!strcasecmp(listener->bind_interface, ifa->ifa_name)){
|
|
|
|
&& ifa->ifa_addr->sa_family == rp->ai_addr->sa_family){
|
|
|
|
have_interface = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ifa->ifa_addr->sa_family == rp->ai_addr->sa_family){
|
|
|
|
if(rp->ai_addr->sa_family == AF_INET){
|
|
|
|
if(rp->ai_addr->sa_family == AF_INET){
|
|
|
|
if(listener->host &&
|
|
|
|
if(listener->host &&
|
|
|
|
memcmp(&((struct sockaddr_in *)rp->ai_addr)->sin_addr,
|
|
|
|
memcmp(&((struct sockaddr_in *)rp->ai_addr)->sin_addr,
|
|
|
|
&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr,
|
|
|
|
&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr,
|
|
|
|
sizeof(struct in_addr))){
|
|
|
|
sizeof(struct in_addr))){
|
|
|
|
|
|
|
|
|
|
|
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Interface address for %s does not match specified listener address (%s).",
|
|
|
|
log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface address for %s does not match specified listener address (%s).",
|
|
|
|
listener->bind_interface, listener->host);
|
|
|
|
listener->bind_interface, listener->host);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
@ -658,7 +661,7 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
|
|
|
|
&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr,
|
|
|
|
&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr,
|
|
|
|
sizeof(struct in6_addr))){
|
|
|
|
sizeof(struct in6_addr))){
|
|
|
|
|
|
|
|
|
|
|
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Interface address for %s does not match specified listener address (%s).",
|
|
|
|
log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface address for %s does not match specified listener address (%s).",
|
|
|
|
listener->bind_interface, listener->host);
|
|
|
|
listener->bind_interface, listener->host);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
@ -671,11 +674,17 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
freeifaddrs(ifaddr);
|
|
|
|
freeifaddrs(ifaddr);
|
|
|
|
|
|
|
|
if(have_interface){
|
|
|
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Interface %s does not support %s configuration.",
|
|
|
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Interface %s does not support %s configuration.",
|
|
|
|
listener->bind_interface, rp->ai_addr->sa_family == AF_INET ? "IPv4" : "IPv6");
|
|
|
|
listener->bind_interface, rp->ai_addr->sa_family == AF_INET ? "IPv4" : "IPv6");
|
|
|
|
|
|
|
|
return MOSQ_ERR_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface %s does not exist.", listener->bind_interface);
|
|
|
|
return MOSQ_ERR_NOT_FOUND;
|
|
|
|
return MOSQ_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -756,11 +765,16 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)
|
|
|
|
if(listener->bind_interface){
|
|
|
|
if(listener->bind_interface){
|
|
|
|
/* It might be possible that an interface does not support all relevant sa_families.
|
|
|
|
/* It might be possible that an interface does not support all relevant sa_families.
|
|
|
|
* We should successfully find at least one. */
|
|
|
|
* We should successfully find at least one. */
|
|
|
|
if(net__bind_interface(listener, rp)){
|
|
|
|
rc = net__bind_interface(listener, rp);
|
|
|
|
|
|
|
|
if(rc){
|
|
|
|
COMPAT_CLOSE(sock);
|
|
|
|
COMPAT_CLOSE(sock);
|
|
|
|
listener->sock_count--;
|
|
|
|
listener->sock_count--;
|
|
|
|
|
|
|
|
if(rc == MOSQ_ERR_NOT_FOUND || rc == MOSQ_ERR_INVAL){
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
interface_bound = true;
|
|
|
|
interface_bound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|