Skip to content

Commit

Permalink
chore: no need for atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Oct 30, 2023
1 parent 659e17f commit 420762a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ _Noreturn static void check_cache() {
}
}

static _Atomic bool cache_initialized = false;

void init_not_http_cache() {
if (cache_initialized) {
return;
}
cache_initialized = true;

if (pthread_rwlock_init(&cacheLock, NULL) != 0) {
syslog(LOG_ERR, "Failed to init cache lock");
exit(EXIT_FAILURE);
Expand Down
8 changes: 6 additions & 2 deletions src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static void send_verdict(
}
}

static _Atomic bool conntrack_info_available = true;
static bool conntrack_info_available = true;
static bool cache_initialized = false;

static void add_to_cache(struct nf_packet *pkt) {
char *ip_str = ip_to_str(&pkt->orig.dst, pkt->orig.dst_port, pkt->orig.ip_version);
Expand Down Expand Up @@ -173,7 +174,10 @@ void handle_packet(struct nf_queue *queue, struct nf_packet *pkt) {
syslog(LOG_WARNING, "Packet has no conntrack. Switching to no cache mode.");
syslog(LOG_WARNING, "Note that this may lead to performance degradation. Especially on low-end routers.");
} else {
init_not_http_cache();
if (!cache_initialized) {
init_not_http_cache();
cache_initialized = true;
}
}
}

Expand Down

0 comments on commit 420762a

Please sign in to comment.