Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/uipc_ktls.c
Show First 20 Lines • Show All 1,008 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
ktls_enable_rx(struct socket *so, struct tls_enable *en) | ktls_enable_rx(struct socket *so, struct tls_enable *en) | ||||
{ | { | ||||
struct ktls_session *tls; | struct ktls_session *tls; | ||||
int error; | int error; | ||||
if (!ktls_offload_enable) | if (!ktls_offload_enable) | ||||
return (ENOTSUP); | return (ENOTSUP); | ||||
if (SOLISTENING(so)) | |||||
return (EINVAL); | |||||
counter_u64_add(ktls_offload_enable_calls, 1); | counter_u64_add(ktls_offload_enable_calls, 1); | ||||
/* | /* | ||||
jhb: style nit: Blank line before the block comment. I think it's also better if this is before the… | |||||
Done Inline ActionsFixed. Wasn't sure about doing the check before or after the ktls_offload_enable_calls counter update, since other error checking is done after it... tuexen: Fixed. Wasn't sure about doing the check before or after the `ktls_offload_enable_calls`… | |||||
* This should always be true since only the TCP socket option | * This should always be true since only the TCP socket option | ||||
* invokes this function. | * invokes this function. | ||||
*/ | */ | ||||
if (so->so_proto->pr_protocol != IPPROTO_TCP) | if (so->so_proto->pr_protocol != IPPROTO_TCP) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* XXX: Don't overwrite existing sessions. We should permit | * XXX: Don't overwrite existing sessions. We should permit | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
ktls_enable_tx(struct socket *so, struct tls_enable *en) | ktls_enable_tx(struct socket *so, struct tls_enable *en) | ||||
{ | { | ||||
struct ktls_session *tls; | struct ktls_session *tls; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
int error; | int error; | ||||
if (!ktls_offload_enable) | if (!ktls_offload_enable) | ||||
return (ENOTSUP); | return (ENOTSUP); | ||||
if (SOLISTENING(so)) | |||||
return (EINVAL); | |||||
counter_u64_add(ktls_offload_enable_calls, 1); | counter_u64_add(ktls_offload_enable_calls, 1); | ||||
/* | /* | ||||
Not Done Inline ActionsSame thoughts here. jhb: Same thoughts here. | |||||
Done Inline ActionsAlso fixed. tuexen: Also fixed. | |||||
* This should always be true since only the TCP socket option | * This should always be true since only the TCP socket option | ||||
* invokes this function. | * invokes this function. | ||||
*/ | */ | ||||
if (so->so_proto->pr_protocol != IPPROTO_TCP) | if (so->so_proto->pr_protocol != IPPROTO_TCP) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* XXX: Don't overwrite existing sessions. We should permit | * XXX: Don't overwrite existing sessions. We should permit | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
ktls_get_rx_mode(struct socket *so) | ktls_get_rx_mode(struct socket *so) | ||||
{ | { | ||||
struct ktls_session *tls; | struct ktls_session *tls; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
int mode; | int mode; | ||||
if (SOLISTENING(so)) | |||||
return (EINVAL); | |||||
inp = so->so_pcb; | inp = so->so_pcb; | ||||
INP_WLOCK_ASSERT(inp); | INP_WLOCK_ASSERT(inp); | ||||
SOCKBUF_LOCK(&so->so_rcv); | SOCKBUF_LOCK(&so->so_rcv); | ||||
tls = so->so_rcv.sb_tls_info; | tls = so->so_rcv.sb_tls_info; | ||||
if (tls == NULL) | if (tls == NULL) | ||||
mode = TCP_TLS_MODE_NONE; | mode = TCP_TLS_MODE_NONE; | ||||
else | else | ||||
mode = tls->mode; | mode = tls->mode; | ||||
SOCKBUF_UNLOCK(&so->so_rcv); | SOCKBUF_UNLOCK(&so->so_rcv); | ||||
return (mode); | return (mode); | ||||
} | } | ||||
int | int | ||||
ktls_get_tx_mode(struct socket *so) | ktls_get_tx_mode(struct socket *so) | ||||
{ | { | ||||
struct ktls_session *tls; | struct ktls_session *tls; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
int mode; | int mode; | ||||
if (SOLISTENING(so)) | |||||
return (EINVAL); | |||||
inp = so->so_pcb; | inp = so->so_pcb; | ||||
INP_WLOCK_ASSERT(inp); | INP_WLOCK_ASSERT(inp); | ||||
SOCKBUF_LOCK(&so->so_snd); | SOCKBUF_LOCK(&so->so_snd); | ||||
tls = so->so_snd.sb_tls_info; | tls = so->so_snd.sb_tls_info; | ||||
if (tls == NULL) | if (tls == NULL) | ||||
mode = TCP_TLS_MODE_NONE; | mode = TCP_TLS_MODE_NONE; | ||||
else | else | ||||
mode = tls->mode; | mode = tls->mode; | ||||
SOCKBUF_UNLOCK(&so->so_snd); | SOCKBUF_UNLOCK(&so->so_snd); | ||||
return (mode); | return (mode); | ||||
} | } | ||||
/* | /* | ||||
* Switch between SW and ifnet TLS sessions as requested. | * Switch between SW and ifnet TLS sessions as requested. | ||||
*/ | */ | ||||
int | int | ||||
ktls_set_tx_mode(struct socket *so, int mode) | ktls_set_tx_mode(struct socket *so, int mode) | ||||
{ | { | ||||
struct ktls_session *tls, *tls_new; | struct ktls_session *tls, *tls_new; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
int error; | int error; | ||||
if (SOLISTENING(so)) | |||||
return (EINVAL); | |||||
switch (mode) { | switch (mode) { | ||||
case TCP_TLS_MODE_SW: | case TCP_TLS_MODE_SW: | ||||
case TCP_TLS_MODE_IFNET: | case TCP_TLS_MODE_IFNET: | ||||
break; | break; | ||||
default: | default: | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 959 Lines • Show Last 20 Lines |
style nit: Blank line before the block comment. I think it's also better if this is before the ktls_offload_enable_calls counter update.