Skip to content

Commit 8d93200

Browse files
committed
Websocket upgrade directive implementation
Contributes to tempesta-tech#755 Signed-off-by: Aleksey Mikhaylov <[email protected]>
1 parent 5f2851d commit 8d93200

File tree

5 files changed

+272
-20
lines changed

5 files changed

+272
-20
lines changed

fw/http.c

+7
Original file line numberDiff line numberDiff line change
@@ -5540,6 +5540,13 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb)
55405540
"request dropped: cannot find appropriate "
55415541
"virtual host");
55425542
TFW_INC_STAT_BH(clnt.msgs_otherr);
5543+
}
5544+
/* Process websocket upgrade case */
5545+
else if (unlikely(
5546+
test_bit(TFW_HTTP_B_CONN_EXTRA, req->flags)
5547+
))
5548+
{
5549+
55435550
}
55445551
/*
55455552
* Look up a cache entry for this request. If there's one, a response

fw/http.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ typedef struct {
170170
* Http headers table.
171171
*
172172
* Singular headers (in terms of RFC 7230 3.2.2) go first to protect header
173-
* repetition attacks. See __hdr_is_singular() and don't forget to
174-
* update the static headers array when add a new singular header here.
175-
* If the new header is hop-by-hop (must not be forwarded and cached by Tempesta)
176-
* it must be listed in tfw_http_init_parser_req()/tfw_http_init_parser_resp()
177-
* for unconditionally hop-by-hop header or in __parse_connection() otherwize.
173+
* repetition attacks. See __hdr_is_singular() and don't forget to update the
174+
* static headers array when add a new singular header here. If the new header
175+
* is hop-by-hop (must not be forwarded and cached by Tempesta) it must be
176+
* listed in tfw_http_init_parser_req()/tfw_http_init_parser_resp()
177+
* for unconditionally hop-by-hop header or in __parse_connection() otherwise.
178178
* If the header is end-to-end it must be listed in __hbh_parser_add_data().
179179
*
180180
* Note: don't forget to update __http_msg_hdr_val() and
@@ -212,6 +212,7 @@ typedef enum {
212212
TFW_HTTP_HDR_X_FORWARDED_FOR,
213213
TFW_HTTP_HDR_KEEP_ALIVE,
214214
TFW_HTTP_HDR_TRANSFER_ENCODING,
215+
TFW_HTTP_HDR_UPGRADE,
215216

216217
/* Start of list of generic (raw) headers. */
217218
TFW_HTTP_HDR_RAW,
@@ -240,6 +241,8 @@ enum {
240241
TFW_HTTP_B_CONN_CLOSE = TFW_HTTP_FLAGS_COMMON,
241242
TFW_HTTP_B_CONN_KA,
242243
TFW_HTTP_B_CONN_EXTRA,
244+
/* Request is a websocket upgrade request */
245+
TFW_HTTP_B_UPGRADE_WEBSOCKET,
243246
/* Chunked is last transfer encoding. */
244247
TFW_HTTP_B_CHUNKED,
245248
/* Chunked in the middle of applied transfer encodings. */

fw/http_msg.c

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ tfw_http_msg_resp_spec_hid(const TfwStr *hdr)
155155
TfwStrDefV("transfer-encoding:",TFW_HTTP_HDR_TRANSFER_ENCODING),
156156
TfwStrDefV("x-forwarded-for:", TFW_HTTP_HDR_X_FORWARDED_FOR),
157157
TfwStrDefV("x-tempesta-cache:", TFW_HTTP_HDR_X_TEMPESTA_CACHE),
158+
TfwStrDefV("upgrade:", TFW_HTTP_HDR_UPGRADE),
158159
};
159160

160161
BUILD_BUG_ON(ARRAY_SIZE(resp_hdrs) !=
@@ -182,6 +183,7 @@ tfw_http_msg_req_spec_hid(const TfwStr *hdr)
182183
TfwStrDefV("user-agent:", TFW_HTTP_HDR_USER_AGENT),
183184
TfwStrDefV("x-forwarded-for:", TFW_HTTP_HDR_X_FORWARDED_FOR),
184185
TfwStrDefV("x-tempesta-cache:", TFW_HTTP_HDR_X_TEMPESTA_CACHE),
186+
TfwStrDefV("upgrade:", TFW_HTTP_HDR_UPGRADE),
185187
};
186188

187189
BUILD_BUG_ON(ARRAY_SIZE(req_hdrs) !=
@@ -215,6 +217,7 @@ __http_msg_hdr_val(TfwStr *hdr, unsigned id, TfwStr *val, bool client)
215217
[TFW_HTTP_HDR_SET_COOKIE] = SLEN("Set-Cookie:"),
216218
[TFW_HTTP_HDR_ETAG] = SLEN("ETag:"),
217219
[TFW_HTTP_HDR_REFERER] = SLEN("Referer:"),
220+
[TFW_HTTP_HDR_UPGRADE] = SLEN("Upgrade:"),
218221
},
219222
(unsigned char []) {
220223
[TFW_HTTP_HDR_HOST] = SLEN("Host:"),
@@ -229,6 +232,7 @@ __http_msg_hdr_val(TfwStr *hdr, unsigned id, TfwStr *val, bool client)
229232
[TFW_HTTP_HDR_COOKIE] = SLEN("Cookie:"),
230233
[TFW_HTTP_HDR_IF_NONE_MATCH] = SLEN("If-None-Match:"),
231234
[TFW_HTTP_HDR_REFERER] = SLEN("Referer:"),
235+
[TFW_HTTP_HDR_UPGRADE] = SLEN("Upgrade:"),
232236
},
233237
};
234238
TfwStr *c, *end;

0 commit comments

Comments
 (0)