| 912 | } |
| 913 | |
| 914 | static int |
| 915 | ktls_try_sw(struct socket *so, struct ktls_session *tls, int direction) |
| 916 | { |
| 917 | struct rm_priotracker prio; |
| 918 | struct ktls_crypto_backend *be; |
| 919 | |
| 920 | /* |
| 921 | * Choose the best software crypto backend. Backends are |
| 922 | * stored in sorted priority order (larget value == most |
| 923 | * important at the head of the list), so this just stops on |
| 924 | * the first backend that claims the session by returning |
| 925 | * success. |
| 926 | */ |
| 927 | if (ktls_allow_unload) |
| 928 | rm_rlock(&ktls_backends_lock, &prio); |
| 929 | LIST_FOREACH(be, &ktls_backends, next) { |
| 930 | if (be->try(so, tls, direction) == 0) |
| 931 | break; |
| 932 | KASSERT(tls->cipher == NULL, |
| 933 | ("ktls backend leaked a cipher pointer")); |
| 934 | } |
| 935 | if (be != NULL) { |
| 936 | if (ktls_allow_unload) |
| 937 | be->use_count++; |
| 938 | tls->be = be; |
| 939 | } |
| 940 | if (ktls_allow_unload) |
| 941 | rm_runlock(&ktls_backends_lock, &prio); |
| 942 | if (be == NULL) |
| 943 | return (EOPNOTSUPP); |
| 944 | tls->mode = TCP_TLS_MODE_SW; |
| 945 | switch (tls->params.cipher_algorithm) { |
| 946 | case CRYPTO_AES_CBC: |
| 947 | counter_u64_add(ktls_sw_cbc, 1); |
| 948 | break; |
| 949 | case CRYPTO_AES_NIST_GCM_16: |
| 950 | counter_u64_add(ktls_sw_gcm, 1); |
| 951 | break; |
| 952 | } |
| 953 | return (0); |
| 954 | } |
| 955 | |
| 956 | /* |
| 957 | * KTLS RX stores data in the socket buffer as a list of TLS records, |
no test coverage detected