Skip to content

Fix syncookies statistics and tests - #63

Open
krizhanovsky wants to merge 18 commits into
mainfrom
ak-470-syncookies-tests
Open

Fix syncookies statistics and tests#63
krizhanovsky wants to merge 18 commits into
mainfrom
ak-470-syncookies-tests

Conversation

@krizhanovsky

@krizhanovsky krizhanovsky commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
  • Fix SYNcookies statistics to align it with related counters from /proc/net/netstat and make SYNcookies easier to monitor and test
  • Fix SYNcookies test (https://github.com/tempesta-tech/escudo/issues/470)
  • Add comments and rename constants in XfwDropStat to distinguish Prometheus statistic (XDP_DROP, XDP_PASS and common traffic) and ClickHouse events (DROP statistics)
  • Add test for TCP syncookie options
  • Add AI integration guides (see Integrate Sashiko for review tempesta#2680)

@krizhanovsky
krizhanovsky marked this pull request as draft August 9, 2026 19:13
Comment thread t/func/tests/test_tcp_syncookies.py
@krizhanovsky
krizhanovsky force-pushed the ak-470-syncookies-tests branch from ad52be7 to 1c684ba Compare August 10, 2026 17:05

@consuelo2210 consuelo2210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed only C/C++ part and left python part to @symstu-tempesta. I have the only question about expanding statistic:

Could we consider keeping this within the existing XfwTrafficStat abstraction? From an extensibility perspective, it seems preferable to add XFW_SYNCOOKIE_FAILED there and use count_traffic_stat(...), rather than introducing a separate field and a separate code path. This would also make adding future traffic statistics simpler and avoid special cases in Prometheus.

Comment thread bpf/filter.h Outdated
@krizhanovsky
krizhanovsky force-pushed the ak-470-syncookies-tests branch from 680109c to 78b9a55 Compare August 14, 2026 21:38
@krizhanovsky
krizhanovsky marked this pull request as ready for review August 16, 2026 19:13
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/framework/xfw.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py Outdated

@consuelo2210 consuelo2210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: just make the alignment consistent after the name changes in drop_stats.h.

Also, commit 78b9a55 has an incorrect description: we don't report XDP_DROP stats to Prometheus.

Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
@symstu-tempesta
symstu-tempesta marked this pull request as draft August 19, 2026 12:58
@symstu-tempesta
symstu-tempesta force-pushed the ak-470-syncookies-tests branch from 029cfd7 to 6790dda Compare August 19, 2026 18:10
@symstu-tempesta
symstu-tempesta marked this pull request as ready for review August 19, 2026 18:10
@symstu-tempesta
symstu-tempesta self-requested a review August 19, 2026 18:19
krizhanovsky and others added 12 commits August 20, 2026 18:47
Previously we configured passive_timer and flood_timer with 0 by default
and tcp_syncookies_flood_mode() and tcp_syncookies_passive_mode() used
jiffies (1/HZ sec). This leaded to immediate, and worse - scheduler
dependent, switch between the modes. Effectively, flood_timer=0
passive_timer=0 in the tests leaded to flacky behavior.

Now by default set the timers to 1 second and discourage 0 values in the
wiki.

Also make the TCPsyncookies Prometheus counters consistent with the
kernel statistics and report generated, received and failed syncookies.
This makes the testing an future observability easier.

Keep the existing statistics split by packet-processing outcome: generated
SYN cookies are TX statistics, failed SYN cookies remain DROP incidents,
and received SYN cookies are traffic statistics.
Adopt slightly modified patch by Maksym Stukalo from the Escudo project:

add Tempesta xFW Prometheus statistics along the currently monitored
/proc/net/netstat - we need all the counters to validate the xFW
behavior.

Change only one test to check the concept - if it's right, then I'll
update the rest of the tests accordingly.
Call XFW.metrics() and run_start() to initialize the metrics values
after slef-requests.

Small cleanup for fetching syncookies values from /proc/net/netstat

Original patch also adjusts the values for syncookies_read_kern_stats(),
but in the current version we distinguish between the kernel and xFW
statistics and analyze both of them.
* Move TCP syncookie failed counter to traffic stats

* Separate common and drop statistics

  Add comments and rename constants in XfwDropStat to distinguish
  Prometheus statistic (XDP_DROP, XDP_PASS and common traffic) and
  ClickHouse events (DROP statistics).
@symstu-tempesta
symstu-tempesta force-pushed the ak-470-syncookies-tests branch from 4c0685c to 4d24a67 Compare August 20, 2026 16:47
* It's difficult to set exact metric values because of kernel and XFW work specifics
* Added comments
* Used variables instead of magic numbers
* Added check_xfw_stats to shorten the code for comparing XFW metrics and kernel stats
@symstu-tempesta
symstu-tempesta force-pushed the ak-470-syncookies-tests branch from 4d24a67 to d3406dd Compare August 20, 2026 19:33
Comment thread t/func/tests/test_tcp_syncookies.py Outdated
Comment on lines -973 to -982
invalid_acks = sum(acknowledged for _, acknowledged in flood_results)
# failed [lo, hi] in params is a factor of invalid_acks: [1, 1] exact, [0, 1] any up to that.
failed_lo, failed_hi = expected_xfw["xfw_syncookie_failed_packets"]
expected = {
**expected_xfw,
"xfw_syncookie_failed_packets": [
failed_lo * invalid_acks,
failed_hi * invalid_acks + 1,
],
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary code originally generated by an LLM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants