]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - net/tls/tls_main.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux.git] / net / tls / tls_main.c
index df921a2904b9b5b96acab53e52fa66090a900660..7e546b8ec0004304d263e6b289317c6a2d70a4a4 100644 (file)
@@ -208,6 +208,26 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
        return tls_push_sg(sk, ctx, sg, offset, flags);
 }
 
+bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
+{
+       struct scatterlist *sg;
+
+       sg = ctx->partially_sent_record;
+       if (!sg)
+               return false;
+
+       while (1) {
+               put_page(sg_page(sg));
+               sk_mem_uncharge(sk, sg->length);
+
+               if (sg_is_last(sg))
+                       break;
+               sg++;
+       }
+       ctx->partially_sent_record = NULL;
+       return true;
+}
+
 static void tls_write_space(struct sock *sk)
 {
        struct tls_context *ctx = tls_get_ctx(sk);
@@ -267,6 +287,10 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
                kfree(ctx->tx.rec_seq);
                kfree(ctx->tx.iv);
                tls_sw_free_resources_tx(sk);
+#ifdef CONFIG_TLS_DEVICE
+       } else if (ctx->tx_conf == TLS_HW) {
+               tls_device_free_resources_tx(sk);
+#endif
        }
 
        if (ctx->rx_conf == TLS_SW) {
@@ -469,27 +493,32 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
 
        switch (crypto_info->cipher_type) {
        case TLS_CIPHER_AES_GCM_128:
+               optsize = sizeof(struct tls12_crypto_info_aes_gcm_128);
+               break;
        case TLS_CIPHER_AES_GCM_256: {
-               optsize = crypto_info->cipher_type == TLS_CIPHER_AES_GCM_128 ?
-                       sizeof(struct tls12_crypto_info_aes_gcm_128) :
-                       sizeof(struct tls12_crypto_info_aes_gcm_256);
-               if (optlen != optsize) {
-                       rc = -EINVAL;
-                       goto err_crypto_info;
-               }
-               rc = copy_from_user(crypto_info + 1, optval + sizeof(*crypto_info),
-                                   optlen - sizeof(*crypto_info));
-               if (rc) {
-                       rc = -EFAULT;
-                       goto err_crypto_info;
-               }
+               optsize = sizeof(struct tls12_crypto_info_aes_gcm_256);
                break;
        }
+       case TLS_CIPHER_AES_CCM_128:
+               optsize = sizeof(struct tls12_crypto_info_aes_ccm_128);
+               break;
        default:
                rc = -EINVAL;
                goto err_crypto_info;
        }
 
+       if (optlen != optsize) {
+               rc = -EINVAL;
+               goto err_crypto_info;
+       }
+
+       rc = copy_from_user(crypto_info + 1, optval + sizeof(*crypto_info),
+                           optlen - sizeof(*crypto_info));
+       if (rc) {
+               rc = -EFAULT;
+               goto err_crypto_info;
+       }
+
        if (tx) {
 #ifdef CONFIG_TLS_DEVICE
                rc = tls_set_device_offload(sk, ctx);