static
| 451 | |
| 452 | // static |
| 453 | int |
| 454 | SessionData::global_session_handler(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) |
| 455 | { |
| 456 | TSHttpSsn ssnp = static_cast<TSHttpSsn>(edata); |
| 457 | |
| 458 | switch (event) { |
| 459 | case TS_EVENT_HTTP_SSN_START: { |
| 460 | // Grab session id for logging against a global value rather than the local |
| 461 | // session_counter. |
| 462 | int64_t id = TSHttpSsnIdGet(ssnp); |
| 463 | |
| 464 | // If the user has asked for SNI filtering, filter on that first because |
| 465 | // any sampling will apply just to that subset of connections that match |
| 466 | // that SNI. |
| 467 | if (!sni_filter.empty()) { |
| 468 | TSVConn ssn_vc = TSHttpSsnClientVConnGet(ssnp); |
| 469 | TSSslConnection ssl_conn = TSVConnSslConnectionGet(ssn_vc); |
| 470 | SSL *ssl_obj = reinterpret_cast<SSL *>(ssl_conn); |
| 471 | if (ssl_obj == nullptr) { |
| 472 | Dbg(dbg_ctl, "global_session_handler(): Ignore non-HTTPS session %" PRId64 "...", id); |
| 473 | break; |
| 474 | } |
| 475 | char const *sni_ptr = SSL_get_servername(ssl_obj, TLSEXT_NAMETYPE_host_name); |
| 476 | if (sni_ptr == nullptr) { |
| 477 | Dbg(dbg_ctl, "global_session_handler(): Ignore HTTPS session with non-existent SNI."); |
| 478 | break; |
| 479 | } else { |
| 480 | const std::string_view sni{sni_ptr}; |
| 481 | if (sni != sni_filter) { |
| 482 | Dbg(dbg_ctl, "global_session_handler(): Ignore HTTPS session with non-filtered SNI: %s", sni_ptr); |
| 483 | break; |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | const auto this_session_count = session_counter++; |
| 488 | if (this_session_count % sample_pool_size != 0) { |
| 489 | Dbg(dbg_ctl, "Ignore session %" PRId64 " per the random sampling mechanism", id); |
| 490 | break; |
| 491 | } else if (enforce_disk_limit && disk_usage >= max_disk_usage) { |
| 492 | Dbg(dbg_ctl, "Ignore session %" PRId64 " due to disk usage %" PRId64 " bytes", id, disk_usage.load()); |
| 493 | break; |
| 494 | } else { |
| 495 | const sockaddr *client_ip = TSHttpSsnClientAddrGet(ssnp); |
| 496 | if (SessionData::is_filtered_out(client_ip)) { |
| 497 | Dbg(dbg_ctl, "Ignore session %" PRId64 " per the client's IP filter", id); |
| 498 | break; |
| 499 | } |
| 500 | } |
| 501 | // Beginning of a new session |
| 502 | /// Get epoch time |
| 503 | auto start = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()); |
| 504 | |
| 505 | // Create new per session data |
| 506 | SessionData *ssnData = new SessionData; |
| 507 | TSUserArgSet(ssnp, session_arg_index, ssnData); |
| 508 | |
| 509 | TSContDataSet(ssnData->aio_cont, ssnData); |
| 510 |
nothing calls this directly
no test coverage detected