Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
renaming of functions
  • Loading branch information
avbelov23 committed May 6, 2022
1 parent 870191a commit 6c779de
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ tfw_handle_validation_req(TfwHttpReq *req, TfwCacheEntry *ce)
|| (req->method == TFW_HTTP_METH_HEAD))
tfw_cache_send_304(req, ce);
else
tfw_http_send_resp(req, 412,
tfw_http_send_err_resp(req, 412,
"request validation: "
"precondition failed");

Expand Down Expand Up @@ -1965,14 +1965,14 @@ tfw_cache_purge_method(TfwHttpReq *req)

/* Deny PURGE requests by default. */
if (!(cache_cfg.cache && g_vhost->cache_purge && g_vhost->cache_purge_acl)) {
tfw_http_send_resp(req, 403, "purge: not configured");
tfw_http_send_err_resp(req, 403, "purge: not configured");
return -EINVAL;
}

/* Accept requests from configured hosts only. */
ss_getpeername(req->conn->sk, &saddr);
if (!tfw_capuacl_match(&saddr)) {
tfw_http_send_resp(req, 403, "purge: ACL violation");
tfw_http_send_err_resp(req, 403, "purge: ACL violation");
return -EINVAL;
}

Expand All @@ -1982,14 +1982,14 @@ tfw_cache_purge_method(TfwHttpReq *req)
ret = tfw_cache_purge_invalidate(req);
break;
default:
tfw_http_send_resp(req, 403, "purge: invalid option");
tfw_http_send_err_resp(req, 403, "purge: invalid option");
return -EINVAL;
}

if (ret)
tfw_http_send_resp(req, 404, "purge: processing error");
tfw_http_send_err_resp(req, 404, "purge: processing error");
else if (!test_bit(TFW_HTTP_B_PURGE_GET, req->flags))
tfw_http_send_resp(req, 200, "purge: success");
tfw_http_send_err_resp(req, 200, "purge: success");

