-------------------------------------------------------------------------
| 225 | |
| 226 | //------------------------------------------------------------------------- |
| 227 | static int |
| 228 | handle_close_hook(TSCont * /* contp ATS_UNUSED */, TSEvent /* event ATS_UNUSED */, void *edata) |
| 229 | { |
| 230 | Dbg(dbg_ctl, "handle_close_hook"); |
| 231 | auto txnp = static_cast<TSHttpTxn>(edata); |
| 232 | |
| 233 | if (enabled == false) { |
| 234 | Dbg(dbg_ctl, "plugin disabled"); |
| 235 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | // get the errors from the state machine |
| 240 | Errors transaction; |
| 241 | Errors session; |
| 242 | TSHttpTxnClientReceivedErrorGet(txnp, &transaction.cls, &transaction.code); |
| 243 | TSHttpTxnClientSentErrorGet(txnp, &session.cls, &session.code); |
| 244 | |
| 245 | // debug if we have an error |
| 246 | if (transaction.cls != 0 || session.cls != 0 || transaction.code != 0 || session.code != 0) { |
| 247 | Dbg(dbg_ctl, "transaction error class=%d code=%" PRIu64 " session error class=%d code=%" PRIu64, transaction.cls, |
| 248 | transaction.code, session.cls, session.code); |
| 249 | } |
| 250 | |
| 251 | // count the error if there is a transaction error CANCEL or a session error ENHANCE_YOUR_CALM |
| 252 | // https://www.rfc-editor.org/rfc/rfc9113.html#name-error-codes |
| 253 | if ((transaction.cls == 2 && transaction.code == 8) || (session.cls == 1 && session.code == 11)) { |
| 254 | TSHttpSsn ssn = TSHttpTxnSsnGet(txnp); |
| 255 | TSVConn vconn = TSHttpSsnClientVConnGet(ssn); |
| 256 | const sockaddr *addr = TSNetVConnRemoteAddrGet(vconn); |
| 257 | swoc::IPAddr ipaddr(addr); |
| 258 | uint32_t count = ip_table.increment(ipaddr); |
| 259 | if (count > RESET_LIMIT) { |
| 260 | std::string address; |
| 261 | Dbg(dbg_ctl, "ip=%s count=%d is over the limit, shutdown connection on close", ipaddr_to_string(ipaddr, address).c_str(), |
| 262 | count); |
| 263 | int fd = TSVConnFdGet(vconn); |
| 264 | shutdown(fd, SHUT_RDWR); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | //------------------------------------------------------------------------- |
| 273 | static int |
nothing calls this directly
no test coverage detected