@@ -5919,6 +5919,42 @@ tfw_http_resp_terminate(TfwHttpMsg *hm)
5919
5919
tfw_http_resp_cache (hm );
5920
5920
}
5921
5921
5922
+ /**
5923
+ * Does websocket upgrade procedure.
5924
+ *
5925
+ * Marks current server and client connection as websocket connection. Starts
5926
+ * reconnection with backend to restore full backend connection count.
5927
+ *
5928
+ * @return zero on success and negative otherwise
5929
+ */
5930
+ static int
5931
+ tfw_http_websocket_upgrade (TfwHttpResp * resp )
5932
+ {
5933
+ TfwServer * srv = (TfwServer * )resp -> conn -> peer ;
5934
+ TfwSrvConn * srv_conn ;
5935
+
5936
+ /* Cannot proceed with upgrade websocket due to error
5937
+ * in creation of new http connection. While it will not be
5938
+ * inherently erroneous to upgrade existing connection, but
5939
+ * we would pay for it with essentially dropping connection with
5940
+ * server. Better just drop upgrade request and reestablish connection.
5941
+ */
5942
+ if (!(srv_conn = tfw_sock_srv_new_conn (srv ))) {
5943
+ tfw_http_conn_error_log (resp -> conn ,
5944
+ "Can't create new connection for "
5945
+ "websocket upgrade response" );
5946
+ return TFW_BLOCK ;
5947
+ }
5948
+
5949
+ set_bit (TFW_CONN_B_UNSCHED , & ((TfwSrvConn * )resp -> conn )-> flags );
5950
+
5951
+ tfw_sock_srv_connect_one (srv , srv_conn );
5952
+
5953
+ srv -> sg -> sched -> upd_srv (srv );
5954
+
5955
+ return TFW_PASS ;
5956
+ }
5957
+
5922
5958
/**
5923
5959
* @return zero on success and negative value otherwise.
5924
5960
* TODO enter the function depending on current GFSM state.
@@ -6111,30 +6147,9 @@ tfw_http_resp_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb)
6111
6147
&& test_bit (TFW_HTTP_B_UPGRADE_WEBSOCKET , hmresp -> flags )
6112
6148
&& resp -> status == 101 ))
6113
6149
{
6114
- TfwServer * srv = (TfwServer * )resp -> conn -> peer ;
6115
- TfwSrvConn * srv_conn ;
6116
-
6117
- /* Cannot proceed with upgrade websocket due to error
6118
- * in creation of new http connection. While it will not be
6119
- * inherently erroneous to upgrade existing connection, but
6120
- * we would pay for it with essentially dropping connection with
6121
- * server. Better just drop upgrade request and
6122
- * reestablish connection.
6123
- */
6124
- if (!(srv_conn = tfw_sock_srv_new_conn (srv ))) {
6125
- tfw_http_conn_error_log (conn , "Can't create new "
6126
- "connection for websocket"
6127
- " upgrade response" );
6150
+ r = tfw_http_websocket_upgrade (resp );
6151
+ if (unlikely (r < TFW_PASS ))
6128
6152
return TFW_BLOCK ;
6129
- }
6130
-
6131
- set_bit (TFW_CONN_B_UNSCHED ,
6132
- & ((TfwSrvConn * )hmresp -> conn )-> flags );
6133
-
6134
- tfw_sock_srv_conn_activate (srv , srv_conn );
6135
- tfw_sock_srv_connect_try (srv_conn );
6136
-
6137
- srv -> sg -> sched -> upd_srv (srv );
6138
6153
}
6139
6154
6140
6155
/*
0 commit comments