From a54930c7c5a60010c55a4f0e9fd5ba286592a977 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 14 Apr 2023 14:49:05 +0300 Subject: [PATCH] Second attempt on req->host changes --- fw/http.c | 30 +++--------------------------- fw/http.h | 6 +++++- fw/http_parser.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/fw/http.c b/fw/http.c index c95a0b9c1b..d075397e5a 100644 --- a/fw/http.c +++ b/fw/http.c @@ -752,21 +752,7 @@ do { \ if (!cl_len) return TFW_BLOCK; - if (req->host.len) { - host = req->host; - } else { - /* Invalid id value */ - unsigned id = TFW_HTTP_HDR_NUM; - - if (!TFW_STR_EMPTY(&req->h_tbl->tbl[TFW_HTTP_HDR_H2_AUTHORITY])) - id = TFW_HTTP_HDR_H2_AUTHORITY; - else if (!TFW_STR_EMPTY(&req->h_tbl->tbl[TFW_HTTP_HDR_HOST])) - id = TFW_HTTP_HDR_HOST; - - if (id != TFW_HTTP_HDR_NUM) - tfw_http_msg_clnthdr_val(req, &req->h_tbl->tbl[id], - id, &host); - } + host = req->host; remaining = RESP_BUF_LEN - SLEN(S_V_DATE) - cl_len; len = host.len + req->uri_path.len + body_len; @@ -1497,8 +1483,6 @@ tfw_http_req_redir(TfwHttpReq *req, int status, TfwHttpRedir *redir) TfwStr *c, *end, *c2, *end2; char *status_line; size_t i = 0; - TfwStr *hdr; - TfwStr hdr_val; tfw_http_prep_date(date_val); @@ -1537,16 +1521,7 @@ do { \ TFW_STRCPY(&req->uri_path); break; case TFW_HTTP_REDIR_HOST: - if (req->host.len) { - hdr_val = req->host; - } else { - hdr = &req->h_tbl->tbl[TFW_HTTP_HDR_HOST]; - tfw_http_msg_clnthdr_val(req, hdr, - TFW_HTTP_HDR_HOST, - &hdr_val); - } - - TFW_STRCPY(&hdr_val); + TFW_STRCPY(&req->host); break; default: BUG(); @@ -5774,6 +5749,7 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb) TfwHttpActionResult res; BUG_ON(!stream->msg); + pr_info(">>> tfw_http_req_process"); T_DBG2("Received %u client data bytes on conn=%p msg=%p\n", skb->len, conn, stream->msg); diff --git a/fw/http.h b/fw/http.h index 5bad693987..aaa5407b5f 100644 --- a/fw/http.h +++ b/fw/http.h @@ -439,7 +439,10 @@ typedef struct { * @pit - iterator for tracking transformed data allocation (applicable * for HTTP/2 mode only); * @userinfo - userinfo in URI, not mandatory; - * @host - host in URI, may differ from Host header; + * @host - host that was picked from request URI, Host or HTTP/2 + * authority header; + * @uri_host - points to host if request URI contained hostname, NULL + * otherwise; * @uri_path - path + query + fragment from URI (RFC3986.3); * @mark - special hash mark for redirects handling in session module; * @multipart_boundary_raw - multipart boundary as is, maybe with escaped chars; @@ -470,6 +473,7 @@ struct tfw_http_req_t { TfwHttpCond cond; TfwMsgParseIter pit; TfwStr userinfo; + TfwStr *uri_host; TfwStr host; TfwStr uri_path; TfwStr mark; diff --git a/fw/http_parser.c b/fw/http_parser.c index 64954e05b2..e1530b71f2 100644 --- a/fw/http_parser.c +++ b/fw/http_parser.c @@ -5870,6 +5870,7 @@ Req_Method_1CharStep: __attribute__((cold)) */ __FSM_STATE(Req_UriAuthorityStart, cold) { if (likely(isalnum(c) || c == '.' || c == '-')) { + req->uri_host = &req->host; __msg_field_open(&req->host, p); __FSM_MOVE_f(Req_UriAuthority, &req->host); } else if (likely(c == '/')) { @@ -5883,6 +5884,7 @@ Req_Method_1CharStep: __attribute__((cold)) req->host.flags |= TFW_STR_COMPLETE; __FSM_JMP(Req_UriMark); } else if (c == '[') { + req->uri_host = &req->host; __msg_field_open(&req->host, p); __FSM_MOVE_f(Req_UriAuthorityIPv6, &req->host); } @@ -10682,8 +10684,12 @@ tfw_h2_parse_req_finish(TfwHttpReq *req) req->body.flags |= TFW_STR_COMPLETE; __set_bit(TFW_HTTP_B_FULLY_PARSED, req->flags); - __h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY], - &req->host); + if (!TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY])) + __h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY], + &req->host); + else + __h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_HOST], + &req->host); __h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_PATH], &req->uri_path);