Lines Matching refs:con
106 static int ceph_tcp_recv(struct ceph_connection *con) in ceph_tcp_recv() argument
110 dout("%s con %p %s %zu\n", __func__, con, in ceph_tcp_recv()
111 iov_iter_is_discard(&con->v2.in_iter) ? "discard" : "need", in ceph_tcp_recv()
112 iov_iter_count(&con->v2.in_iter)); in ceph_tcp_recv()
113 ret = do_recvmsg(con->sock, &con->v2.in_iter); in ceph_tcp_recv()
114 dout("%s con %p ret %d left %zu\n", __func__, con, ret, in ceph_tcp_recv()
115 iov_iter_count(&con->v2.in_iter)); in ceph_tcp_recv()
194 static int ceph_tcp_send(struct ceph_connection *con) in ceph_tcp_send() argument
198 dout("%s con %p have %zu try_sendpage %d\n", __func__, con, in ceph_tcp_send()
199 iov_iter_count(&con->v2.out_iter), con->v2.out_iter_sendpage); in ceph_tcp_send()
200 if (con->v2.out_iter_sendpage) in ceph_tcp_send()
201 ret = do_try_sendpage(con->sock, &con->v2.out_iter); in ceph_tcp_send()
203 ret = do_sendmsg(con->sock, &con->v2.out_iter); in ceph_tcp_send()
204 dout("%s con %p ret %d left %zu\n", __func__, con, ret, in ceph_tcp_send()
205 iov_iter_count(&con->v2.out_iter)); in ceph_tcp_send()
209 static void add_in_kvec(struct ceph_connection *con, void *buf, int len) in add_in_kvec() argument
211 BUG_ON(con->v2.in_kvec_cnt >= ARRAY_SIZE(con->v2.in_kvecs)); in add_in_kvec()
212 WARN_ON(!iov_iter_is_kvec(&con->v2.in_iter)); in add_in_kvec()
214 con->v2.in_kvecs[con->v2.in_kvec_cnt].iov_base = buf; in add_in_kvec()
215 con->v2.in_kvecs[con->v2.in_kvec_cnt].iov_len = len; in add_in_kvec()
216 con->v2.in_kvec_cnt++; in add_in_kvec()
218 con->v2.in_iter.nr_segs++; in add_in_kvec()
219 con->v2.in_iter.count += len; in add_in_kvec()
222 static void reset_in_kvecs(struct ceph_connection *con) in reset_in_kvecs() argument
224 WARN_ON(iov_iter_count(&con->v2.in_iter)); in reset_in_kvecs()
226 con->v2.in_kvec_cnt = 0; in reset_in_kvecs()
227 iov_iter_kvec(&con->v2.in_iter, READ, con->v2.in_kvecs, 0, 0); in reset_in_kvecs()
230 static void set_in_bvec(struct ceph_connection *con, const struct bio_vec *bv) in set_in_bvec() argument
232 WARN_ON(iov_iter_count(&con->v2.in_iter)); in set_in_bvec()
234 con->v2.in_bvec = *bv; in set_in_bvec()
235 iov_iter_bvec(&con->v2.in_iter, READ, &con->v2.in_bvec, 1, bv->bv_len); in set_in_bvec()
238 static void set_in_skip(struct ceph_connection *con, int len) in set_in_skip() argument
240 WARN_ON(iov_iter_count(&con->v2.in_iter)); in set_in_skip()
242 dout("%s con %p len %d\n", __func__, con, len); in set_in_skip()
243 iov_iter_discard(&con->v2.in_iter, READ, len); in set_in_skip()
246 static void add_out_kvec(struct ceph_connection *con, void *buf, int len) in add_out_kvec() argument
248 BUG_ON(con->v2.out_kvec_cnt >= ARRAY_SIZE(con->v2.out_kvecs)); in add_out_kvec()
249 WARN_ON(!iov_iter_is_kvec(&con->v2.out_iter)); in add_out_kvec()
250 WARN_ON(con->v2.out_zero); in add_out_kvec()
252 con->v2.out_kvecs[con->v2.out_kvec_cnt].iov_base = buf; in add_out_kvec()
253 con->v2.out_kvecs[con->v2.out_kvec_cnt].iov_len = len; in add_out_kvec()
254 con->v2.out_kvec_cnt++; in add_out_kvec()
256 con->v2.out_iter.nr_segs++; in add_out_kvec()
257 con->v2.out_iter.count += len; in add_out_kvec()
260 static void reset_out_kvecs(struct ceph_connection *con) in reset_out_kvecs() argument
262 WARN_ON(iov_iter_count(&con->v2.out_iter)); in reset_out_kvecs()
263 WARN_ON(con->v2.out_zero); in reset_out_kvecs()
265 con->v2.out_kvec_cnt = 0; in reset_out_kvecs()
267 iov_iter_kvec(&con->v2.out_iter, WRITE, con->v2.out_kvecs, 0, 0); in reset_out_kvecs()
268 con->v2.out_iter_sendpage = false; in reset_out_kvecs()
271 static void set_out_bvec(struct ceph_connection *con, const struct bio_vec *bv, in set_out_bvec() argument
274 WARN_ON(iov_iter_count(&con->v2.out_iter)); in set_out_bvec()
275 WARN_ON(con->v2.out_zero); in set_out_bvec()
277 con->v2.out_bvec = *bv; in set_out_bvec()
278 con->v2.out_iter_sendpage = zerocopy; in set_out_bvec()
279 iov_iter_bvec(&con->v2.out_iter, WRITE, &con->v2.out_bvec, 1, in set_out_bvec()
280 con->v2.out_bvec.bv_len); in set_out_bvec()
283 static void set_out_bvec_zero(struct ceph_connection *con) in set_out_bvec_zero() argument
285 WARN_ON(iov_iter_count(&con->v2.out_iter)); in set_out_bvec_zero()
286 WARN_ON(!con->v2.out_zero); in set_out_bvec_zero()
288 con->v2.out_bvec.bv_page = ceph_zero_page; in set_out_bvec_zero()
289 con->v2.out_bvec.bv_offset = 0; in set_out_bvec_zero()
290 con->v2.out_bvec.bv_len = min(con->v2.out_zero, (int)PAGE_SIZE); in set_out_bvec_zero()
291 con->v2.out_iter_sendpage = true; in set_out_bvec_zero()
292 iov_iter_bvec(&con->v2.out_iter, WRITE, &con->v2.out_bvec, 1, in set_out_bvec_zero()
293 con->v2.out_bvec.bv_len); in set_out_bvec_zero()
296 static void out_zero_add(struct ceph_connection *con, int len) in out_zero_add() argument
298 dout("%s con %p len %d\n", __func__, con, len); in out_zero_add()
299 con->v2.out_zero += len; in out_zero_add()
302 static void *alloc_conn_buf(struct ceph_connection *con, int len) in alloc_conn_buf() argument
306 dout("%s con %p len %d\n", __func__, con, len); in alloc_conn_buf()
308 if (WARN_ON(con->v2.conn_buf_cnt >= ARRAY_SIZE(con->v2.conn_bufs))) in alloc_conn_buf()
315 con->v2.conn_bufs[con->v2.conn_buf_cnt++] = buf; in alloc_conn_buf()
319 static void free_conn_bufs(struct ceph_connection *con) in free_conn_bufs() argument
321 while (con->v2.conn_buf_cnt) in free_conn_bufs()
322 kvfree(con->v2.conn_bufs[--con->v2.conn_buf_cnt]); in free_conn_bufs()
325 static void add_in_sign_kvec(struct ceph_connection *con, void *buf, int len) in add_in_sign_kvec() argument
327 BUG_ON(con->v2.in_sign_kvec_cnt >= ARRAY_SIZE(con->v2.in_sign_kvecs)); in add_in_sign_kvec()
329 con->v2.in_sign_kvecs[con->v2.in_sign_kvec_cnt].iov_base = buf; in add_in_sign_kvec()
330 con->v2.in_sign_kvecs[con->v2.in_sign_kvec_cnt].iov_len = len; in add_in_sign_kvec()
331 con->v2.in_sign_kvec_cnt++; in add_in_sign_kvec()
334 static void clear_in_sign_kvecs(struct ceph_connection *con) in clear_in_sign_kvecs() argument
336 con->v2.in_sign_kvec_cnt = 0; in clear_in_sign_kvecs()
339 static void add_out_sign_kvec(struct ceph_connection *con, void *buf, int len) in add_out_sign_kvec() argument
341 BUG_ON(con->v2.out_sign_kvec_cnt >= ARRAY_SIZE(con->v2.out_sign_kvecs)); in add_out_sign_kvec()
343 con->v2.out_sign_kvecs[con->v2.out_sign_kvec_cnt].iov_base = buf; in add_out_sign_kvec()
344 con->v2.out_sign_kvecs[con->v2.out_sign_kvec_cnt].iov_len = len; in add_out_sign_kvec()
345 con->v2.out_sign_kvec_cnt++; in add_out_sign_kvec()
348 static void clear_out_sign_kvecs(struct ceph_connection *con) in clear_out_sign_kvecs() argument
350 con->v2.out_sign_kvec_cnt = 0; in clear_out_sign_kvecs()
353 static bool con_secure(struct ceph_connection *con) in con_secure() argument
355 return con->v2.con_mode == CEPH_CON_MODE_SECURE; in con_secure()
564 static void encode_epilogue_plain(struct ceph_connection *con, bool aborted) in encode_epilogue_plain() argument
566 con->v2.out_epil.late_status = aborted ? FRAME_LATE_STATUS_ABORTED : in encode_epilogue_plain()
568 cpu_to_le32s(&con->v2.out_epil.front_crc); in encode_epilogue_plain()
569 cpu_to_le32s(&con->v2.out_epil.middle_crc); in encode_epilogue_plain()
570 cpu_to_le32s(&con->v2.out_epil.data_crc); in encode_epilogue_plain()
573 static void encode_epilogue_secure(struct ceph_connection *con, bool aborted) in encode_epilogue_secure() argument
575 memset(&con->v2.out_epil, 0, sizeof(con->v2.out_epil)); in encode_epilogue_secure()
576 con->v2.out_epil.late_status = aborted ? FRAME_LATE_STATUS_ABORTED : in encode_epilogue_secure()
638 static int verify_control_crc(struct ceph_connection *con) in verify_control_crc() argument
640 int ctrl_len = con->v2.in_desc.fd_lens[0]; in verify_control_crc()
643 WARN_ON(con->v2.in_kvecs[0].iov_len != ctrl_len); in verify_control_crc()
644 WARN_ON(con->v2.in_kvecs[1].iov_len != CEPH_CRC_LEN); in verify_control_crc()
646 crc = crc32c(-1, con->v2.in_kvecs[0].iov_base, ctrl_len); in verify_control_crc()
647 expected_crc = get_unaligned_le32(con->v2.in_kvecs[1].iov_base); in verify_control_crc()
657 static int verify_epilogue_crcs(struct ceph_connection *con, u32 front_crc, in verify_epilogue_crcs() argument
660 if (front_len(con->in_msg)) { in verify_epilogue_crcs()
661 con->in_front_crc = crc32c(-1, con->in_msg->front.iov_base, in verify_epilogue_crcs()
662 front_len(con->in_msg)); in verify_epilogue_crcs()
664 WARN_ON(!middle_len(con->in_msg) && !data_len(con->in_msg)); in verify_epilogue_crcs()
665 con->in_front_crc = -1; in verify_epilogue_crcs()
668 if (middle_len(con->in_msg)) in verify_epilogue_crcs()
669 con->in_middle_crc = crc32c(-1, in verify_epilogue_crcs()
670 con->in_msg->middle->vec.iov_base, in verify_epilogue_crcs()
671 middle_len(con->in_msg)); in verify_epilogue_crcs()
672 else if (data_len(con->in_msg)) in verify_epilogue_crcs()
673 con->in_middle_crc = -1; in verify_epilogue_crcs()
675 con->in_middle_crc = 0; in verify_epilogue_crcs()
677 if (!data_len(con->in_msg)) in verify_epilogue_crcs()
678 con->in_data_crc = 0; in verify_epilogue_crcs()
680 dout("%s con %p msg %p crcs %u %u %u\n", __func__, con, con->in_msg, in verify_epilogue_crcs()
681 con->in_front_crc, con->in_middle_crc, con->in_data_crc); in verify_epilogue_crcs()
683 if (con->in_front_crc != front_crc) { in verify_epilogue_crcs()
685 con->in_front_crc, front_crc); in verify_epilogue_crcs()
688 if (con->in_middle_crc != middle_crc) { in verify_epilogue_crcs()
690 con->in_middle_crc, middle_crc); in verify_epilogue_crcs()
693 if (con->in_data_crc != data_crc) { in verify_epilogue_crcs()
695 con->in_data_crc, data_crc); in verify_epilogue_crcs()
702 static int setup_crypto(struct ceph_connection *con, in setup_crypto() argument
710 __func__, con, con->v2.con_mode, session_key_len, con_secret_len); in setup_crypto()
711 WARN_ON(con->v2.hmac_tfm || con->v2.gcm_tfm || con->v2.gcm_req); in setup_crypto()
713 if (con->v2.con_mode != CEPH_CON_MODE_CRC && in setup_crypto()
714 con->v2.con_mode != CEPH_CON_MODE_SECURE) { in setup_crypto()
715 pr_err("bad con_mode %d\n", con->v2.con_mode); in setup_crypto()
720 WARN_ON(con->v2.con_mode != CEPH_CON_MODE_CRC); in setup_crypto()
726 con->v2.hmac_tfm = crypto_alloc_shash("hmac(sha256)", 0, 0); in setup_crypto()
728 if (IS_ERR(con->v2.hmac_tfm)) { in setup_crypto()
729 ret = PTR_ERR(con->v2.hmac_tfm); in setup_crypto()
730 con->v2.hmac_tfm = NULL; in setup_crypto()
736 crypto_shash_alignmask(con->v2.hmac_tfm)); in setup_crypto()
737 ret = crypto_shash_setkey(con->v2.hmac_tfm, session_key, in setup_crypto()
744 if (con->v2.con_mode == CEPH_CON_MODE_CRC) { in setup_crypto()
755 con->v2.gcm_tfm = crypto_alloc_aead("gcm(aes)", 0, 0); in setup_crypto()
757 if (IS_ERR(con->v2.gcm_tfm)) { in setup_crypto()
758 ret = PTR_ERR(con->v2.gcm_tfm); in setup_crypto()
759 con->v2.gcm_tfm = NULL; in setup_crypto()
765 crypto_aead_alignmask(con->v2.gcm_tfm)); in setup_crypto()
766 ret = crypto_aead_setkey(con->v2.gcm_tfm, con_secret, CEPH_GCM_KEY_LEN); in setup_crypto()
772 WARN_ON(crypto_aead_ivsize(con->v2.gcm_tfm) != CEPH_GCM_IV_LEN); in setup_crypto()
773 ret = crypto_aead_setauthsize(con->v2.gcm_tfm, CEPH_GCM_TAG_LEN); in setup_crypto()
779 con->v2.gcm_req = aead_request_alloc(con->v2.gcm_tfm, GFP_NOIO); in setup_crypto()
780 if (!con->v2.gcm_req) { in setup_crypto()
785 crypto_init_wait(&con->v2.gcm_wait); in setup_crypto()
786 aead_request_set_callback(con->v2.gcm_req, CRYPTO_TFM_REQ_MAY_BACKLOG, in setup_crypto()
787 crypto_req_done, &con->v2.gcm_wait); in setup_crypto()
789 memcpy(&con->v2.in_gcm_nonce, con_secret + CEPH_GCM_KEY_LEN, in setup_crypto()
791 memcpy(&con->v2.out_gcm_nonce, in setup_crypto()
797 static int hmac_sha256(struct ceph_connection *con, const struct kvec *kvecs, in hmac_sha256() argument
800 SHASH_DESC_ON_STACK(desc, con->v2.hmac_tfm); /* tfm arg is ignored */ in hmac_sha256()
804 dout("%s con %p hmac_tfm %p kvec_cnt %d\n", __func__, con, in hmac_sha256()
805 con->v2.hmac_tfm, kvec_cnt); in hmac_sha256()
807 if (!con->v2.hmac_tfm) { in hmac_sha256()
812 desc->tfm = con->v2.hmac_tfm; in hmac_sha256()
819 crypto_shash_alignmask(con->v2.hmac_tfm)); in hmac_sha256()
841 static int gcm_crypt(struct ceph_connection *con, bool encrypt, in gcm_crypt() argument
848 nonce = encrypt ? &con->v2.out_gcm_nonce : &con->v2.in_gcm_nonce; in gcm_crypt()
850 aead_request_set_ad(con->v2.gcm_req, 0); /* no AAD */ in gcm_crypt()
851 aead_request_set_crypt(con->v2.gcm_req, src, dst, src_len, (u8 *)nonce); in gcm_crypt()
852 ret = crypto_wait_req(encrypt ? crypto_aead_encrypt(con->v2.gcm_req) : in gcm_crypt()
853 crypto_aead_decrypt(con->v2.gcm_req), in gcm_crypt()
854 &con->v2.gcm_wait); in gcm_crypt()
1020 static int decrypt_preamble(struct ceph_connection *con) in decrypt_preamble() argument
1024 sg_init_one(&sg, con->v2.in_buf, CEPH_PREAMBLE_SECURE_LEN); in decrypt_preamble()
1025 return gcm_crypt(con, false, &sg, &sg, CEPH_PREAMBLE_SECURE_LEN); in decrypt_preamble()
1028 static int decrypt_control_remainder(struct ceph_connection *con) in decrypt_control_remainder() argument
1030 int ctrl_len = con->v2.in_desc.fd_lens[0]; in decrypt_control_remainder()
1035 WARN_ON(con->v2.in_kvecs[0].iov_len != rem_len); in decrypt_control_remainder()
1036 WARN_ON(con->v2.in_kvecs[1].iov_len != pt_len); in decrypt_control_remainder()
1039 sg_set_buf(&sgs[0], con->v2.in_kvecs[0].iov_base, rem_len); in decrypt_control_remainder()
1040 sg_set_buf(&sgs[1], con->v2.in_buf, pt_len); in decrypt_control_remainder()
1042 return gcm_crypt(con, false, sgs, sgs, in decrypt_control_remainder()
1046 static int decrypt_message(struct ceph_connection *con) in decrypt_message() argument
1051 ret = setup_message_sgs(&sgt, con->in_msg, FRONT_PAD(con->v2.in_buf), in decrypt_message()
1052 MIDDLE_PAD(con->v2.in_buf), DATA_PAD(con->v2.in_buf), in decrypt_message()
1053 con->v2.in_buf, true); in decrypt_message()
1057 ret = gcm_crypt(con, false, sgt.sgl, sgt.sgl, in decrypt_message()
1058 tail_onwire_len(con->in_msg, true)); in decrypt_message()
1065 static int prepare_banner(struct ceph_connection *con) in prepare_banner() argument
1070 buf = alloc_conn_buf(con, buf_len); in prepare_banner()
1081 add_out_kvec(con, buf, buf_len); in prepare_banner()
1082 add_out_sign_kvec(con, buf, buf_len); in prepare_banner()
1083 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING); in prepare_banner()
1104 static void prepare_head_plain(struct ceph_connection *con, void *base, in prepare_head_plain() argument
1118 add_out_kvec(con, base, base_len); in prepare_head_plain()
1120 add_out_sign_kvec(con, base, base_len); in prepare_head_plain()
1124 add_out_kvec(con, base, crcp - base); in prepare_head_plain()
1125 add_out_kvec(con, extdata, extdata_len); in prepare_head_plain()
1126 add_out_kvec(con, crcp, CEPH_CRC_LEN); in prepare_head_plain()
1128 add_out_sign_kvec(con, base, crcp - base); in prepare_head_plain()
1129 add_out_sign_kvec(con, extdata, extdata_len); in prepare_head_plain()
1130 add_out_sign_kvec(con, crcp, CEPH_CRC_LEN); in prepare_head_plain()
1134 static int prepare_head_secure_small(struct ceph_connection *con, in prepare_head_secure_small() argument
1146 ret = gcm_crypt(con, true, &sg, &sg, in prepare_head_secure_small()
1151 add_out_kvec(con, base, CEPH_PREAMBLE_SECURE_LEN); in prepare_head_secure_small()
1175 static int prepare_head_secure_big(struct ceph_connection *con, in prepare_head_secure_big() argument
1188 ret = gcm_crypt(con, true, sgs, sgs, rem - base); in prepare_head_secure_big()
1197 ret = gcm_crypt(con, true, sgs, sgs, rem_tag - rem); in prepare_head_secure_big()
1201 add_out_kvec(con, base, rem - base); in prepare_head_secure_big()
1202 add_out_kvec(con, pmbl_tag, CEPH_GCM_TAG_LEN); in prepare_head_secure_big()
1203 add_out_kvec(con, rem, pmbl_tag - rem); in prepare_head_secure_big()
1207 static int __prepare_control(struct ceph_connection *con, int tag, in __prepare_control() argument
1215 dout("%s con %p tag %d len %d (%d+%d)\n", __func__, con, tag, in __prepare_control()
1225 if (con_secure(con)) { in __prepare_control()
1231 ret = prepare_head_secure_small(con, base, ctrl_len); in __prepare_control()
1234 ret = prepare_head_secure_big(con, base, ctrl_len); in __prepare_control()
1238 prepare_head_plain(con, base, ctrl_len, extdata, extdata_len, in __prepare_control()
1242 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING); in __prepare_control()
1246 static int prepare_control(struct ceph_connection *con, int tag, in prepare_control() argument
1249 return __prepare_control(con, tag, base, ctrl_len, NULL, 0, false); in prepare_control()
1252 static int prepare_hello(struct ceph_connection *con) in prepare_hello() argument
1257 ctrl_len = 1 + ceph_entity_addr_encoding_len(&con->peer_addr); in prepare_hello()
1258 buf = alloc_conn_buf(con, head_onwire_len(ctrl_len, false)); in prepare_hello()
1264 ceph_encode_entity_addr(&p, &con->peer_addr); in prepare_hello()
1267 return __prepare_control(con, FRAME_TAG_HELLO, buf, ctrl_len, in prepare_hello()
1274 static int prepare_auth_request(struct ceph_connection *con) in prepare_auth_request() argument
1282 buf = alloc_conn_buf(con, head_onwire_len(ctrl_len, false)); in prepare_auth_request()
1286 mutex_unlock(&con->mutex); in prepare_auth_request()
1287 ret = con->ops->get_auth_request(con, CTRL_BODY(buf), &ctrl_len, in prepare_auth_request()
1289 mutex_lock(&con->mutex); in prepare_auth_request()
1290 if (con->state != CEPH_CON_S_V2_HELLO) { in prepare_auth_request()
1291 dout("%s con %p state changed to %d\n", __func__, con, in prepare_auth_request()
1292 con->state); in prepare_auth_request()
1296 dout("%s con %p get_auth_request ret %d\n", __func__, con, ret); in prepare_auth_request()
1300 authorizer_copy = alloc_conn_buf(con, authorizer_len); in prepare_auth_request()
1306 return __prepare_control(con, FRAME_TAG_AUTH_REQUEST, buf, ctrl_len, in prepare_auth_request()
1310 static int prepare_auth_request_more(struct ceph_connection *con, in prepare_auth_request_more() argument
1319 buf = alloc_conn_buf(con, head_onwire_len(ctrl_len, false)); in prepare_auth_request_more()
1323 mutex_unlock(&con->mutex); in prepare_auth_request_more()
1324 ret = con->ops->handle_auth_reply_more(con, reply, reply_len, in prepare_auth_request_more()
1327 mutex_lock(&con->mutex); in prepare_auth_request_more()
1328 if (con->state != CEPH_CON_S_V2_AUTH) { in prepare_auth_request_more()
1329 dout("%s con %p state changed to %d\n", __func__, con, in prepare_auth_request_more()
1330 con->state); in prepare_auth_request_more()
1334 dout("%s con %p handle_auth_reply_more ret %d\n", __func__, con, ret); in prepare_auth_request_more()
1338 return __prepare_control(con, FRAME_TAG_AUTH_REQUEST_MORE, buf, in prepare_auth_request_more()
1342 static int prepare_auth_signature(struct ceph_connection *con) in prepare_auth_signature() argument
1347 buf = alloc_conn_buf(con, head_onwire_len(SHA256_DIGEST_SIZE, in prepare_auth_signature()
1348 con_secure(con))); in prepare_auth_signature()
1352 ret = hmac_sha256(con, con->v2.in_sign_kvecs, con->v2.in_sign_kvec_cnt, in prepare_auth_signature()
1357 return prepare_control(con, FRAME_TAG_AUTH_SIGNATURE, buf, in prepare_auth_signature()
1361 static int prepare_client_ident(struct ceph_connection *con) in prepare_client_ident() argument
1363 struct ceph_entity_addr *my_addr = &con->msgr->inst.addr; in prepare_client_ident()
1364 struct ceph_client *client = from_msgr(con->msgr); in prepare_client_ident()
1369 WARN_ON(con->v2.server_cookie); in prepare_client_ident()
1370 WARN_ON(con->v2.connect_seq); in prepare_client_ident()
1371 WARN_ON(con->v2.peer_global_seq); in prepare_client_ident()
1373 if (!con->v2.client_cookie) { in prepare_client_ident()
1375 get_random_bytes(&con->v2.client_cookie, in prepare_client_ident()
1376 sizeof(con->v2.client_cookie)); in prepare_client_ident()
1377 } while (!con->v2.client_cookie); in prepare_client_ident()
1378 dout("%s con %p generated cookie 0x%llx\n", __func__, con, in prepare_client_ident()
1379 con->v2.client_cookie); in prepare_client_ident()
1381 dout("%s con %p cookie already set 0x%llx\n", __func__, con, in prepare_client_ident()
1382 con->v2.client_cookie); in prepare_client_ident()
1386 __func__, con, ceph_pr_addr(my_addr), le32_to_cpu(my_addr->nonce), in prepare_client_ident()
1387 ceph_pr_addr(&con->peer_addr), le32_to_cpu(con->peer_addr.nonce), in prepare_client_ident()
1388 global_id, con->v2.global_seq, client->supported_features, in prepare_client_ident()
1389 client->required_features, con->v2.client_cookie); in prepare_client_ident()
1392 ceph_entity_addr_encoding_len(&con->peer_addr) + 6 * 8; in prepare_client_ident()
1393 buf = alloc_conn_buf(con, head_onwire_len(ctrl_len, con_secure(con))); in prepare_client_ident()
1401 ceph_encode_entity_addr(&p, &con->peer_addr); in prepare_client_ident()
1403 ceph_encode_64(&p, con->v2.global_seq); in prepare_client_ident()
1407 ceph_encode_64(&p, con->v2.client_cookie); in prepare_client_ident()
1410 return prepare_control(con, FRAME_TAG_CLIENT_IDENT, buf, ctrl_len); in prepare_client_ident()
1413 static int prepare_session_reconnect(struct ceph_connection *con) in prepare_session_reconnect() argument
1415 struct ceph_entity_addr *my_addr = &con->msgr->inst.addr; in prepare_session_reconnect()
1419 WARN_ON(!con->v2.client_cookie); in prepare_session_reconnect()
1420 WARN_ON(!con->v2.server_cookie); in prepare_session_reconnect()
1421 WARN_ON(!con->v2.connect_seq); in prepare_session_reconnect()
1422 WARN_ON(!con->v2.peer_global_seq); in prepare_session_reconnect()
1425 __func__, con, ceph_pr_addr(my_addr), le32_to_cpu(my_addr->nonce), in prepare_session_reconnect()
1426 con->v2.client_cookie, con->v2.server_cookie, con->v2.global_seq, in prepare_session_reconnect()
1427 con->v2.connect_seq, con->in_seq); in prepare_session_reconnect()
1430 buf = alloc_conn_buf(con, head_onwire_len(ctrl_len, con_secure(con))); in prepare_session_reconnect()
1438 ceph_encode_64(&p, con->v2.client_cookie); in prepare_session_reconnect()
1439 ceph_encode_64(&p, con->v2.server_cookie); in prepare_session_reconnect()
1440 ceph_encode_64(&p, con->v2.global_seq); in prepare_session_reconnect()
1441 ceph_encode_64(&p, con->v2.connect_seq); in prepare_session_reconnect()
1442 ceph_encode_64(&p, con->in_seq); in prepare_session_reconnect()
1445 return prepare_control(con, FRAME_TAG_SESSION_RECONNECT, buf, ctrl_len); in prepare_session_reconnect()
1448 static int prepare_keepalive2(struct ceph_connection *con) in prepare_keepalive2() argument
1450 struct ceph_timespec *ts = CTRL_BODY(con->v2.out_buf); in prepare_keepalive2()
1454 dout("%s con %p timestamp %lld.%09ld\n", __func__, con, now.tv_sec, in prepare_keepalive2()
1459 reset_out_kvecs(con); in prepare_keepalive2()
1460 return prepare_control(con, FRAME_TAG_KEEPALIVE2, con->v2.out_buf, in prepare_keepalive2()
1464 static int prepare_ack(struct ceph_connection *con) in prepare_ack() argument
1468 dout("%s con %p in_seq_acked %llu -> %llu\n", __func__, con, in prepare_ack()
1469 con->in_seq_acked, con->in_seq); in prepare_ack()
1470 con->in_seq_acked = con->in_seq; in prepare_ack()
1472 p = CTRL_BODY(con->v2.out_buf); in prepare_ack()
1473 ceph_encode_64(&p, con->in_seq_acked); in prepare_ack()
1475 reset_out_kvecs(con); in prepare_ack()
1476 return prepare_control(con, FRAME_TAG_ACK, con->v2.out_buf, 8); in prepare_ack()
1479 static void prepare_epilogue_plain(struct ceph_connection *con, bool aborted) in prepare_epilogue_plain() argument
1481 dout("%s con %p msg %p aborted %d crcs %u %u %u\n", __func__, con, in prepare_epilogue_plain()
1482 con->out_msg, aborted, con->v2.out_epil.front_crc, in prepare_epilogue_plain()
1483 con->v2.out_epil.middle_crc, con->v2.out_epil.data_crc); in prepare_epilogue_plain()
1485 encode_epilogue_plain(con, aborted); in prepare_epilogue_plain()
1486 add_out_kvec(con, &con->v2.out_epil, CEPH_EPILOGUE_PLAIN_LEN); in prepare_epilogue_plain()
1493 static void prepare_message_plain(struct ceph_connection *con) in prepare_message_plain() argument
1495 struct ceph_msg *msg = con->out_msg; in prepare_message_plain()
1497 prepare_head_plain(con, con->v2.out_buf, in prepare_message_plain()
1506 con->v2.out_state = OUT_S_FINISH_MESSAGE; in prepare_message_plain()
1510 con->v2.out_epil.front_crc = -1; in prepare_message_plain()
1511 con->v2.out_epil.middle_crc = -1; in prepare_message_plain()
1512 con->v2.out_state = OUT_S_QUEUE_DATA; in prepare_message_plain()
1517 con->v2.out_epil.front_crc = crc32c(-1, msg->front.iov_base, in prepare_message_plain()
1519 add_out_kvec(con, msg->front.iov_base, front_len(msg)); in prepare_message_plain()
1522 con->v2.out_epil.front_crc = -1; in prepare_message_plain()
1526 con->v2.out_epil.middle_crc = in prepare_message_plain()
1528 add_out_kvec(con, msg->middle->vec.iov_base, middle_len(msg)); in prepare_message_plain()
1530 con->v2.out_epil.middle_crc = data_len(msg) ? -1 : 0; in prepare_message_plain()
1534 con->v2.out_state = OUT_S_QUEUE_DATA; in prepare_message_plain()
1536 con->v2.out_epil.data_crc = 0; in prepare_message_plain()
1537 prepare_epilogue_plain(con, false); in prepare_message_plain()
1538 con->v2.out_state = OUT_S_FINISH_MESSAGE; in prepare_message_plain()
1549 static int prepare_message_secure(struct ceph_connection *con) in prepare_message_secure() argument
1559 ret = prepare_head_secure_small(con, con->v2.out_buf, in prepare_message_secure()
1564 tail_len = tail_onwire_len(con->out_msg, true); in prepare_message_secure()
1570 con->v2.out_state = OUT_S_FINISH_MESSAGE; in prepare_message_secure()
1574 encode_epilogue_secure(con, false); in prepare_message_secure()
1575 ret = setup_message_sgs(&sgt, con->out_msg, zerop, zerop, zerop, in prepare_message_secure()
1576 &con->v2.out_epil, false); in prepare_message_secure()
1587 WARN_ON(con->v2.out_enc_pages || con->v2.out_enc_page_cnt); in prepare_message_secure()
1588 con->v2.out_enc_pages = enc_pages; in prepare_message_secure()
1589 con->v2.out_enc_page_cnt = enc_page_cnt; in prepare_message_secure()
1590 con->v2.out_enc_resid = tail_len; in prepare_message_secure()
1591 con->v2.out_enc_i = 0; in prepare_message_secure()
1598 ret = gcm_crypt(con, true, sgt.sgl, enc_sgt.sgl, in prepare_message_secure()
1603 dout("%s con %p msg %p sg_cnt %d enc_page_cnt %d\n", __func__, con, in prepare_message_secure()
1604 con->out_msg, sgt.orig_nents, enc_page_cnt); in prepare_message_secure()
1605 con->v2.out_state = OUT_S_QUEUE_ENC_PAGE; in prepare_message_secure()
1613 static int prepare_message(struct ceph_connection *con) in prepare_message() argument
1617 front_len(con->out_msg), in prepare_message()
1618 middle_len(con->out_msg), in prepare_message()
1619 data_len(con->out_msg) in prepare_message()
1624 dout("%s con %p msg %p logical %d+%d+%d+%d\n", __func__, con, in prepare_message()
1625 con->out_msg, lens[0], lens[1], lens[2], lens[3]); in prepare_message()
1627 if (con->in_seq > con->in_seq_acked) { in prepare_message()
1628 dout("%s con %p in_seq_acked %llu -> %llu\n", __func__, con, in prepare_message()
1629 con->in_seq_acked, con->in_seq); in prepare_message()
1630 con->in_seq_acked = con->in_seq; in prepare_message()
1633 reset_out_kvecs(con); in prepare_message()
1635 encode_preamble(&desc, con->v2.out_buf); in prepare_message()
1636 fill_header2(CTRL_BODY(con->v2.out_buf), &con->out_msg->hdr, in prepare_message()
1637 con->in_seq_acked); in prepare_message()
1639 if (con_secure(con)) { in prepare_message()
1640 ret = prepare_message_secure(con); in prepare_message()
1644 prepare_message_plain(con); in prepare_message()
1647 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING); in prepare_message()
1651 static int prepare_read_banner_prefix(struct ceph_connection *con) in prepare_read_banner_prefix() argument
1655 buf = alloc_conn_buf(con, CEPH_BANNER_V2_PREFIX_LEN); in prepare_read_banner_prefix()
1659 reset_in_kvecs(con); in prepare_read_banner_prefix()
1660 add_in_kvec(con, buf, CEPH_BANNER_V2_PREFIX_LEN); in prepare_read_banner_prefix()
1661 add_in_sign_kvec(con, buf, CEPH_BANNER_V2_PREFIX_LEN); in prepare_read_banner_prefix()
1662 con->state = CEPH_CON_S_V2_BANNER_PREFIX; in prepare_read_banner_prefix()
1666 static int prepare_read_banner_payload(struct ceph_connection *con, in prepare_read_banner_payload() argument
1671 buf = alloc_conn_buf(con, payload_len); in prepare_read_banner_payload()
1675 reset_in_kvecs(con); in prepare_read_banner_payload()
1676 add_in_kvec(con, buf, payload_len); in prepare_read_banner_payload()
1677 add_in_sign_kvec(con, buf, payload_len); in prepare_read_banner_payload()
1678 con->state = CEPH_CON_S_V2_BANNER_PAYLOAD; in prepare_read_banner_payload()
1682 static void prepare_read_preamble(struct ceph_connection *con) in prepare_read_preamble() argument
1684 reset_in_kvecs(con); in prepare_read_preamble()
1685 add_in_kvec(con, con->v2.in_buf, in prepare_read_preamble()
1686 con_secure(con) ? CEPH_PREAMBLE_SECURE_LEN : in prepare_read_preamble()
1688 con->v2.in_state = IN_S_HANDLE_PREAMBLE; in prepare_read_preamble()
1691 static int prepare_read_control(struct ceph_connection *con) in prepare_read_control() argument
1693 int ctrl_len = con->v2.in_desc.fd_lens[0]; in prepare_read_control()
1697 reset_in_kvecs(con); in prepare_read_control()
1698 if (con->state == CEPH_CON_S_V2_HELLO || in prepare_read_control()
1699 con->state == CEPH_CON_S_V2_AUTH) { in prepare_read_control()
1701 buf = alloc_conn_buf(con, head_len); in prepare_read_control()
1706 memcpy(buf, con->v2.in_buf, CEPH_PREAMBLE_LEN); in prepare_read_control()
1708 add_in_kvec(con, CTRL_BODY(buf), ctrl_len); in prepare_read_control()
1709 add_in_kvec(con, CTRL_BODY(buf) + ctrl_len, CEPH_CRC_LEN); in prepare_read_control()
1710 add_in_sign_kvec(con, buf, head_len); in prepare_read_control()
1713 buf = alloc_conn_buf(con, ctrl_len); in prepare_read_control()
1717 add_in_kvec(con, buf, ctrl_len); in prepare_read_control()
1719 add_in_kvec(con, CTRL_BODY(con->v2.in_buf), ctrl_len); in prepare_read_control()
1721 add_in_kvec(con, con->v2.in_buf, CEPH_CRC_LEN); in prepare_read_control()
1723 con->v2.in_state = IN_S_HANDLE_CONTROL; in prepare_read_control()
1727 static int prepare_read_control_remainder(struct ceph_connection *con) in prepare_read_control_remainder() argument
1729 int ctrl_len = con->v2.in_desc.fd_lens[0]; in prepare_read_control_remainder()
1733 buf = alloc_conn_buf(con, ctrl_len); in prepare_read_control_remainder()
1737 memcpy(buf, CTRL_BODY(con->v2.in_buf), CEPH_PREAMBLE_INLINE_LEN); in prepare_read_control_remainder()
1739 reset_in_kvecs(con); in prepare_read_control_remainder()
1740 add_in_kvec(con, buf + CEPH_PREAMBLE_INLINE_LEN, rem_len); in prepare_read_control_remainder()
1741 add_in_kvec(con, con->v2.in_buf, in prepare_read_control_remainder()
1743 con->v2.in_state = IN_S_HANDLE_CONTROL_REMAINDER; in prepare_read_control_remainder()
1747 static void prepare_read_data(struct ceph_connection *con) in prepare_read_data() argument
1751 if (!con_secure(con)) in prepare_read_data()
1752 con->in_data_crc = -1; in prepare_read_data()
1753 ceph_msg_data_cursor_init(&con->v2.in_cursor, con->in_msg, in prepare_read_data()
1754 data_len(con->in_msg)); in prepare_read_data()
1756 get_bvec_at(&con->v2.in_cursor, &bv); in prepare_read_data()
1757 set_in_bvec(con, &bv); in prepare_read_data()
1758 con->v2.in_state = IN_S_PREPARE_READ_DATA_CONT; in prepare_read_data()
1761 static void prepare_read_data_cont(struct ceph_connection *con) in prepare_read_data_cont() argument
1765 if (!con_secure(con)) in prepare_read_data_cont()
1766 con->in_data_crc = ceph_crc32c_page(con->in_data_crc, in prepare_read_data_cont()
1767 con->v2.in_bvec.bv_page, in prepare_read_data_cont()
1768 con->v2.in_bvec.bv_offset, in prepare_read_data_cont()
1769 con->v2.in_bvec.bv_len); in prepare_read_data_cont()
1771 ceph_msg_data_advance(&con->v2.in_cursor, con->v2.in_bvec.bv_len); in prepare_read_data_cont()
1772 if (con->v2.in_cursor.total_resid) { in prepare_read_data_cont()
1773 get_bvec_at(&con->v2.in_cursor, &bv); in prepare_read_data_cont()
1774 set_in_bvec(con, &bv); in prepare_read_data_cont()
1775 WARN_ON(con->v2.in_state != IN_S_PREPARE_READ_DATA_CONT); in prepare_read_data_cont()
1783 reset_in_kvecs(con); in prepare_read_data_cont()
1784 if (con_secure(con)) { in prepare_read_data_cont()
1785 if (need_padding(data_len(con->in_msg))) in prepare_read_data_cont()
1786 add_in_kvec(con, DATA_PAD(con->v2.in_buf), in prepare_read_data_cont()
1787 padding_len(data_len(con->in_msg))); in prepare_read_data_cont()
1788 add_in_kvec(con, con->v2.in_buf, CEPH_EPILOGUE_SECURE_LEN); in prepare_read_data_cont()
1790 add_in_kvec(con, con->v2.in_buf, CEPH_EPILOGUE_PLAIN_LEN); in prepare_read_data_cont()
1792 con->v2.in_state = IN_S_HANDLE_EPILOGUE; in prepare_read_data_cont()
1795 static void __finish_skip(struct ceph_connection *con) in __finish_skip() argument
1797 con->in_seq++; in __finish_skip()
1798 prepare_read_preamble(con); in __finish_skip()
1801 static void prepare_skip_message(struct ceph_connection *con) in prepare_skip_message() argument
1803 struct ceph_frame_desc *desc = &con->v2.in_desc; in prepare_skip_message()
1806 dout("%s con %p %d+%d+%d\n", __func__, con, desc->fd_lens[1], in prepare_skip_message()
1810 desc->fd_lens[3], con_secure(con)); in prepare_skip_message()
1812 __finish_skip(con); in prepare_skip_message()
1814 set_in_skip(con, tail_len); in prepare_skip_message()
1815 con->v2.in_state = IN_S_FINISH_SKIP; in prepare_skip_message()
1819 static int process_banner_prefix(struct ceph_connection *con) in process_banner_prefix() argument
1824 WARN_ON(con->v2.in_kvecs[0].iov_len != CEPH_BANNER_V2_PREFIX_LEN); in process_banner_prefix()
1826 p = con->v2.in_kvecs[0].iov_base; in process_banner_prefix()
1829 con->error_msg = "server is speaking msgr1 protocol"; in process_banner_prefix()
1831 con->error_msg = "protocol error, bad banner"; in process_banner_prefix()
1837 dout("%s con %p payload_len %d\n", __func__, con, payload_len); in process_banner_prefix()
1839 return prepare_read_banner_payload(con, payload_len); in process_banner_prefix()
1842 static int process_banner_payload(struct ceph_connection *con) in process_banner_payload() argument
1844 void *end = con->v2.in_kvecs[0].iov_base + con->v2.in_kvecs[0].iov_len; in process_banner_payload()
1851 p = con->v2.in_kvecs[0].iov_base; in process_banner_payload()
1856 __func__, con, server_feat, server_req_feat); in process_banner_payload()
1861 con->error_msg = "missing required protocol features"; in process_banner_payload()
1867 con->error_msg = "missing required protocol features"; in process_banner_payload()
1872 ret = prepare_hello(con); in process_banner_payload()
1878 con->state = CEPH_CON_S_V2_HELLO; in process_banner_payload()
1879 prepare_read_preamble(con); in process_banner_payload()
1887 static int process_hello(struct ceph_connection *con, void *p, void *end) in process_hello() argument
1889 struct ceph_entity_addr *my_addr = &con->msgr->inst.addr; in process_hello()
1894 if (con->state != CEPH_CON_S_V2_HELLO) { in process_hello()
1895 con->error_msg = "protocol error, unexpected hello"; in process_hello()
1906 dout("%s con %p entity_type %d addr_for_me %s\n", __func__, con, in process_hello()
1909 if (entity_type != con->peer_name.type) { in process_hello()
1911 con->peer_name.type, entity_type); in process_hello()
1912 con->error_msg = "wrong peer at address"; in process_hello()
1927 __func__, con, ceph_pr_addr(my_addr), in process_hello()
1928 ceph_pr_addr(&con->peer_addr)); in process_hello()
1931 __func__, con, ceph_pr_addr(my_addr)); in process_hello()
1939 ret = prepare_auth_request(con); in process_hello()
1946 con->state = CEPH_CON_S_V2_AUTH; in process_hello()
1954 static int process_auth_bad_method(struct ceph_connection *con, in process_auth_bad_method() argument
1963 if (con->state != CEPH_CON_S_V2_AUTH) { in process_auth_bad_method()
1964 con->error_msg = "protocol error, unexpected auth_bad_method"; in process_auth_bad_method()
1970 dout("%s con %p used_proto %d result %d\n", __func__, con, used_proto, in process_auth_bad_method()
1980 dout("%s con %p allowed_protos[%d] %d\n", __func__, con, in process_auth_bad_method()
1991 dout("%s con %p allowed_modes[%d] %d\n", __func__, con, in process_auth_bad_method()
1995 mutex_unlock(&con->mutex); in process_auth_bad_method()
1996 ret = con->ops->handle_auth_bad_method(con, used_proto, result, in process_auth_bad_method()
2001 mutex_lock(&con->mutex); in process_auth_bad_method()
2002 if (con->state != CEPH_CON_S_V2_AUTH) { in process_auth_bad_method()
2003 dout("%s con %p state changed to %d\n", __func__, con, in process_auth_bad_method()
2004 con->state); in process_auth_bad_method()
2008 dout("%s con %p handle_auth_bad_method ret %d\n", __func__, con, ret); in process_auth_bad_method()
2016 static int process_auth_reply_more(struct ceph_connection *con, in process_auth_reply_more() argument
2022 if (con->state != CEPH_CON_S_V2_AUTH) { in process_auth_reply_more()
2023 con->error_msg = "protocol error, unexpected auth_reply_more"; in process_auth_reply_more()
2030 dout("%s con %p payload_len %d\n", __func__, con, payload_len); in process_auth_reply_more()
2032 reset_out_kvecs(con); in process_auth_reply_more()
2033 ret = prepare_auth_request_more(con, p, payload_len); in process_auth_reply_more()
2053 static int process_auth_done(struct ceph_connection *con, void *p, void *end) in process_auth_done() argument
2064 if (con->state != CEPH_CON_S_V2_AUTH) { in process_auth_done()
2065 con->error_msg = "protocol error, unexpected auth_done"; in process_auth_done()
2070 ceph_decode_32_safe(&p, end, con->v2.con_mode, bad); in process_auth_done()
2074 __func__, con, global_id, con->v2.con_mode, payload_len); in process_auth_done()
2076 mutex_unlock(&con->mutex); in process_auth_done()
2079 ret = con->ops->handle_auth_done(con, global_id, p, payload_len, in process_auth_done()
2082 mutex_lock(&con->mutex); in process_auth_done()
2083 if (con->state != CEPH_CON_S_V2_AUTH) { in process_auth_done()
2084 dout("%s con %p state changed to %d\n", __func__, con, in process_auth_done()
2085 con->state); in process_auth_done()
2090 dout("%s con %p handle_auth_done ret %d\n", __func__, con, ret); in process_auth_done()
2094 ret = setup_crypto(con, session_key, session_key_len, con_secret, in process_auth_done()
2099 reset_out_kvecs(con); in process_auth_done()
2100 ret = prepare_auth_signature(con); in process_auth_done()
2106 con->state = CEPH_CON_S_V2_AUTH_SIGNATURE; in process_auth_done()
2118 static int process_auth_signature(struct ceph_connection *con, in process_auth_signature() argument
2124 if (con->state != CEPH_CON_S_V2_AUTH_SIGNATURE) { in process_auth_signature()
2125 con->error_msg = "protocol error, unexpected auth_signature"; in process_auth_signature()
2129 ret = hmac_sha256(con, con->v2.out_sign_kvecs, in process_auth_signature()
2130 con->v2.out_sign_kvec_cnt, hmac); in process_auth_signature()
2136 con->error_msg = "integrity error, bad auth signature"; in process_auth_signature()
2140 dout("%s con %p auth signature ok\n", __func__, con); in process_auth_signature()
2143 if (!con->v2.server_cookie) { in process_auth_signature()
2144 ret = prepare_client_ident(con); in process_auth_signature()
2150 con->state = CEPH_CON_S_V2_SESSION_CONNECT; in process_auth_signature()
2152 ret = prepare_session_reconnect(con); in process_auth_signature()
2158 con->state = CEPH_CON_S_V2_SESSION_RECONNECT; in process_auth_signature()
2168 static int process_server_ident(struct ceph_connection *con, in process_server_ident() argument
2171 struct ceph_client *client = from_msgr(con->msgr); in process_server_ident()
2180 if (con->state != CEPH_CON_S_V2_SESSION_CONNECT) { in process_server_ident()
2181 con->error_msg = "protocol error, unexpected server_ident"; in process_server_ident()
2199 __func__, con, ceph_pr_addr(&addr), le32_to_cpu(addr.nonce), in process_server_ident()
2203 if (memcmp(&addr, &con->peer_addr, sizeof(con->peer_addr))) { in process_server_ident()
2205 ceph_pr_addr(&con->peer_addr), in process_server_ident()
2206 le32_to_cpu(con->peer_addr.nonce), in process_server_ident()
2208 con->error_msg = "wrong peer at address"; in process_server_ident()
2215 con->error_msg = "missing required protocol features"; in process_server_ident()
2224 WARN_ON(!con->peer_name.type); in process_server_ident()
2225 con->peer_name.num = cpu_to_le64(global_id); in process_server_ident()
2226 con->v2.peer_global_seq = global_seq; in process_server_ident()
2227 con->peer_features = features; in process_server_ident()
2229 con->v2.server_cookie = cookie; in process_server_ident()
2232 ceph_con_flag_set(con, CEPH_CON_F_LOSSYTX); in process_server_ident()
2233 WARN_ON(con->v2.server_cookie); in process_server_ident()
2235 WARN_ON(!con->v2.server_cookie); in process_server_ident()
2238 clear_in_sign_kvecs(con); in process_server_ident()
2239 clear_out_sign_kvecs(con); in process_server_ident()
2240 free_conn_bufs(con); in process_server_ident()
2241 con->delay = 0; /* reset backoff memory */ in process_server_ident()
2243 con->state = CEPH_CON_S_OPEN; in process_server_ident()
2244 con->v2.out_state = OUT_S_GET_NEXT; in process_server_ident()
2252 static int process_ident_missing_features(struct ceph_connection *con, in process_ident_missing_features() argument
2255 struct ceph_client *client = from_msgr(con->msgr); in process_ident_missing_features()
2258 if (con->state != CEPH_CON_S_V2_SESSION_CONNECT) { in process_ident_missing_features()
2259 con->error_msg = "protocol error, unexpected ident_missing_features"; in process_ident_missing_features()
2266 con->error_msg = "missing required protocol features"; in process_ident_missing_features()
2274 static int process_session_reconnect_ok(struct ceph_connection *con, in process_session_reconnect_ok() argument
2279 if (con->state != CEPH_CON_S_V2_SESSION_RECONNECT) { in process_session_reconnect_ok()
2280 con->error_msg = "protocol error, unexpected session_reconnect_ok"; in process_session_reconnect_ok()
2286 dout("%s con %p seq %llu\n", __func__, con, seq); in process_session_reconnect_ok()
2287 ceph_con_discard_requeued(con, seq); in process_session_reconnect_ok()
2289 clear_in_sign_kvecs(con); in process_session_reconnect_ok()
2290 clear_out_sign_kvecs(con); in process_session_reconnect_ok()
2291 free_conn_bufs(con); in process_session_reconnect_ok()
2292 con->delay = 0; /* reset backoff memory */ in process_session_reconnect_ok()
2294 con->state = CEPH_CON_S_OPEN; in process_session_reconnect_ok()
2295 con->v2.out_state = OUT_S_GET_NEXT; in process_session_reconnect_ok()
2303 static int process_session_retry(struct ceph_connection *con, in process_session_retry() argument
2309 if (con->state != CEPH_CON_S_V2_SESSION_RECONNECT) { in process_session_retry()
2310 con->error_msg = "protocol error, unexpected session_retry"; in process_session_retry()
2316 dout("%s con %p connect_seq %llu\n", __func__, con, connect_seq); in process_session_retry()
2317 WARN_ON(connect_seq <= con->v2.connect_seq); in process_session_retry()
2318 con->v2.connect_seq = connect_seq + 1; in process_session_retry()
2320 free_conn_bufs(con); in process_session_retry()
2322 reset_out_kvecs(con); in process_session_retry()
2323 ret = prepare_session_reconnect(con); in process_session_retry()
2336 static int process_session_retry_global(struct ceph_connection *con, in process_session_retry_global() argument
2342 if (con->state != CEPH_CON_S_V2_SESSION_RECONNECT) { in process_session_retry_global()
2343 con->error_msg = "protocol error, unexpected session_retry_global"; in process_session_retry_global()
2349 dout("%s con %p global_seq %llu\n", __func__, con, global_seq); in process_session_retry_global()
2350 WARN_ON(global_seq <= con->v2.global_seq); in process_session_retry_global()
2351 con->v2.global_seq = ceph_get_global_seq(con->msgr, global_seq); in process_session_retry_global()
2353 free_conn_bufs(con); in process_session_retry_global()
2355 reset_out_kvecs(con); in process_session_retry_global()
2356 ret = prepare_session_reconnect(con); in process_session_retry_global()
2369 static int process_session_reset(struct ceph_connection *con, in process_session_reset() argument
2375 if (con->state != CEPH_CON_S_V2_SESSION_RECONNECT) { in process_session_reset()
2376 con->error_msg = "protocol error, unexpected session_reset"; in process_session_reset()
2382 con->error_msg = "protocol error, bad session_reset"; in process_session_reset()
2386 pr_info("%s%lld %s session reset\n", ENTITY_NAME(con->peer_name), in process_session_reset()
2387 ceph_pr_addr(&con->peer_addr)); in process_session_reset()
2388 ceph_con_reset_session(con); in process_session_reset()
2390 mutex_unlock(&con->mutex); in process_session_reset()
2391 if (con->ops->peer_reset) in process_session_reset()
2392 con->ops->peer_reset(con); in process_session_reset()
2393 mutex_lock(&con->mutex); in process_session_reset()
2394 if (con->state != CEPH_CON_S_V2_SESSION_RECONNECT) { in process_session_reset()
2395 dout("%s con %p state changed to %d\n", __func__, con, in process_session_reset()
2396 con->state); in process_session_reset()
2400 free_conn_bufs(con); in process_session_reset()
2402 reset_out_kvecs(con); in process_session_reset()
2403 ret = prepare_client_ident(con); in process_session_reset()
2409 con->state = CEPH_CON_S_V2_SESSION_CONNECT; in process_session_reset()
2417 static int process_keepalive2_ack(struct ceph_connection *con, in process_keepalive2_ack() argument
2420 if (con->state != CEPH_CON_S_OPEN) { in process_keepalive2_ack()
2421 con->error_msg = "protocol error, unexpected keepalive2_ack"; in process_keepalive2_ack()
2426 ceph_decode_timespec64(&con->last_keepalive_ack, p); in process_keepalive2_ack()
2428 dout("%s con %p timestamp %lld.%09ld\n", __func__, con, in process_keepalive2_ack()
2429 con->last_keepalive_ack.tv_sec, con->last_keepalive_ack.tv_nsec); in process_keepalive2_ack()
2438 static int process_ack(struct ceph_connection *con, void *p, void *end) in process_ack() argument
2442 if (con->state != CEPH_CON_S_OPEN) { in process_ack()
2443 con->error_msg = "protocol error, unexpected ack"; in process_ack()
2449 dout("%s con %p seq %llu\n", __func__, con, seq); in process_ack()
2450 ceph_con_discard_sent(con, seq); in process_ack()
2458 static int process_control(struct ceph_connection *con, void *p, void *end) in process_control() argument
2460 int tag = con->v2.in_desc.fd_tag; in process_control()
2463 dout("%s con %p tag %d len %d\n", __func__, con, tag, (int)(end - p)); in process_control()
2467 ret = process_hello(con, p, end); in process_control()
2470 ret = process_auth_bad_method(con, p, end); in process_control()
2473 ret = process_auth_reply_more(con, p, end); in process_control()
2476 ret = process_auth_done(con, p, end); in process_control()
2479 ret = process_auth_signature(con, p, end); in process_control()
2482 ret = process_server_ident(con, p, end); in process_control()
2485 ret = process_ident_missing_features(con, p, end); in process_control()
2488 ret = process_session_reconnect_ok(con, p, end); in process_control()
2491 ret = process_session_retry(con, p, end); in process_control()
2494 ret = process_session_retry_global(con, p, end); in process_control()
2497 ret = process_session_reset(con, p, end); in process_control()
2500 ret = process_keepalive2_ack(con, p, end); in process_control()
2503 ret = process_ack(con, p, end); in process_control()
2507 con->error_msg = "protocol error, bad tag"; in process_control()
2511 dout("%s con %p error %d\n", __func__, con, ret); in process_control()
2515 prepare_read_preamble(con); in process_control()
2525 static int process_message_header(struct ceph_connection *con, in process_message_header() argument
2528 struct ceph_frame_desc *desc = &con->v2.in_desc; in process_message_header()
2537 if ((s64)seq - (s64)con->in_seq < 1) { in process_message_header()
2539 ENTITY_NAME(con->peer_name), in process_message_header()
2540 ceph_pr_addr(&con->peer_addr), in process_message_header()
2541 seq, con->in_seq + 1); in process_message_header()
2544 if ((s64)seq - (s64)con->in_seq > 1) { in process_message_header()
2545 pr_err("bad seq %llu, expected %llu\n", seq, con->in_seq + 1); in process_message_header()
2546 con->error_msg = "bad message sequence # for incoming message"; in process_message_header()
2550 ceph_con_discard_sent(con, le64_to_cpu(hdr2->ack_seq)); in process_message_header()
2553 desc->fd_lens[3], &con->peer_name); in process_message_header()
2554 ret = ceph_con_in_msg_alloc(con, &hdr, &skip); in process_message_header()
2558 WARN_ON(!con->in_msg ^ skip); in process_message_header()
2562 WARN_ON(!con->in_msg); in process_message_header()
2563 WARN_ON(con->in_msg->con != con); in process_message_header()
2567 static int process_message(struct ceph_connection *con) in process_message() argument
2569 ceph_con_process_message(con); in process_message()
2575 if (con->state != CEPH_CON_S_OPEN) { in process_message()
2576 dout("%s con %p state changed to %d\n", __func__, con, in process_message()
2577 con->state); in process_message()
2581 prepare_read_preamble(con); in process_message()
2585 static int __handle_control(struct ceph_connection *con, void *p) in __handle_control() argument
2587 void *end = p + con->v2.in_desc.fd_lens[0]; in __handle_control()
2591 if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE) in __handle_control()
2592 return process_control(con, p, end); in __handle_control()
2594 ret = process_message_header(con, p, end); in __handle_control()
2598 prepare_skip_message(con); in __handle_control()
2602 msg = con->in_msg; /* set in process_message_header() */ in __handle_control()
2605 return process_message(con); in __handle_control()
2607 prepare_read_data(con); in __handle_control()
2611 reset_in_kvecs(con); in __handle_control()
2614 add_in_kvec(con, msg->front.iov_base, front_len(msg)); in __handle_control()
2617 if (con_secure(con) && need_padding(front_len(msg))) in __handle_control()
2618 add_in_kvec(con, FRONT_PAD(con->v2.in_buf), in __handle_control()
2625 add_in_kvec(con, msg->middle->vec.iov_base, middle_len(msg)); in __handle_control()
2628 if (con_secure(con) && need_padding(middle_len(msg))) in __handle_control()
2629 add_in_kvec(con, MIDDLE_PAD(con->v2.in_buf), in __handle_control()
2636 con->v2.in_state = IN_S_PREPARE_READ_DATA; in __handle_control()
2638 add_in_kvec(con, con->v2.in_buf, in __handle_control()
2639 con_secure(con) ? CEPH_EPILOGUE_SECURE_LEN : in __handle_control()
2641 con->v2.in_state = IN_S_HANDLE_EPILOGUE; in __handle_control()
2646 static int handle_preamble(struct ceph_connection *con) in handle_preamble() argument
2648 struct ceph_frame_desc *desc = &con->v2.in_desc; in handle_preamble()
2651 if (con_secure(con)) { in handle_preamble()
2652 ret = decrypt_preamble(con); in handle_preamble()
2655 con->error_msg = "integrity error, bad preamble auth tag"; in handle_preamble()
2660 ret = decode_preamble(con->v2.in_buf, desc); in handle_preamble()
2663 con->error_msg = "integrity error, bad crc"; in handle_preamble()
2665 con->error_msg = "protocol error, bad preamble"; in handle_preamble()
2670 con, desc->fd_tag, desc->fd_seg_cnt, desc->fd_lens[0], in handle_preamble()
2673 if (!con_secure(con)) in handle_preamble()
2674 return prepare_read_control(con); in handle_preamble()
2677 return prepare_read_control_remainder(con); in handle_preamble()
2679 return __handle_control(con, CTRL_BODY(con->v2.in_buf)); in handle_preamble()
2682 static int handle_control(struct ceph_connection *con) in handle_control() argument
2684 int ctrl_len = con->v2.in_desc.fd_lens[0]; in handle_control()
2688 WARN_ON(con_secure(con)); in handle_control()
2690 ret = verify_control_crc(con); in handle_control()
2692 con->error_msg = "integrity error, bad crc"; in handle_control()
2696 if (con->state == CEPH_CON_S_V2_AUTH) { in handle_control()
2697 buf = alloc_conn_buf(con, ctrl_len); in handle_control()
2701 memcpy(buf, con->v2.in_kvecs[0].iov_base, ctrl_len); in handle_control()
2702 return __handle_control(con, buf); in handle_control()
2705 return __handle_control(con, con->v2.in_kvecs[0].iov_base); in handle_control()
2708 static int handle_control_remainder(struct ceph_connection *con) in handle_control_remainder() argument
2712 WARN_ON(!con_secure(con)); in handle_control_remainder()
2714 ret = decrypt_control_remainder(con); in handle_control_remainder()
2717 con->error_msg = "integrity error, bad control remainder auth tag"; in handle_control_remainder()
2721 return __handle_control(con, con->v2.in_kvecs[0].iov_base - in handle_control_remainder()
2725 static int handle_epilogue(struct ceph_connection *con) in handle_epilogue() argument
2730 if (con_secure(con)) { in handle_epilogue()
2731 ret = decrypt_message(con); in handle_epilogue()
2734 con->error_msg = "integrity error, bad epilogue auth tag"; in handle_epilogue()
2739 ret = decode_epilogue(con->v2.in_buf, NULL, NULL, NULL); in handle_epilogue()
2741 con->error_msg = "protocol error, bad epilogue"; in handle_epilogue()
2745 ret = decode_epilogue(con->v2.in_buf, &front_crc, in handle_epilogue()
2748 con->error_msg = "protocol error, bad epilogue"; in handle_epilogue()
2752 ret = verify_epilogue_crcs(con, front_crc, middle_crc, in handle_epilogue()
2755 con->error_msg = "integrity error, bad crc"; in handle_epilogue()
2760 return process_message(con); in handle_epilogue()
2763 static void finish_skip(struct ceph_connection *con) in finish_skip() argument
2765 dout("%s con %p\n", __func__, con); in finish_skip()
2767 if (con_secure(con)) in finish_skip()
2768 gcm_inc_nonce(&con->v2.in_gcm_nonce); in finish_skip()
2770 __finish_skip(con); in finish_skip()
2773 static int populate_in_iter(struct ceph_connection *con) in populate_in_iter() argument
2777 dout("%s con %p state %d in_state %d\n", __func__, con, con->state, in populate_in_iter()
2778 con->v2.in_state); in populate_in_iter()
2779 WARN_ON(iov_iter_count(&con->v2.in_iter)); in populate_in_iter()
2781 if (con->state == CEPH_CON_S_V2_BANNER_PREFIX) { in populate_in_iter()
2782 ret = process_banner_prefix(con); in populate_in_iter()
2783 } else if (con->state == CEPH_CON_S_V2_BANNER_PAYLOAD) { in populate_in_iter()
2784 ret = process_banner_payload(con); in populate_in_iter()
2785 } else if ((con->state >= CEPH_CON_S_V2_HELLO && in populate_in_iter()
2786 con->state <= CEPH_CON_S_V2_SESSION_RECONNECT) || in populate_in_iter()
2787 con->state == CEPH_CON_S_OPEN) { in populate_in_iter()
2788 switch (con->v2.in_state) { in populate_in_iter()
2790 ret = handle_preamble(con); in populate_in_iter()
2793 ret = handle_control(con); in populate_in_iter()
2796 ret = handle_control_remainder(con); in populate_in_iter()
2799 prepare_read_data(con); in populate_in_iter()
2803 prepare_read_data_cont(con); in populate_in_iter()
2807 ret = handle_epilogue(con); in populate_in_iter()
2810 finish_skip(con); in populate_in_iter()
2814 WARN(1, "bad in_state %d", con->v2.in_state); in populate_in_iter()
2818 WARN(1, "bad state %d", con->state); in populate_in_iter()
2822 dout("%s con %p error %d\n", __func__, con, ret); in populate_in_iter()
2826 if (WARN_ON(!iov_iter_count(&con->v2.in_iter))) in populate_in_iter()
2828 dout("%s con %p populated %zu\n", __func__, con, in populate_in_iter()
2829 iov_iter_count(&con->v2.in_iter)); in populate_in_iter()
2833 int ceph_con_v2_try_read(struct ceph_connection *con) in ceph_con_v2_try_read() argument
2837 dout("%s con %p state %d need %zu\n", __func__, con, con->state, in ceph_con_v2_try_read()
2838 iov_iter_count(&con->v2.in_iter)); in ceph_con_v2_try_read()
2840 if (con->state == CEPH_CON_S_PREOPEN) in ceph_con_v2_try_read()
2848 if (WARN_ON(!iov_iter_count(&con->v2.in_iter))) in ceph_con_v2_try_read()
2852 ret = ceph_tcp_recv(con); in ceph_con_v2_try_read()
2856 ret = populate_in_iter(con); in ceph_con_v2_try_read()
2858 if (ret && ret != -EAGAIN && !con->error_msg) in ceph_con_v2_try_read()
2859 con->error_msg = "read processing error"; in ceph_con_v2_try_read()
2865 static void queue_data(struct ceph_connection *con) in queue_data() argument
2869 con->v2.out_epil.data_crc = -1; in queue_data()
2870 ceph_msg_data_cursor_init(&con->v2.out_cursor, con->out_msg, in queue_data()
2871 data_len(con->out_msg)); in queue_data()
2873 get_bvec_at(&con->v2.out_cursor, &bv); in queue_data()
2874 set_out_bvec(con, &bv, true); in queue_data()
2875 con->v2.out_state = OUT_S_QUEUE_DATA_CONT; in queue_data()
2878 static void queue_data_cont(struct ceph_connection *con) in queue_data_cont() argument
2882 con->v2.out_epil.data_crc = ceph_crc32c_page( in queue_data_cont()
2883 con->v2.out_epil.data_crc, con->v2.out_bvec.bv_page, in queue_data_cont()
2884 con->v2.out_bvec.bv_offset, con->v2.out_bvec.bv_len); in queue_data_cont()
2886 ceph_msg_data_advance(&con->v2.out_cursor, con->v2.out_bvec.bv_len); in queue_data_cont()
2887 if (con->v2.out_cursor.total_resid) { in queue_data_cont()
2888 get_bvec_at(&con->v2.out_cursor, &bv); in queue_data_cont()
2889 set_out_bvec(con, &bv, true); in queue_data_cont()
2890 WARN_ON(con->v2.out_state != OUT_S_QUEUE_DATA_CONT); in queue_data_cont()
2898 reset_out_kvecs(con); in queue_data_cont()
2899 prepare_epilogue_plain(con, false); in queue_data_cont()
2900 con->v2.out_state = OUT_S_FINISH_MESSAGE; in queue_data_cont()
2903 static void queue_enc_page(struct ceph_connection *con) in queue_enc_page() argument
2907 dout("%s con %p i %d resid %d\n", __func__, con, con->v2.out_enc_i, in queue_enc_page()
2908 con->v2.out_enc_resid); in queue_enc_page()
2909 WARN_ON(!con->v2.out_enc_resid); in queue_enc_page()
2911 bv.bv_page = con->v2.out_enc_pages[con->v2.out_enc_i]; in queue_enc_page()
2913 bv.bv_len = min(con->v2.out_enc_resid, (int)PAGE_SIZE); in queue_enc_page()
2915 set_out_bvec(con, &bv, false); in queue_enc_page()
2916 con->v2.out_enc_i++; in queue_enc_page()
2917 con->v2.out_enc_resid -= bv.bv_len; in queue_enc_page()
2919 if (con->v2.out_enc_resid) { in queue_enc_page()
2920 WARN_ON(con->v2.out_state != OUT_S_QUEUE_ENC_PAGE); in queue_enc_page()
2928 WARN_ON(con->v2.out_enc_i != con->v2.out_enc_page_cnt); in queue_enc_page()
2929 con->v2.out_state = OUT_S_FINISH_MESSAGE; in queue_enc_page()
2932 static void queue_zeros(struct ceph_connection *con) in queue_zeros() argument
2934 dout("%s con %p out_zero %d\n", __func__, con, con->v2.out_zero); in queue_zeros()
2936 if (con->v2.out_zero) { in queue_zeros()
2937 set_out_bvec_zero(con); in queue_zeros()
2938 con->v2.out_zero -= con->v2.out_bvec.bv_len; in queue_zeros()
2939 con->v2.out_state = OUT_S_QUEUE_ZEROS; in queue_zeros()
2948 reset_out_kvecs(con); in queue_zeros()
2949 prepare_epilogue_plain(con, true); in queue_zeros()
2950 con->v2.out_state = OUT_S_FINISH_MESSAGE; in queue_zeros()
2953 static void finish_message(struct ceph_connection *con) in finish_message() argument
2955 dout("%s con %p msg %p\n", __func__, con, con->out_msg); in finish_message()
2958 if (con->v2.out_enc_pages) { in finish_message()
2959 WARN_ON(!con->v2.out_enc_page_cnt); in finish_message()
2960 ceph_release_page_vector(con->v2.out_enc_pages, in finish_message()
2961 con->v2.out_enc_page_cnt); in finish_message()
2962 con->v2.out_enc_pages = NULL; in finish_message()
2963 con->v2.out_enc_page_cnt = 0; in finish_message()
2966 if (con->out_msg) { in finish_message()
2967 ceph_msg_put(con->out_msg); in finish_message()
2968 con->out_msg = NULL; in finish_message()
2971 con->v2.out_state = OUT_S_GET_NEXT; in finish_message()
2974 static int populate_out_iter(struct ceph_connection *con) in populate_out_iter() argument
2978 dout("%s con %p state %d out_state %d\n", __func__, con, con->state, in populate_out_iter()
2979 con->v2.out_state); in populate_out_iter()
2980 WARN_ON(iov_iter_count(&con->v2.out_iter)); in populate_out_iter()
2982 if (con->state != CEPH_CON_S_OPEN) { in populate_out_iter()
2983 WARN_ON(con->state < CEPH_CON_S_V2_BANNER_PREFIX || in populate_out_iter()
2984 con->state > CEPH_CON_S_V2_SESSION_RECONNECT); in populate_out_iter()
2988 switch (con->v2.out_state) { in populate_out_iter()
2990 WARN_ON(!con->out_msg); in populate_out_iter()
2991 queue_data(con); in populate_out_iter()
2994 WARN_ON(!con->out_msg); in populate_out_iter()
2995 queue_data_cont(con); in populate_out_iter()
2998 queue_enc_page(con); in populate_out_iter()
3001 WARN_ON(con->out_msg); /* revoked */ in populate_out_iter()
3002 queue_zeros(con); in populate_out_iter()
3005 finish_message(con); in populate_out_iter()
3010 WARN(1, "bad out_state %d", con->v2.out_state); in populate_out_iter()
3014 WARN_ON(con->v2.out_state != OUT_S_GET_NEXT); in populate_out_iter()
3015 if (ceph_con_flag_test_and_clear(con, CEPH_CON_F_KEEPALIVE_PENDING)) { in populate_out_iter()
3016 ret = prepare_keepalive2(con); in populate_out_iter()
3021 } else if (!list_empty(&con->out_queue)) { in populate_out_iter()
3022 ceph_con_get_out_msg(con); in populate_out_iter()
3023 ret = prepare_message(con); in populate_out_iter()
3028 } else if (con->in_seq > con->in_seq_acked) { in populate_out_iter()
3029 ret = prepare_ack(con); in populate_out_iter()
3039 if (WARN_ON(!iov_iter_count(&con->v2.out_iter))) in populate_out_iter()
3041 dout("%s con %p populated %zu\n", __func__, con, in populate_out_iter()
3042 iov_iter_count(&con->v2.out_iter)); in populate_out_iter()
3046 WARN_ON(iov_iter_count(&con->v2.out_iter)); in populate_out_iter()
3047 dout("%s con %p nothing pending\n", __func__, con); in populate_out_iter()
3048 ceph_con_flag_clear(con, CEPH_CON_F_WRITE_PENDING); in populate_out_iter()
3052 int ceph_con_v2_try_write(struct ceph_connection *con) in ceph_con_v2_try_write() argument
3056 dout("%s con %p state %d have %zu\n", __func__, con, con->state, in ceph_con_v2_try_write()
3057 iov_iter_count(&con->v2.out_iter)); in ceph_con_v2_try_write()
3060 if (con->state == CEPH_CON_S_PREOPEN) { in ceph_con_v2_try_write()
3061 WARN_ON(con->peer_addr.type != CEPH_ENTITY_ADDR_TYPE_MSGR2); in ceph_con_v2_try_write()
3068 con->v2.global_seq = ceph_get_global_seq(con->msgr, 0); in ceph_con_v2_try_write()
3069 if (con->v2.server_cookie) in ceph_con_v2_try_write()
3070 con->v2.connect_seq++; in ceph_con_v2_try_write()
3072 ret = prepare_read_banner_prefix(con); in ceph_con_v2_try_write()
3075 con->error_msg = "connect error"; in ceph_con_v2_try_write()
3079 reset_out_kvecs(con); in ceph_con_v2_try_write()
3080 ret = prepare_banner(con); in ceph_con_v2_try_write()
3083 con->error_msg = "connect error"; in ceph_con_v2_try_write()
3087 ret = ceph_tcp_connect(con); in ceph_con_v2_try_write()
3090 con->error_msg = "connect error"; in ceph_con_v2_try_write()
3095 if (!iov_iter_count(&con->v2.out_iter)) { in ceph_con_v2_try_write()
3096 ret = populate_out_iter(con); in ceph_con_v2_try_write()
3098 if (ret && ret != -EAGAIN && !con->error_msg) in ceph_con_v2_try_write()
3099 con->error_msg = "write processing error"; in ceph_con_v2_try_write()
3104 tcp_sock_set_cork(con->sock->sk, true); in ceph_con_v2_try_write()
3106 ret = ceph_tcp_send(con); in ceph_con_v2_try_write()
3110 ret = populate_out_iter(con); in ceph_con_v2_try_write()
3112 if (ret && ret != -EAGAIN && !con->error_msg) in ceph_con_v2_try_write()
3113 con->error_msg = "write processing error"; in ceph_con_v2_try_write()
3118 tcp_sock_set_cork(con->sock->sk, false); in ceph_con_v2_try_write()
3135 static void prepare_zero_front(struct ceph_connection *con, int resid) in prepare_zero_front() argument
3139 WARN_ON(!resid || resid > front_len(con->out_msg)); in prepare_zero_front()
3140 sent = front_len(con->out_msg) - resid; in prepare_zero_front()
3141 dout("%s con %p sent %d resid %d\n", __func__, con, sent, resid); in prepare_zero_front()
3144 con->v2.out_epil.front_crc = in prepare_zero_front()
3145 crc32c(-1, con->out_msg->front.iov_base, sent); in prepare_zero_front()
3146 con->v2.out_epil.front_crc = in prepare_zero_front()
3147 crc32c_zeros(con->v2.out_epil.front_crc, resid); in prepare_zero_front()
3149 con->v2.out_epil.front_crc = crc32c_zeros(-1, resid); in prepare_zero_front()
3152 con->v2.out_iter.count -= resid; in prepare_zero_front()
3153 out_zero_add(con, resid); in prepare_zero_front()
3156 static void prepare_zero_middle(struct ceph_connection *con, int resid) in prepare_zero_middle() argument
3160 WARN_ON(!resid || resid > middle_len(con->out_msg)); in prepare_zero_middle()
3161 sent = middle_len(con->out_msg) - resid; in prepare_zero_middle()
3162 dout("%s con %p sent %d resid %d\n", __func__, con, sent, resid); in prepare_zero_middle()
3165 con->v2.out_epil.middle_crc = in prepare_zero_middle()
3166 crc32c(-1, con->out_msg->middle->vec.iov_base, sent); in prepare_zero_middle()
3167 con->v2.out_epil.middle_crc = in prepare_zero_middle()
3168 crc32c_zeros(con->v2.out_epil.middle_crc, resid); in prepare_zero_middle()
3170 con->v2.out_epil.middle_crc = crc32c_zeros(-1, resid); in prepare_zero_middle()
3173 con->v2.out_iter.count -= resid; in prepare_zero_middle()
3174 out_zero_add(con, resid); in prepare_zero_middle()
3177 static void prepare_zero_data(struct ceph_connection *con) in prepare_zero_data() argument
3179 dout("%s con %p\n", __func__, con); in prepare_zero_data()
3180 con->v2.out_epil.data_crc = crc32c_zeros(-1, data_len(con->out_msg)); in prepare_zero_data()
3181 out_zero_add(con, data_len(con->out_msg)); in prepare_zero_data()
3184 static void revoke_at_queue_data(struct ceph_connection *con) in revoke_at_queue_data() argument
3189 WARN_ON(!data_len(con->out_msg)); in revoke_at_queue_data()
3190 WARN_ON(!iov_iter_is_kvec(&con->v2.out_iter)); in revoke_at_queue_data()
3191 resid = iov_iter_count(&con->v2.out_iter); in revoke_at_queue_data()
3193 boundary = front_len(con->out_msg) + middle_len(con->out_msg); in revoke_at_queue_data()
3197 dout("%s con %p was sending head\n", __func__, con); in revoke_at_queue_data()
3198 if (front_len(con->out_msg)) in revoke_at_queue_data()
3199 prepare_zero_front(con, front_len(con->out_msg)); in revoke_at_queue_data()
3200 if (middle_len(con->out_msg)) in revoke_at_queue_data()
3201 prepare_zero_middle(con, middle_len(con->out_msg)); in revoke_at_queue_data()
3202 prepare_zero_data(con); in revoke_at_queue_data()
3203 WARN_ON(iov_iter_count(&con->v2.out_iter) != resid); in revoke_at_queue_data()
3204 con->v2.out_state = OUT_S_QUEUE_ZEROS; in revoke_at_queue_data()
3208 boundary = middle_len(con->out_msg); in revoke_at_queue_data()
3211 dout("%s con %p was sending front\n", __func__, con); in revoke_at_queue_data()
3212 prepare_zero_front(con, resid); in revoke_at_queue_data()
3213 if (middle_len(con->out_msg)) in revoke_at_queue_data()
3214 prepare_zero_middle(con, middle_len(con->out_msg)); in revoke_at_queue_data()
3215 prepare_zero_data(con); in revoke_at_queue_data()
3216 queue_zeros(con); in revoke_at_queue_data()
3221 dout("%s con %p was sending middle\n", __func__, con); in revoke_at_queue_data()
3222 prepare_zero_middle(con, resid); in revoke_at_queue_data()
3223 prepare_zero_data(con); in revoke_at_queue_data()
3224 queue_zeros(con); in revoke_at_queue_data()
3227 static void revoke_at_queue_data_cont(struct ceph_connection *con) in revoke_at_queue_data_cont() argument
3231 WARN_ON(!data_len(con->out_msg)); in revoke_at_queue_data_cont()
3232 WARN_ON(!iov_iter_is_bvec(&con->v2.out_iter)); in revoke_at_queue_data_cont()
3233 resid = iov_iter_count(&con->v2.out_iter); in revoke_at_queue_data_cont()
3234 WARN_ON(!resid || resid > con->v2.out_bvec.bv_len); in revoke_at_queue_data_cont()
3235 sent = con->v2.out_bvec.bv_len - resid; in revoke_at_queue_data_cont()
3236 dout("%s con %p sent %d resid %d\n", __func__, con, sent, resid); in revoke_at_queue_data_cont()
3239 con->v2.out_epil.data_crc = ceph_crc32c_page( in revoke_at_queue_data_cont()
3240 con->v2.out_epil.data_crc, con->v2.out_bvec.bv_page, in revoke_at_queue_data_cont()
3241 con->v2.out_bvec.bv_offset, sent); in revoke_at_queue_data_cont()
3242 ceph_msg_data_advance(&con->v2.out_cursor, sent); in revoke_at_queue_data_cont()
3244 WARN_ON(resid > con->v2.out_cursor.total_resid); in revoke_at_queue_data_cont()
3245 con->v2.out_epil.data_crc = crc32c_zeros(con->v2.out_epil.data_crc, in revoke_at_queue_data_cont()
3246 con->v2.out_cursor.total_resid); in revoke_at_queue_data_cont()
3248 con->v2.out_iter.count -= resid; in revoke_at_queue_data_cont()
3249 out_zero_add(con, con->v2.out_cursor.total_resid); in revoke_at_queue_data_cont()
3250 queue_zeros(con); in revoke_at_queue_data_cont()
3253 static void revoke_at_finish_message(struct ceph_connection *con) in revoke_at_finish_message() argument
3258 WARN_ON(!iov_iter_is_kvec(&con->v2.out_iter)); in revoke_at_finish_message()
3259 resid = iov_iter_count(&con->v2.out_iter); in revoke_at_finish_message()
3261 if (!front_len(con->out_msg) && !middle_len(con->out_msg) && in revoke_at_finish_message()
3262 !data_len(con->out_msg)) { in revoke_at_finish_message()
3265 __func__, con); in revoke_at_finish_message()
3269 boundary = front_len(con->out_msg) + middle_len(con->out_msg) + in revoke_at_finish_message()
3274 dout("%s con %p was sending head\n", __func__, con); in revoke_at_finish_message()
3275 if (front_len(con->out_msg)) in revoke_at_finish_message()
3276 prepare_zero_front(con, front_len(con->out_msg)); in revoke_at_finish_message()
3277 if (middle_len(con->out_msg)) in revoke_at_finish_message()
3278 prepare_zero_middle(con, middle_len(con->out_msg)); in revoke_at_finish_message()
3279 con->v2.out_iter.count -= CEPH_EPILOGUE_PLAIN_LEN; in revoke_at_finish_message()
3280 WARN_ON(iov_iter_count(&con->v2.out_iter) != resid); in revoke_at_finish_message()
3281 con->v2.out_state = OUT_S_QUEUE_ZEROS; in revoke_at_finish_message()
3285 boundary = middle_len(con->out_msg) + CEPH_EPILOGUE_PLAIN_LEN; in revoke_at_finish_message()
3288 dout("%s con %p was sending front\n", __func__, con); in revoke_at_finish_message()
3289 prepare_zero_front(con, resid); in revoke_at_finish_message()
3290 if (middle_len(con->out_msg)) in revoke_at_finish_message()
3291 prepare_zero_middle(con, middle_len(con->out_msg)); in revoke_at_finish_message()
3292 con->v2.out_iter.count -= CEPH_EPILOGUE_PLAIN_LEN; in revoke_at_finish_message()
3293 queue_zeros(con); in revoke_at_finish_message()
3300 dout("%s con %p was sending middle\n", __func__, con); in revoke_at_finish_message()
3301 prepare_zero_middle(con, resid); in revoke_at_finish_message()
3302 con->v2.out_iter.count -= CEPH_EPILOGUE_PLAIN_LEN; in revoke_at_finish_message()
3303 queue_zeros(con); in revoke_at_finish_message()
3308 dout("%s con %p was sending epilogue - noop\n", __func__, con); in revoke_at_finish_message()
3311 void ceph_con_v2_revoke(struct ceph_connection *con) in ceph_con_v2_revoke() argument
3313 WARN_ON(con->v2.out_zero); in ceph_con_v2_revoke()
3315 if (con_secure(con)) { in ceph_con_v2_revoke()
3316 WARN_ON(con->v2.out_state != OUT_S_QUEUE_ENC_PAGE && in ceph_con_v2_revoke()
3317 con->v2.out_state != OUT_S_FINISH_MESSAGE); in ceph_con_v2_revoke()
3318 dout("%s con %p secure - noop\n", __func__, con); in ceph_con_v2_revoke()
3322 switch (con->v2.out_state) { in ceph_con_v2_revoke()
3324 revoke_at_queue_data(con); in ceph_con_v2_revoke()
3327 revoke_at_queue_data_cont(con); in ceph_con_v2_revoke()
3330 revoke_at_finish_message(con); in ceph_con_v2_revoke()
3333 WARN(1, "bad out_state %d", con->v2.out_state); in ceph_con_v2_revoke()
3338 static void revoke_at_prepare_read_data(struct ceph_connection *con) in revoke_at_prepare_read_data() argument
3343 WARN_ON(!data_len(con->in_msg)); in revoke_at_prepare_read_data()
3344 WARN_ON(!iov_iter_is_kvec(&con->v2.in_iter)); in revoke_at_prepare_read_data()
3345 resid = iov_iter_count(&con->v2.in_iter); in revoke_at_prepare_read_data()
3348 if (con_secure(con)) in revoke_at_prepare_read_data()
3349 remaining = padded_len(data_len(con->in_msg)) + in revoke_at_prepare_read_data()
3352 remaining = data_len(con->in_msg) + CEPH_EPILOGUE_PLAIN_LEN; in revoke_at_prepare_read_data()
3354 dout("%s con %p resid %d remaining %d\n", __func__, con, resid, in revoke_at_prepare_read_data()
3356 con->v2.in_iter.count -= resid; in revoke_at_prepare_read_data()
3357 set_in_skip(con, resid + remaining); in revoke_at_prepare_read_data()
3358 con->v2.in_state = IN_S_FINISH_SKIP; in revoke_at_prepare_read_data()
3361 static void revoke_at_prepare_read_data_cont(struct ceph_connection *con) in revoke_at_prepare_read_data_cont() argument
3366 WARN_ON(!data_len(con->in_msg)); in revoke_at_prepare_read_data_cont()
3367 WARN_ON(!iov_iter_is_bvec(&con->v2.in_iter)); in revoke_at_prepare_read_data_cont()
3368 resid = iov_iter_count(&con->v2.in_iter); in revoke_at_prepare_read_data_cont()
3369 WARN_ON(!resid || resid > con->v2.in_bvec.bv_len); in revoke_at_prepare_read_data_cont()
3370 recved = con->v2.in_bvec.bv_len - resid; in revoke_at_prepare_read_data_cont()
3371 dout("%s con %p recved %d resid %d\n", __func__, con, recved, resid); in revoke_at_prepare_read_data_cont()
3374 ceph_msg_data_advance(&con->v2.in_cursor, recved); in revoke_at_prepare_read_data_cont()
3375 WARN_ON(resid > con->v2.in_cursor.total_resid); in revoke_at_prepare_read_data_cont()
3377 if (con_secure(con)) in revoke_at_prepare_read_data_cont()
3378 remaining = padding_len(data_len(con->in_msg)) + in revoke_at_prepare_read_data_cont()
3383 dout("%s con %p total_resid %zu remaining %d\n", __func__, con, in revoke_at_prepare_read_data_cont()
3384 con->v2.in_cursor.total_resid, remaining); in revoke_at_prepare_read_data_cont()
3385 con->v2.in_iter.count -= resid; in revoke_at_prepare_read_data_cont()
3386 set_in_skip(con, con->v2.in_cursor.total_resid + remaining); in revoke_at_prepare_read_data_cont()
3387 con->v2.in_state = IN_S_FINISH_SKIP; in revoke_at_prepare_read_data_cont()
3390 static void revoke_at_handle_epilogue(struct ceph_connection *con) in revoke_at_handle_epilogue() argument
3394 WARN_ON(!iov_iter_is_kvec(&con->v2.in_iter)); in revoke_at_handle_epilogue()
3395 resid = iov_iter_count(&con->v2.in_iter); in revoke_at_handle_epilogue()
3398 dout("%s con %p resid %d\n", __func__, con, resid); in revoke_at_handle_epilogue()
3399 con->v2.in_iter.count -= resid; in revoke_at_handle_epilogue()
3400 set_in_skip(con, resid); in revoke_at_handle_epilogue()
3401 con->v2.in_state = IN_S_FINISH_SKIP; in revoke_at_handle_epilogue()
3404 void ceph_con_v2_revoke_incoming(struct ceph_connection *con) in ceph_con_v2_revoke_incoming() argument
3406 switch (con->v2.in_state) { in ceph_con_v2_revoke_incoming()
3408 revoke_at_prepare_read_data(con); in ceph_con_v2_revoke_incoming()
3411 revoke_at_prepare_read_data_cont(con); in ceph_con_v2_revoke_incoming()
3414 revoke_at_handle_epilogue(con); in ceph_con_v2_revoke_incoming()
3417 WARN(1, "bad in_state %d", con->v2.in_state); in ceph_con_v2_revoke_incoming()
3422 bool ceph_con_v2_opened(struct ceph_connection *con) in ceph_con_v2_opened() argument
3424 return con->v2.peer_global_seq; in ceph_con_v2_opened()
3427 void ceph_con_v2_reset_session(struct ceph_connection *con) in ceph_con_v2_reset_session() argument
3429 con->v2.client_cookie = 0; in ceph_con_v2_reset_session()
3430 con->v2.server_cookie = 0; in ceph_con_v2_reset_session()
3431 con->v2.global_seq = 0; in ceph_con_v2_reset_session()
3432 con->v2.connect_seq = 0; in ceph_con_v2_reset_session()
3433 con->v2.peer_global_seq = 0; in ceph_con_v2_reset_session()
3436 void ceph_con_v2_reset_protocol(struct ceph_connection *con) in ceph_con_v2_reset_protocol() argument
3438 iov_iter_truncate(&con->v2.in_iter, 0); in ceph_con_v2_reset_protocol()
3439 iov_iter_truncate(&con->v2.out_iter, 0); in ceph_con_v2_reset_protocol()
3440 con->v2.out_zero = 0; in ceph_con_v2_reset_protocol()
3442 clear_in_sign_kvecs(con); in ceph_con_v2_reset_protocol()
3443 clear_out_sign_kvecs(con); in ceph_con_v2_reset_protocol()
3444 free_conn_bufs(con); in ceph_con_v2_reset_protocol()
3446 if (con->v2.out_enc_pages) { in ceph_con_v2_reset_protocol()
3447 WARN_ON(!con->v2.out_enc_page_cnt); in ceph_con_v2_reset_protocol()
3448 ceph_release_page_vector(con->v2.out_enc_pages, in ceph_con_v2_reset_protocol()
3449 con->v2.out_enc_page_cnt); in ceph_con_v2_reset_protocol()
3450 con->v2.out_enc_pages = NULL; in ceph_con_v2_reset_protocol()
3451 con->v2.out_enc_page_cnt = 0; in ceph_con_v2_reset_protocol()
3454 con->v2.con_mode = CEPH_CON_MODE_UNKNOWN; in ceph_con_v2_reset_protocol()
3455 memzero_explicit(&con->v2.in_gcm_nonce, CEPH_GCM_IV_LEN); in ceph_con_v2_reset_protocol()
3456 memzero_explicit(&con->v2.out_gcm_nonce, CEPH_GCM_IV_LEN); in ceph_con_v2_reset_protocol()
3458 if (con->v2.hmac_tfm) { in ceph_con_v2_reset_protocol()
3459 crypto_free_shash(con->v2.hmac_tfm); in ceph_con_v2_reset_protocol()
3460 con->v2.hmac_tfm = NULL; in ceph_con_v2_reset_protocol()
3462 if (con->v2.gcm_req) { in ceph_con_v2_reset_protocol()
3463 aead_request_free(con->v2.gcm_req); in ceph_con_v2_reset_protocol()
3464 con->v2.gcm_req = NULL; in ceph_con_v2_reset_protocol()
3466 if (con->v2.gcm_tfm) { in ceph_con_v2_reset_protocol()
3467 crypto_free_aead(con->v2.gcm_tfm); in ceph_con_v2_reset_protocol()
3468 con->v2.gcm_tfm = NULL; in ceph_con_v2_reset_protocol()