Skip to content

Commit

Permalink
SERVER-11776 move port check outside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
benety committed May 29, 2014
1 parent 8f41489 commit da27016
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/mongo/db/commands/isself.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,27 @@ namespace mongo {
#if !defined(_WIN32) && !defined(__sunos__)
// on linux and os x we can do a quick check for an ip match

const vector<string> myaddrs = getMyAddrs();
const vector<string> addrs = getAllIPs(_host);

for (vector<string>::const_iterator i=myaddrs.begin(), iend=myaddrs.end(); i!=iend; ++i) {
for (vector<string>::const_iterator j=addrs.begin(), jend=addrs.end(); j!=jend; ++j) {
string a = *i;
string b = *j;

// check if the ports match as well
if ( (p == serverGlobalParams.port) &&
(a == b || ( str::startsWith( a , "127." ) &&
str::startsWith( b , "127." ) )) // 127. is all loopback
) {

// add to cache
scoped_lock lk( isSelfCommand._cacheLock );
isSelfCommand._cache[host] = true;
return true;
// no need for ip match if the ports do not match
if (p == serverGlobalParams.port) {
const vector<string> myaddrs = getMyAddrs();
const vector<string> addrs = getAllIPs(_host);

for (vector<string>::const_iterator i=myaddrs.begin(), iend=myaddrs.end();
i!=iend; ++i) {
for (vector<string>::const_iterator j=addrs.begin(), jend=addrs.end();
j!=jend; ++j) {
string a = *i;
string b = *j;

if ( a == b || ( str::startsWith( a , "127." ) &&
str::startsWith( b , "127." ) ) // 127. is all loopback
) {

// add to cache
scoped_lock lk( isSelfCommand._cacheLock );
isSelfCommand._cache[host] = true;
return true;
}
}
}
}
Expand Down

0 comments on commit da27016

Please sign in to comment.