Skip to content

Commit 01fee37

Browse files
committed
fixup! Upgrade connection to websocket and provision new connection
Signed-off-by: Aleksey Mikhaylov <[email protected]>
1 parent 8223998 commit 01fee37

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

fw/http.c

+38-23
Original file line numberDiff line numberDiff line change
@@ -5919,6 +5919,42 @@ tfw_http_resp_terminate(TfwHttpMsg *hm)
59195919
tfw_http_resp_cache(hm);
59205920
}
59215921

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+
59225958
/**
59235959
* @return zero on success and negative value otherwise.
59245960
* 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)
61116147
&& test_bit(TFW_HTTP_B_UPGRADE_WEBSOCKET, hmresp->flags)
61126148
&& resp->status == 101))
61136149
{
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))
61286152
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);
61386153
}
61396154

61406155
/*

fw/server.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ int tfw_sched_register(TfwScheduler *sched);
345345
void tfw_sched_unregister(TfwScheduler *sched);
346346

347347
/* Public sock_srv routings */
348-
void tfw_sock_srv_connect_try(TfwSrvConn *srv_conn);
349-
void tfw_sock_srv_conn_activate(TfwServer *srv, TfwSrvConn *srv_conn);
348+
void tfw_sock_srv_connect_one(TfwServer *srv, TfwSrvConn *srv_conn);
350349
TfwSrvConn *tfw_sock_srv_new_conn(TfwServer *srv);
351350

352351
#endif /* __SERVER_H__ */

fw/sock_srv.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,24 @@ tfw_sock_srv_disconnect(TfwConn *conn)
524524
* not-yet-established connections in the TfwServer->conn_list.
525525
*/
526526

527+
static inline void
528+
tfw_sock_srv_conn_activate(TfwServer *srv, TfwSrvConn *srv_conn)
529+
{
530+
set_bit(TFW_CONN_B_ACTIVE, &srv_conn->flags);
531+
}
532+
527533
/*
528534
* Get reference to server and mark the connection as active, which means
529535
* that server must be put during connection release procedure.
536+
*
537+
* And start connection attempt.
530538
*/
531539
void
532-
tfw_sock_srv_conn_activate(TfwServer *srv, TfwSrvConn *srv_conn)
540+
tfw_sock_srv_connect_one(TfwServer * srv, TfwSrvConn *srv_conn)
533541
{
534542
tfw_server_get(srv);
535-
set_bit(TFW_CONN_B_ACTIVE, &srv_conn->flags);
543+
tfw_sock_srv_conn_activate(srv, srv_conn);
544+
tfw_sock_srv_connect_try_later(srv_conn);
536545
}
537546

538547
static void
@@ -549,8 +558,7 @@ tfw_sock_srv_connect_srv(TfwServer *srv)
549558
* that parallel execution can't happen with the same socket.
550559
*/
551560
list_for_each_entry(srv_conn, &srv->conn_list, list) {
552-
tfw_sock_srv_conn_activate(srv, srv_conn);
553-
tfw_sock_srv_connect_try_later(srv_conn);
561+
tfw_sock_srv_connect_one(srv, srv_conn);
554562
}
555563
}
556564

@@ -652,8 +660,7 @@ tfw_sock_srv_append_conns_n(TfwServer *srv, size_t conn_n)
652660
for (i = 0; i < conn_n; ++i) {
653661
if (!(srv_conn = tfw_sock_srv_new_conn(srv)))
654662
return -ENOMEM;
655-
tfw_sock_srv_conn_activate(srv, srv_conn);
656-
tfw_sock_srv_connect_try_later(srv_conn);
663+
tfw_sock_srv_connect_one(srv, srv_conn);
657664
tfw_srv_loop_sched_rcu();
658665
}
659666

0 commit comments

Comments
 (0)