Skip to content

Commit

Permalink
Wrap all access to the forwarded and clients structures in locks. Thi…
Browse files Browse the repository at this point in the history
…s is sometimes a bit cumbersome, however, it is necessary as we cannot completely lock the routines because this would prevent DNS resolution from being able to work

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Apr 14, 2019
1 parent cc88ed7 commit 9c0da2f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ void resolveClients(bool onlynew)

// If onlynew flag is set, we will only resolve new clients
// If not, we will try to re-resolve all known clients
if(onlynew && !clients[clientID].new)
lock_shm();
bool newlock = clients[clientID].new;
unlock_shm();
if(onlynew && !newlock)
continue;

// Obtain/update hostname of this client
lock_shm();
size_t oldnamepos = clients[clientID].namepos;
size_t newnamepos = resolveAndAddHostname(clients[clientID].ippos, oldnamepos);
size_t ippos = clients[clientID].ippos;
unlock_shm();
size_t newnamepos = resolveAndAddHostname(ippos, oldnamepos);

if(newnamepos != oldnamepos)
{
Expand Down Expand Up @@ -143,12 +149,18 @@ void resolveForwardDestinations(bool onlynew)

// If onlynew flag is set, we will only resolve new upstream destinations
// If not, we will try to re-resolve all known upstream destinations
if(onlynew && !forwarded[forwardID].new)
lock_shm();
bool newflag = forwarded[forwardID].new;
unlock_shm();
if(onlynew && !newflag)
continue;

// Obtain/update hostname of this client
lock_shm();
size_t oldnamepos = forwarded[forwardID].namepos;
size_t newnamepos = resolveAndAddHostname(forwarded[forwardID].ippos, oldnamepos);
size_t ippos = forwarded[forwardID].ippos;
unlock_shm();
size_t newnamepos = resolveAndAddHostname(ippos, oldnamepos);

if(newnamepos != oldnamepos)
{
Expand Down

0 comments on commit 9c0da2f

Please sign in to comment.