Browse code

- also use a lock for reading the global blacklist, to be safe against eventual reloads

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5004 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 26/09/2008 12:22:30
Showing 1 changed files
... ...
@@ -397,6 +397,7 @@ static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg
397 397
 	void *nodeflags;
398 398
 	char *ptr;
399 399
 	char req_number[MAXNUMBERLEN+1];
400
+	int ret = -1;
400 401
 
401 402
 	if (msg->first_line.type != SIP_REQUEST) {
402 403
 		LM_ERR("SIP msg is not a request\n");
... ...
@@ -422,19 +423,23 @@ static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg
422 423
 	}
423 424
 
424 425
 	LM_DBG("check entry %s\n", req_number);
426
+
427
+	/* avoids dirty reads when updating d-tree */
428
+	lock_get(lock);
425 429
 	if (dtrie_longest_match(arg1->dtrie_root, ptr, strlen(ptr), &nodeflags) >= 0) {
426 430
 		if (nodeflags == (void *)MARK_WHITELIST) {
427 431
 			/* LM_DBG("whitelisted"); */
428
-			return 1; /* found, but is whitelisted */
432
+			ret = 1; /* found, but is whitelisted */
429 433
 		}
430 434
 	}
431 435
 	else {
432 436
 		/* LM_ERR("not found"); */
433
-		return 1; /* not found is ok */
437
+		ret = 1; /* not found is ok */
434 438
 	}
439
+	lock_release(lock);
435 440
 
436 441
 	LM_DBG("entry %s is blacklisted\n", req_number);
437
-	return -1;
442
+	return ret;
438 443
 }
439 444
 
440 445