Skip to content

Commit 14766c3

Browse files
committed
jsch action is implemented.
1 parent 930ba7d commit 14766c3

File tree

6 files changed

+80
-51
lines changed

6 files changed

+80
-51
lines changed

fw/http.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static struct {
150150
* here, because it refers to HTTP layer.
151151
*/
152152
unsigned int max_header_list_size = 0;
153+
bool is_jsch_global = true;
153154

154155
#define S_CRLFCRLF "\r\n\r\n"
155156
#define S_HTTP "http://"
@@ -6034,6 +6035,13 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb,
60346035
"request has been filtered out via http table",
60356036
HTTP2_ECODE_PROTO);
60366037
}
6038+
if (res.type == TFW_HTTP_RES_JSCH) {
6039+
req->need_jsch = true;
6040+
req->vhost = res.vhost;
6041+
}
6042+
else {
6043+
req->need_jsch = is_jsch_global;
6044+
}
60376045
if (res.type == TFW_HTTP_RES_VHOST) {
60386046
req->vhost = res.vhost;
60396047
}
@@ -6139,37 +6147,39 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb,
61396147
* to GET. We should send js challenge to the client because the real
61406148
* method, expected by the client is GET.
61416149
*/
6142-
switch (tfw_http_sess_obtain(req)) {
6143-
case TFW_HTTP_SESS_SUCCESS:
6144-
break;
6150+
if (req->need_jsch) {
6151+
switch (tfw_http_sess_obtain(req)) {
6152+
case TFW_HTTP_SESS_SUCCESS:
6153+
break;
61456154

6146-
case TFW_HTTP_SESS_REDIRECT_NEED:
6147-
/* Response is built and stored in @req->resp. */
6148-
break;
6155+
case TFW_HTTP_SESS_REDIRECT_NEED:
6156+
/* Response is built and stored in @req->resp. */
6157+
break;
61496158

6150-
case TFW_HTTP_SESS_VIOLATE:
6151-
TFW_INC_STAT_BH(clnt.msgs_filtout);
6152-
return tfw_http_req_parse_block(req, 403, NULL,
6153-
HTTP2_ECODE_PROTO);
6159+
case TFW_HTTP_SESS_VIOLATE:
6160+
TFW_INC_STAT_BH(clnt.msgs_filtout);
6161+
return tfw_http_req_parse_block(req, 403, NULL,
6162+
HTTP2_ECODE_PROTO);
61546163

6155-
case TFW_HTTP_SESS_JS_NOT_SUPPORTED:
6156-
/*
6157-
* Requested resource can't be challenged, try service it
6158-
* from cache.
6159-
*/
6160-
T_DBG("Can't send JS challenge for request since a "
6161-
"non-challengeable resource (e.g. image) was requested");
6162-
__set_bit(TFW_HTTP_B_JS_NOT_SUPPORTED, req->flags);
6163-
break;
6164+
case TFW_HTTP_SESS_JS_NOT_SUPPORTED:
6165+
/*
6166+
* Requested resource can't be challenged, try service it
6167+
* from cache.
6168+
*/
6169+
T_DBG("Can't send JS challenge for request since a "
6170+
"non-challengeable resource (e.g. image) was requested");
6171+
__set_bit(TFW_HTTP_B_JS_NOT_SUPPORTED, req->flags);
6172+
break;
61646173

6165-
case TFW_HTTP_SESS_FAILURE:
6166-
TFW_INC_STAT_BH(clnt.msgs_otherr);
6167-
return tfw_http_req_parse_drop_with_fin(req, 500,
6168-
"request dropped: internal error"
6169-
" in Sticky module",
6170-
HTTP2_ECODE_PROTO);
6171-
default:
6172-
BUG();
6174+
case TFW_HTTP_SESS_FAILURE:
6175+
TFW_INC_STAT_BH(clnt.msgs_otherr);
6176+
return tfw_http_req_parse_drop_with_fin(req, 500,
6177+
"request dropped: internal error"
6178+
" in Sticky module",
6179+
HTTP2_ECODE_PROTO);
6180+
default:
6181+
BUG();
6182+
}
61736183
}
61746184

61756185
if (TFW_MSG_H2(req))

fw/http.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ struct tfw_http_req_t {
400400
unsigned char method_override;
401401
unsigned int header_list_sz;
402402
unsigned int headers_cnt;
403+
bool need_jsch;
403404
};
404405

405406
#define TFW_IDX_BITS 24
@@ -722,6 +723,7 @@ typedef void (*tfw_http_cache_cb_t)(TfwHttpMsg *);
722723
(TFW_MSG_H2(hmmsg) ? HTTP2_EXTRA_HDR_OVERHEAD : 0)
723724

724725
extern unsigned int max_header_list_size;
726+
extern bool is_jsch_global;
725727

726728
/* External HTTP functions. */
727729
int tfw_http_msg_process(TfwConn *conn, struct sk_buff *skb,

fw/http_match.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef enum {
7676
TFW_HTTP_MATCH_ACT_BLOCK,
7777
TFW_HTTP_MATCH_ACT_FLAG,
7878
TFW_HTTP_MATCH_ACT_CACHE_TTL,
79+
TFW_HTTP_MATCH_ACT_JSCH,
7980
_TFW_HTTP_MATCH_ACT_COUNT
8081
} tfw_http_rule_act_t;
8182

fw/http_sess.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,20 @@ tfw_http_sess_resp_process(TfwHttpResp *resp, bool cache,
590590
{
591591
return 0;
592592
}
593-
BUG_ON(!req->sess);
593+
if (req->need_jsch) {
594+
BUG_ON(!req->sess);
594595

595-
/*
596-
* RFC 6265 4.1.1 and 4.1.2 says that we should not set session cookie
597-
* if it's not necessary. Since client didn't send up the cookie and
598-
* it seems that we don't enforce them, we can just set the cookie in
599-
* each response forwarded to the client.
600-
*/
601-
if (test_bit(TFW_HTTP_B_HAS_STICKY, req->flags))
602-
return 0;
603-
return tfw_http_sticky_add(resp, cache, stream_id);
596+
/*
597+
* RFC 6265 4.1.1 and 4.1.2 says that we should not set session cookie
598+
* if it's not necessary. Since client didn't send up the cookie and
599+
* it seems that we don't enforce them, we can just set the cookie in
600+
* each response forwarded to the client.
601+
*/
602+
if (test_bit(TFW_HTTP_B_HAS_STICKY, req->flags))
603+
return 0;
604+
return tfw_http_sticky_add(resp, cache, stream_id);
605+
}
606+
return 0;
604607
}
605608

606609
/**
@@ -668,6 +671,8 @@ tfw_http_sess_check_jsch(StickyVal *sv, TfwHttpReq* req)
668671
{
669672
unsigned long min_time;
670673
TfwCfgJsCh *js_ch = req->vhost->cookie->js_challenge;
674+
if (!req->need_jsch)
675+
return 0;
671676

672677
if (!js_ch)
673678
return 0;
@@ -845,20 +850,22 @@ tfw_http_sess_obtain(TfwHttpReq *req)
845850
* We leave this for administrator decision or more progressive DDoS
846851
* mitigation techniques.
847852
*/
848-
r = tfw_http_sticky_req_process(req, sv, c_val);
849-
switch (r) {
850-
case TFW_HTTP_SESS_SUCCESS:
851-
break;
852-
case TFW_HTTP_SESS_FAILURE:
853-
return r;
854-
default:
855-
/*
856-
* Any js challenge processing error: cookie not found
857-
* or invalid or request comes not in time. We increment
858-
* max_misses and restart js challenge.
859-
*/
860-
BUG_ON(r < __TFW_HTTP_SESS_PUB_CODE_MAX);
861-
return tfw_http_sticky_challenge_start(req);
853+
if (req->need_jsch) {
854+
r = tfw_http_sticky_req_process(req, sv, c_val);
855+
switch (r) {
856+
case TFW_HTTP_SESS_SUCCESS:
857+
break;
858+
case TFW_HTTP_SESS_FAILURE:
859+
return r;
860+
default:
861+
/*
862+
* Any js challenge processing error: cookie not found
863+
* or invalid or request comes not in time. We increment
864+
* max_misses and restart js challenge.
865+
*/
866+
BUG_ON(r < __TFW_HTTP_SESS_PUB_CODE_MAX);
867+
return tfw_http_sticky_challenge_start(req);
868+
}
862869
}
863870

864871
if (req->vhost->cookie->learn) {

fw/http_tbl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ tfw_http_tbl_scan(TfwMsg *msg, TfwHttpTable *table, TfwHttpActionResult *action)
156156
return 0;
157157
case TFW_HTTP_MATCH_ACT_BLOCK:
158158
return -1;
159+
case TFW_HTTP_MATCH_ACT_JSCH:
160+
action->type = TFW_HTTP_RES_JSCH;
161+
action->vhost = tfw_vhost_lookup_default();
162+
return 0;
159163

160164
default:
161165
action->type = TFW_HTTP_RES_VHOST;
@@ -499,6 +503,10 @@ tfw_cfgop_http_rule(TfwCfgSpec *cs, TfwCfgEntry *e)
499503
rule->act.type = TFW_HTTP_MATCH_ACT_CACHE_TTL;
500504
rule->act.cache_ttl = act_val_parsed;
501505
}
506+
else if (!strcasecmp(action, "jsch")) {
507+
is_jsch_global = false;
508+
rule->act.type = TFW_HTTP_MATCH_ACT_JSCH;
509+
}
502510
else if (action && action_val &&
503511
!tfw_cfg_parse_uint(action, &rule->act.redir.resp_code))
504512
{

fw/http_tbl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#define TFW_HTTP_RES_VHOST 0
3232
#define TFW_HTTP_RES_REDIR 1
33+
#define TFW_HTTP_RES_JSCH 2
3334

3435
typedef struct {
3536
TfwStr url;

0 commit comments

Comments
 (0)