Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Eliminate if inside br_low and write
Browse files Browse the repository at this point in the history
  • Loading branch information
baluchicken committed Mar 1, 2024
1 parent acda7b0 commit 7881508
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ jobs:
sudo modprobe camblet
sudo dmesg -T
- name: Setup upterm session
uses: lhotari/action-upterm@v1
with:
## limits ssh access and adds the ssh public key for the user which triggered the workflow
limit-access-to-actor: true
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
# with:
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow
# limit-access-to-actor: true

- name: Run proxy-wasm smoke test
working-directory: camblet-driver
Expand Down
26 changes: 13 additions & 13 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ struct camblet_socket

tcp_connection_context *conn_ctx;

bool handshake_completed;
camblet_sendmsg_t *br_low_sendmsg;
camblet_recvmsg_t *br_low_recvmsg;

};

static int get_read_buffer_capacity(camblet_socket *s);
Expand Down Expand Up @@ -402,7 +404,6 @@ static camblet_socket *camblet_new_server_socket(struct sock *sock, opa_socket_c
s->parameters = kzalloc(sizeof(csr_parameters), GFP_KERNEL);
s->read_buffer = buffer_new(16 * 1024);
s->write_buffer = buffer_new(16 * 1024);
s->handshake_completed = false;

s->sock = sock;
s->opa_socket_ctx = opa_socket_ctx;
Expand Down Expand Up @@ -530,6 +531,12 @@ static int ensure_tls_handshake(camblet_socket *s, struct msghdr *msg)
br_ssl_client_reset(s->cc, s->hostname, false);
}

// Initialize the low_read and low_write functions
// with tcp_sendmsg and recvmsg. These will be used
// by BearSSL to read and write data to socket.
s->br_low_recvmsg = plain_recvmsg;
s->br_low_sendmsg = plain_sendmsg;

ret = br_sslio_flush(&s->ioc);
if (ret == 0)
{
Expand Down Expand Up @@ -979,7 +986,8 @@ static int configure_ktls_sock(camblet_socket *s)
br_ssl_engine_context *ec = get_ssl_engine_context(s);
ec->out.vtable = &br_sslrec_out_clear_vtable;
ec->incrypt = 0;
s->handshake_completed= true;
s->br_low_recvmsg=ktls_recvmsg;
s->br_low_sendmsg=ktls_sendmsg;
}

s->sendmsg = bearssl_sendmsg;
Expand Down Expand Up @@ -1464,15 +1472,7 @@ static command_answer *prepare_opa_input(const tcp_connection_context *conn_ctx,
static int br_low_read(void *ctx, unsigned char *buf, size_t len)
{
camblet_socket *s = (camblet_socket *)ctx;
int ret = 0;
if (s->handshake_completed && ktls_available)
{
ret = ktls_recvmsg(s, buf, len, 0);
}
else
{
ret = plain_recvmsg(s, buf, len, 0);
}
int ret = s->br_low_recvmsg(s, buf, len, 0);
// BearSSL doesn't like 0 return value, but it's not an error
// so we return -1 instead and set sock_closed to true to
// indicate that the socket is closed without errors.
Expand All @@ -1490,7 +1490,7 @@ static int br_low_read(void *ctx, unsigned char *buf, size_t len)
static int br_low_write(void *ctx, const unsigned char *buf, size_t len)
{
camblet_socket *s = (camblet_socket *)ctx;
return s->handshake_completed && ktls_available ? ktls_sendmsg(s, buf, len) : plain_sendmsg(s, buf, len);
return s->br_low_sendmsg(s, buf, len);
}

opa_socket_context enriched_socket_eval(const tcp_connection_context *conn_ctx, direction direction, struct sock *sk, int port)
Expand Down

0 comments on commit 7881508

Please sign in to comment.