Skip to content

Commit f920564

Browse files
committed
jsch action is implemented.
1 parent 910f3a1 commit f920564

File tree

6 files changed

+80
-52
lines changed

6 files changed

+80
-52
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://"
@@ -6029,6 +6030,13 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb,
60296030
"request has been filtered out via http table",
60306031
HTTP2_ECODE_PROTO);
60316032
}
6033+
if (res.type == TFW_HTTP_RES_JSCH) {
6034+
req->need_jsch = true;
6035+
req->vhost = res.vhost;
6036+
}
6037+
else {
6038+
req->need_jsch = is_jsch_global;
6039+
}
60326040
if (res.type == TFW_HTTP_RES_VHOST) {
60336041
req->vhost = res.vhost;
60346042
}
@@ -6134,37 +6142,39 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb,
61346142
* to GET. We should send js challenge to the client because the real
61356143
* method, expected by the client is GET.
61366144
*/
6137-
switch (tfw_http_sess_obtain(req)) {
6138-
case TFW_HTTP_SESS_SUCCESS:
6139-
break;
6145+
if (req->need_jsch) {
6146+
switch (tfw_http_sess_obtain(req)) {
6147+
case TFW_HTTP_SESS_SUCCESS:
6148+
break;
61406149

6141-
case TFW_HTTP_SESS_REDIRECT_NEED:
6142-
/* Response is built and stored in @req->resp. */
6143-
break;
6150+
case TFW_HTTP_SESS_REDIRECT_NEED:
6151+
/* Response is built and stored in @req->resp. */
6152+
break;
61446153

6145-
case TFW_HTTP_SESS_VIOLATE:
6146-
TFW_INC_STAT_BH(clnt.msgs_filtout);
6147-
return tfw_http_req_parse_block(req, 403, NULL,
6148-
HTTP2_ECODE_PROTO);
6154+
case TFW_HTTP_SESS_VIOLATE:
6155+
TFW_INC_STAT_BH(clnt.msgs_filtout);
6156+
return tfw_http_req_parse_block(req, 403, NULL,
6157+
HTTP2_ECODE_PROTO);
61496158

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

6160-
case TFW_HTTP_SESS_FAILURE:
6161-
TFW_INC_STAT_BH(clnt.msgs_otherr);
6162-
return tfw_http_req_parse_drop_with_fin(req, 500,
6163-
"request dropped: internal error"
6164-
" in Sticky module",
6165-
HTTP2_ECODE_PROTO);
6166-
default:
6167-
BUG();
6169+
case TFW_HTTP_SESS_FAILURE:
6170+
TFW_INC_STAT_BH(clnt.msgs_otherr);
6171+
return tfw_http_req_parse_drop_with_fin(req, 500,
6172+
"request dropped: internal error"
6173+
" in Sticky module",
6174+
HTTP2_ECODE_PROTO);
6175+
default:
6176+
BUG();
6177+
}
61686178
}
61696179

61706180
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 & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,19 @@ tfw_http_sess_resp_process(TfwHttpResp *resp, bool cache)
588588
{
589589
return 0;
590590
}
591-
BUG_ON(!req->sess);
592-
593-
/*
594-
* RFC 6265 4.1.1 and 4.1.2 says that we should not set session cookie
595-
* if it's not necessary. Since client didn't send up the cookie and
596-
* it seems that we don't enforce them, we can just set the cookie in
597-
* each response forwarded to the client.
598-
*/
599-
if (test_bit(TFW_HTTP_B_HAS_STICKY, req->flags))
600-
return 0;
601-
return tfw_http_sticky_add(resp, cache);
591+
if (req->need_jsch) {
592+
BUG_ON(!req->sess);
593+
/*
594+
* RFC 6265 4.1.1 and 4.1.2 says that we should not set session cookie
595+
* if it's not necessary. Since client didn't send up the cookie and
596+
* it seems that we don't enforce them, we can just set the cookie in
597+
* each response forwarded to the client.
598+
*/
599+
if (test_bit(TFW_HTTP_B_HAS_STICKY, req->flags))
600+
return 0;
601+
return tfw_http_sticky_add(resp, cache);
602+
}
603+
return 0;
602604
}
603605

604606
/**
@@ -666,6 +668,8 @@ tfw_http_sess_check_jsch(StickyVal *sv, TfwHttpReq* req)
666668
{
667669
unsigned long min_time;
668670
TfwCfgJsCh *js_ch = req->vhost->cookie->js_challenge;
671+
if (!req->need_jsch)
672+
return 0;
669673

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

862868
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)