MCPcopy Create free account
hub / github.com/apache/trafficserver / handle_start_hook

Function handle_start_hook

plugins/experimental/block_errors/block_errors.cc:169–218  ·  view source on GitHub ↗

-------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

167
168//-------------------------------------------------------------------------
169static int
170handle_start_hook(TSCont * /* contp ATS_UNUSED */, TSEvent /* event ATS_UNUSED */, void *edata)
171{
172 Dbg(dbg_ctl, "handle_start_hook");
173 auto vconn = static_cast<TSVConn>(edata);
174
175 if (enabled == false) {
176 Dbg(dbg_ctl, "plugin disabled");
177 TSVConnReenable(vconn);
178 return 0;
179 }
180
181 // only handle ssl connections
182 if (TSVConnIsSsl(vconn) == 0) {
183 Dbg(dbg_ctl, "not a ssl connection");
184 TSVConnReenable(vconn);
185 return 0;
186 }
187
188 // get the ip address
189 const sockaddr *addr = TSNetVConnRemoteAddrGet(vconn);
190 swoc::IPAddr ipaddr(addr);
191
192 // get the count for the ip address
193 uint32_t count = ip_table.getCount(ipaddr);
194 Dbg(dbg_ctl, "count=%d", count);
195
196 // if the count is over the limit, shutdown or downgrade the connection
197 if (count > RESET_LIMIT) {
198 std::string address;
199 if (shutdown_connection == true) {
200 // shutdown the connection
201 Dbg(dbg_ctl, "ip=%s count=%d is over the limit, shutdown connection on start", ipaddr_to_string(ipaddr, address).c_str(),
202 count);
203 int fd = TSVConnFdGet(vconn);
204 shutdown(fd, SHUT_RDWR);
205 char buffer[4096];
206 while (read(fd, buffer, sizeof(buffer)) > 0) {
207 // drain the connection
208 }
209 } else {
210 // downgrade the connection
211 Dbg(dbg_ctl, "ip=%s count=%d is over the limit, downgrading connection", ipaddr_to_string(ipaddr, address).c_str(), count);
212 TSVConnProtocolDisable(vconn, TS_ALPN_PROTOCOL_HTTP_2_0);
213 }
214 }
215
216 TSVConnReenable(vconn);
217 return 0;
218}
219
220//-------------------------------------------------------------------------
221struct Errors {

Callers

nothing calls this directly

Calls 9

TSVConnReenableFunction · 0.85
TSVConnIsSslFunction · 0.85
TSNetVConnRemoteAddrGetFunction · 0.85
TSVConnFdGetFunction · 0.85
shutdownFunction · 0.85
TSVConnProtocolDisableFunction · 0.85
getCountMethod · 0.80
readFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected