Fix for ZTO-33 (Jira), only assign routes if there is a viable source IP.

This commit is contained in:
Adam Ierymenko 2020-11-06 11:01:45 -05:00
parent 317263b31c
commit 90f18f7ee7
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
3 changed files with 73 additions and 11 deletions

View file

@ -1949,21 +1949,21 @@ public:
const InetAddress *const target = reinterpret_cast<const InetAddress *>(&(n.config.routes[i].target));
const InetAddress *const via = reinterpret_cast<const InetAddress *>(&(n.config.routes[i].via));
// Make sure we are allowed to set this managed route.
if ( (!checkIfManagedIsAllowed(n,*target)) || ((via->ss_family == target->ss_family)&&(matchIpOnly(myIps,*via))) )
continue;
// Find an IP on the interface that can be a source IP, abort if no IPs assigned.
const InetAddress *src = NULL;
for (unsigned int j=0; j<n.config.assignedAddressCount; ++j) {
const InetAddress *const tmp = reinterpret_cast<const InetAddress *>(&(n.config.assignedAddresses[j]));
if (target->isV4() && tmp->isV4()) {
src = reinterpret_cast<InetAddress *>(&(n.config.assignedAddresses[j]));
break;
} else if (target->isV6() && tmp->isV6()) {
src = reinterpret_cast<InetAddress *>(&(n.config.assignedAddresses[j]));
break;
unsigned int mostMatchingPrefixBits = 0;
for(std::vector<InetAddress>::const_iterator i(myIps.begin());i!=myIps.end();++i) {
const unsigned int matchingPrefixBits = i->matchingPrefixBits(*target);
if (matchingPrefixBits >= mostMatchingPrefixBits) {
mostMatchingPrefixBits = matchingPrefixBits;
src = &(*i);
}
}
if (!src)
src = &NULL_INET_ADDR;
if ( (!checkIfManagedIsAllowed(n,*target)) || ((via->ss_family == target->ss_family)&&(matchIpOnly(myIps,*via))) )
continue;
// Ignore routes implied by local managed IPs since adding the IP adds the route