This commit is a pure refactor. Its purpose is to lift code that needs to be called from both initial tx establishment and tx rekeying into dedicated functions. Signed-off-by: Daniel Zahka --- net/psp/psp_sock.c | 94 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c index 3a8abd023f99..9b0ecce8350f 100644 --- a/net/psp/psp_sock.c +++ b/net/psp/psp_sock.c @@ -187,12 +187,67 @@ static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas) return 0; } +static int +psp_pas_set_tx_key(struct psp_dev *psd, struct psp_assoc *pas, + struct psp_key_parsed *key, struct netlink_ext_ack *extack) +{ + struct psp_assoc *dummy; + int rc; + + /* Pass a fake association to drivers to make sure they don't + * try to store pointers to it. For re-keying we'll need to + * re-allocate the assoc structures. + */ + dummy = psp_assoc_dummy(pas); + if (!dummy) + return -ENOMEM; + + memcpy(&dummy->tx, key, sizeof(*key)); + rc = psp_dev_tx_key_add(psd, dummy, extack); + if (rc) + goto exit_free_dummy; + + memcpy(pas->drv_data, dummy->drv_data, psd->caps->assoc_drv_spc); + memcpy(&pas->tx, key, sizeof(*key)); + +exit_free_dummy: + kfree(dummy); + return rc; +} + +static int +psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, + struct psp_key_parsed *key, struct netlink_ext_ack *extack) +{ + struct inet_connection_sock *icsk; + int err; + + err = psp_sock_recv_queue_check(sk, pas); + if (err) { + NL_SET_ERR_MSG(extack, "Socket has incompatible segments already in the recv queue"); + return err; + } + + err = psp_pas_set_tx_key(psd, pas, key, extack); + if (err) + return err; + + WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit); + tcp_write_collapse_fence(sk); + pas->upgrade_seq = tcp_sk(sk)->rcv_nxt; + + icsk = inet_csk(sk); + icsk->icsk_ext_hdr_len += psp_sk_overhead(sk); + icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); + + return err; +} + int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, u32 version, struct psp_key_parsed *key, struct netlink_ext_ack *extack) { - struct inet_connection_sock *icsk; - struct psp_assoc *pas, *dummy; + struct psp_assoc *pas; int err; lock_sock(sk); @@ -220,40 +275,7 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, goto exit_unlock; } - err = psp_sock_recv_queue_check(sk, pas); - if (err) { - NL_SET_ERR_MSG(extack, "Socket has incompatible segments already in the recv queue"); - goto exit_unlock; - } - - /* Pass a fake association to drivers to make sure they don't - * try to store pointers to it. For re-keying we'll need to - * re-allocate the assoc structures. - */ - dummy = psp_assoc_dummy(pas); - if (!dummy) { - err = -ENOMEM; - goto exit_unlock; - } - - memcpy(&dummy->tx, key, sizeof(*key)); - err = psp_dev_tx_key_add(psd, dummy, extack); - if (err) - goto exit_free_dummy; - - memcpy(pas->drv_data, dummy->drv_data, psd->caps->assoc_drv_spc); - memcpy(&pas->tx, key, sizeof(*key)); - - WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit); - tcp_write_collapse_fence(sk); - pas->upgrade_seq = tcp_sk(sk)->rcv_nxt; - - icsk = inet_csk(sk); - icsk->icsk_ext_hdr_len += psp_sk_overhead(sk); - icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); - -exit_free_dummy: - kfree(dummy); + err = psp_sock_set_tx_key(sk, psd, pas, key, extack); exit_unlock: release_sock(sk); return err; -- 2.47.3