return ret;
}
Expand Down Expand Up @@ -2382,7 +2382,7 @@ cache_req_process_node(TfwHttpReq *req, tfw_http_cache_cb_t action)
}
out:
if (!resp && (req->cache_ctl.flags & TFW_HTTP_CC_OIFCACHED))
tfw_http_send_resp(req, 504, "resource not cached");
tfw_http_send_err_resp(req, 504, "resource not cached");
else
/*
* TODO: RFC 7234 4.3.2: Extend preconditional request headers
Expand Down
44 changes: 22 additions & 22 deletions fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ tfw_h2_resp_fwd(TfwHttpResp *resp)
}

static void
tfw_h2_send_resp(TfwHttpReq *req, int status, unsigned int stream_id)
tfw_h2_send_err_resp(TfwHttpReq *req, int status, unsigned int stream_id)
{
TfwStr *msg;
resp_code_t code;
Expand Down Expand Up @@ -1055,7 +1055,7 @@ tfw_h2_send_resp(TfwHttpReq *req, int status, unsigned int stream_id)
* the fourth chunk must be CRLF.
*/
static void
tfw_h1_send_resp(TfwHttpReq *req, int status)
tfw_h1_send_err_resp(TfwHttpReq *req, int status)
{
TfwMsgIter it;
resp_code_t code;
Expand Down Expand Up @@ -1131,7 +1131,7 @@ tfw_h1_send_resp(TfwHttpReq *req, int status)
* a value.
*/
static void
tfw_h2_send_resp2(TfwHttpReq *req, TfwStr *msg, int status,
tfw_h2_send_resp(TfwHttpReq *req, TfwStr *msg, int status,
unsigned int stream_id)
{
TfwHttpResp *resp;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ tfw_h2_send_resp2(TfwHttpReq *req, TfwStr *msg, int status,
* a value.
*/
static void
tfw_h1_send_resp2(TfwHttpReq *req, TfwStr *msg, int status)
tfw_h1_send_resp(TfwHttpReq *req, TfwStr *msg, int status)
{
TfwMsgIter it;
TfwHttpResp *resp;
Expand Down Expand Up @@ -1489,24 +1489,24 @@ tfw_http_nip_req_resched_err(TfwSrvConn *srv_conn, TfwHttpReq *req,

/* Common interface for sending error responses. */
void
tfw_http_send_resp(TfwHttpReq *req, int status, const char *reason)
tfw_http_send_err_resp(TfwHttpReq *req, int status, const char *reason)
{
if (!(tfw_blk_flags & TFW_BLK_ERR_NOLOG)) {
T_WARN_ADDR_STATUS(reason, &req->conn->peer->addr,
TFW_NO_PORT, status);
}

if (TFW_MSG_H2(req))
tfw_h2_send_resp(req, status, 0);
tfw_h2_send_err_resp(req, status, 0);
else
tfw_h1_send_resp(req, status);
tfw_h1_send_err_resp(req, status);
}

static void
tfw_http_send_resp2(TfwHttpReq *req, TfwStr *msg, int status)
tfw_http_send_resp(TfwHttpReq *req, TfwStr *msg, int status)
{
if (TFW_MSG_H2(req)) {
tfw_h2_send_resp2(req, msg, status, 0);
tfw_h2_send_resp(req, msg, status, 0);
} else {
TfwCliConn *cli_conn = (TfwCliConn *)req->conn;

Expand All @@ -1517,7 +1517,7 @@ tfw_http_send_resp2(TfwHttpReq *req, TfwStr *msg, int status)
list_add_tail(&req->msg.seq_list, &cli_conn->seq_queue);
spin_unlock(&cli_conn->seq_qlock);

tfw_h1_send_resp2(req, msg, status);
tfw_h1_send_resp(req, msg, status);
}
}

Expand Down Expand Up @@ -1614,7 +1614,7 @@ do { \
S_CRLF S_CRLF) + (url_p - url),
.nchunks = 10
};
tfw_http_send_resp2(req, &msg, status);
tfw_http_send_resp(req, &msg, status);
}
}

Expand Down Expand Up @@ -1717,7 +1717,7 @@ tfw_http_req_zap_error(struct list_head *eq)
|| (!TFW_MSG_H2(req)
&& !test_bit(TFW_HTTP_B_REQ_DROP, req->flags)))
{
tfw_http_send_resp(req, req->httperr.status,
tfw_http_send_err_resp(req, req->httperr.status,
req->httperr.reason);
}
else
Expand Down Expand Up @@ -2237,7 +2237,7 @@ tfw_http_req_resched(TfwHttpReq *req, TfwServer *srv, struct list_head *eq)
}
} else if (!(sch_conn = tfw_http_get_srv_conn((TfwMsg *)req))) {
T_DBG("Unable to find a backend server\n");
tfw_http_send_resp(req, 502, "request dropped: unable to"
tfw_http_send_err_resp(req, 502, "request dropped: unable to"
" find an available back end server");
TFW_INC_STAT_BH(clnt.msgs_otherr);
return 0;
Expand Down Expand Up @@ -4893,7 +4893,7 @@ tfw_h1_resp_adjust_fwd(TfwHttpResp *resp)
*/
if (tfw_http_adjust_resp(resp)) {
tfw_http_conn_msg_free((TfwHttpMsg *)resp);
tfw_http_send_resp(req, 500,
tfw_http_send_err_resp(req, 500,
"response dropped: processing error");
TFW_INC_STAT_BH(serv.msgs_otherr);
return;
Expand Down Expand Up @@ -4966,15 +4966,15 @@ tfw_h2_error_resp(TfwHttpReq *req, int status, bool reply, bool attack,
* is already in locally closed state (switched in
* @tfw_h2_stream_id_close() during failed proxy/internal response
* creation) or will be switched into locally closed state in
* @tfw_h2_send_resp() (or in @tfw_h2_stream_id_close() if no error
* @tfw_h2_send_err_resp() (or in @tfw_h2_stream_id_close() if no error
* response is needed) below; remotely (i.e. on client side) stream
* will be closed - due to END_STREAM flag set in the last frame of
* error response; in case of attack we must close entire connection,
* and GOAWAY frame should be sent (RFC 7540 section 6.8) after
* error response.
*/
if (reply) {
tfw_h2_send_resp(req, status, 0);
tfw_h2_send_err_resp(req, status, 0);
if (attack)
tfw_h2_conn_terminate_close(ctx, HTTP2_ECODE_PROTO,
!on_req_recv_event);
Expand Down Expand Up @@ -5039,7 +5039,7 @@ tfw_h1_error_resp(TfwHttpReq *req, int status, bool reply, bool attack,
*/
if (on_req_recv_event || attack)
tfw_http_req_set_conn_close(req);
tfw_h1_send_resp(req, status);
tfw_h1_send_err_resp(req, status);
}
/*
* Serve all pending requests if not under attack, close immediately
Expand Down Expand Up @@ -5263,7 +5263,7 @@ tfw_h2_resp_adjust_fwd(TfwHttpResp *resp)
T_WARN_ADDR_STATUS("response dropped: processing error",
&req->conn->peer->addr,
TFW_NO_PORT, 500);
tfw_h2_send_resp(req, 500, stream_id);
tfw_h2_send_err_resp(req, 500, stream_id);
tfw_hpack_enc_release(&ctx->hpack, resp->flags);
TFW_INC_STAT_BH(serv.msgs_otherr);

Expand Down Expand Up @@ -5343,11 +5343,11 @@ tfw_http_req_cache_cb(TfwHttpMsg *msg)
goto conn_put;

send_502:
tfw_http_send_resp(req, 502, "request dropped: processing error");
tfw_http_send_err_resp(req, 502, "request dropped: processing error");
TFW_INC_STAT_BH(clnt.msgs_otherr);
return;
send_500:
tfw_http_send_resp(req, 500, "request dropped: processing error");
tfw_http_send_err_resp(req, 500, "request dropped: processing error");
TFW_INC_STAT_BH(clnt.msgs_otherr);
conn_put:
/*
Expand Down Expand Up @@ -5942,7 +5942,7 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb)
* The request should either be stored or released.
* Otherwise we lose the reference to it and get a leak.
*/
tfw_http_send_resp(req, 500, "request dropped:"
tfw_http_send_err_resp(req, 500, "request dropped:"
" processing error");
TFW_INC_STAT_BH(clnt.msgs_otherr);
}
Expand Down Expand Up @@ -6178,7 +6178,7 @@ tfw_http_resp_cache(TfwHttpMsg *hmresp)
if (tfw_cache_process(hmresp, tfw_http_resp_cache_cb))
{
tfw_http_conn_msg_free(hmresp);
tfw_http_send_resp(req, 500, "response dropped:"
tfw_http_send_err_resp(req, 500, "response dropped:"
" processing error");
TFW_INC_STAT_BH(serv.msgs_otherr);
/* Proceed with processing of the next response. */
Expand Down
2 changes: 1 addition & 1 deletion fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ int tfw_h1_prep_redirect(TfwHttpResp *resp, unsigned short status,
int tfw_http_prep_304(TfwHttpReq *req, struct sk_buff **skb_head,
TfwMsgIter *it);
void tfw_http_conn_msg_free(TfwHttpMsg *hm);
void tfw_http_send_resp(TfwHttpReq *req, int status, const char *reason);
void tfw_http_send_err_resp(TfwHttpReq *req, int status, const char *reason);

/* Helper functions */
char *tfw_http_msg_body_dup(const char *filename, size_t *len);
Expand Down

0 comments on commit 6c779de

Please sign in to comment.