Keep the values of numbered traffic counters across reloads

What a numbered counter counted now belongs to the process: a counter
rule points to the value of its number, created the first time the
number is met (from the counter file, if one is open) and shared by the
rules of that number in every configuration loaded. A reload no longer
resets it when there is no counter file, and once configurations can
outlive one another, clients of the old and the new one count into the
same value. An unnumbered counter, and those LdapPlugin makes, keep a
value of their own as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-13 19:05:59 +03:00
1 parent 8887031324
commit 8bd5c0f0fa
10 files changed
+143 -44

No files matched your search

+7 -7
View File
@@ -214,7 +214,7 @@ void dumpcounters(struct trafcount *tlin, int counterd){
if(cfp){
for(tl = tlin; cfp && tl; tl = tl->next){
if(tl->type >= conf.countertype)
fprintf(cfp, "%05d %020"PRIu64"%s%s\n", tl->number, tl->traf64, tl->comment?" #" : "", tl->comment? tl->comment : "");
fprintf(cfp, "%05d %020"PRIu64"%s%s\n", tl->number, tl->v->traf64, tl->comment?" #" : "", tl->comment? tl->comment : "");
}
fclose(cfp);
}
@@ -228,15 +228,15 @@ void dumpcounters(struct trafcount *tlin, int counterd){
if(lseek(counterd,
sizeof(struct counter_header) + (tl->number - 1) * sizeof(struct counter_record),
SEEK_SET) >= 0){
crecord.traf64 = tl->traf64;
crecord.cleared = tl->cleared;
crecord.updated = tl->updated;
crecord.traf64 = tl->v->traf64;
crecord.cleared = tl->v->cleared;
crecord.updated = tl->v->updated;
if(write(counterd, &crecord, sizeof(struct counter_record))){}
}
}
if(tl->type!=NEVER && timechanged(tl->cleared, curtime, tl->type)){
tl->cleared = curtime;
tl->traf64 = 0;
if(tl->type!=NEVER && timechanged(tl->v->cleared, curtime, tl->type)){
tl->v->cleared = curtime;
tl->v->traf64 = 0;
}
}
}