• Home
  • Raw
  • Download

Lines Matching full:tcp

15 #include <linux/tcp.h>
83 struct tcp_handle *tcp = NULL; in hmdfs_tcpi_rtt() local
88 tcp = (struct tcp_handle *)(conn_impl->connect_handle); in hmdfs_tcpi_rtt()
89 if (tcp->sock) in hmdfs_tcpi_rtt()
90 rtt_us = tcp_sk(tcp->sock->sk)->srtt_us >> 3; in hmdfs_tcpi_rtt()
117 hmdfs_err("tcp recv error %d", rc); in tcp_read_head_from_socket()
153 hmdfs_err("tcp recv error %d", rc); in tcp_read_buffer_from_socket()
219 struct tcp_handle *tcp = NULL; in tcp_recvpage_tls() local
226 hmdfs_err("tcp connect == NULL"); in tcp_recvpage_tls()
230 tcp = (struct tcp_handle *)(connect->connect_handle); in tcp_recvpage_tls()
234 hmdfs_warning("tcp: readpage from peer %llu ret err %d", in tcp_recvpage_tls()
249 ret = hmdfs_get_readpage_buffer(tcp->sock, recv, page); in tcp_recvpage_tls()
264 ret = hmdfs_drop_readpage_buffer(tcp->sock, recv); in tcp_recvpage_tls()
397 struct tcp_handle *tcp = NULL; in tcp_recvbuffer_cipher() local
404 tcp = (struct tcp_handle *)(connect->connect_handle); in tcp_recvbuffer_cipher()
426 ret = tcp_read_buffer_from_socket(tcp->sock, cipherbuffer, in tcp_recvbuffer_cipher()
456 struct tcp_handle *tcp = NULL; in tcp_recvbuffer_tls() local
461 tcp = (struct tcp_handle *)(connect->connect_handle); in tcp_recvbuffer_tls()
476 ret = tcp_read_buffer_from_socket(tcp->sock, outdata, outlen); in tcp_recvbuffer_tls()
481 tcp->connect->stat.recv_bytes += outlen; in tcp_recvbuffer_tls()
493 static int tcp_receive_from_sock(struct tcp_handle *tcp) in tcp_receive_from_sock() argument
498 if (!tcp) { in tcp_receive_from_sock()
499 hmdfs_info("tcp recv thread !tcp"); in tcp_receive_from_sock()
503 if (!tcp->sock) { in tcp_receive_from_sock()
504 hmdfs_info("tcp recv thread !sock"); in tcp_receive_from_sock()
508 recv = kmem_cache_alloc(tcp->recv_cache, GFP_KERNEL); in tcp_receive_from_sock()
510 hmdfs_info("tcp recv thread !cache"); in tcp_receive_from_sock()
514 ret = tcp_read_head_from_socket(tcp->sock, recv, in tcp_receive_from_sock()
519 tcp->connect->stat.recv_bytes += sizeof(struct hmdfs_head_cmd); in tcp_receive_from_sock()
520 tcp->connect->stat.recv_message_count++; in tcp_receive_from_sock()
523 hmdfs_info_ratelimited("tcp recv fd %d wrong magic. drop message", in tcp_receive_from_sock()
524 tcp->fd); in tcp_receive_from_sock()
531 hmdfs_info("tcp recv fd %d length error. drop message", in tcp_receive_from_sock()
532 tcp->fd); in tcp_receive_from_sock()
536 if (tcp->connect->status == CONNECT_STAT_WORKING && in tcp_receive_from_sock()
539 ret = tcp_recvpage_tls(tcp->connect, recv); in tcp_receive_from_sock()
543 if (tcp->connect->status == CONNECT_STAT_WORKING) in tcp_receive_from_sock()
544 ret = tcp_recvbuffer_tls(tcp->connect, recv); in tcp_receive_from_sock()
546 ret = tcp_recvbuffer_cipher(tcp->connect, recv); in tcp_receive_from_sock()
549 kmem_cache_free(tcp->recv_cache, recv); in tcp_receive_from_sock()
553 static bool tcp_handle_is_available(struct tcp_handle *tcp) in tcp_handle_is_available() argument
560 if (!tcp || !tcp->sock || !tcp->sock->sk) { in tcp_handle_is_available()
561 hmdfs_err("Invalid tcp connection"); in tcp_handle_is_available()
565 if (tcp->sock->sk->sk_state != TCP_ESTABLISHED) { in tcp_handle_is_available()
566 hmdfs_err("TCP conn %d is broken, current sk_state is %d", in tcp_handle_is_available()
567 tcp->fd, tcp->sock->sk->sk_state); in tcp_handle_is_available()
571 if (tcp->sock->state != SS_CONNECTING && in tcp_handle_is_available()
572 tcp->sock->state != SS_CONNECTED) { in tcp_handle_is_available()
573 hmdfs_err("TCP conn %d is broken, current sock state is %d", in tcp_handle_is_available()
574 tcp->fd, tcp->sock->state); in tcp_handle_is_available()
579 tls_ctx = tls_get_ctx(tcp->sock->sk); in tcp_handle_is_available()
584 "TCP conn %d is broken, the strparser has stopped", in tcp_handle_is_available()
585 tcp->fd); in tcp_handle_is_available()
596 struct tcp_handle *tcp = (struct tcp_handle *)arg; in tcp_recv_thread() local
599 WARN_ON(!tcp); in tcp_recv_thread()
600 WARN_ON(!tcp->sock); in tcp_recv_thread()
603 old_cred = hmdfs_override_creds(tcp->connect->node->sbi->system_cred); in tcp_recv_thread()
611 if (tcp_handle_is_available(tcp) && in tcp_recv_thread()
612 list_empty(&tcp->connect->list)) in tcp_recv_thread()
614 if (!mutex_trylock(&tcp->close_mutex)) in tcp_recv_thread()
616 if (tcp_handle_is_available(tcp)) in tcp_recv_thread()
617 ret = tcp_receive_from_sock(tcp); in tcp_recv_thread()
626 tcp->recv_task = NULL; in tcp_recv_thread()
627 mutex_unlock(&tcp->close_mutex); in tcp_recv_thread()
629 hmdfs_node_inc_evt_seq(tcp->connect->node); in tcp_recv_thread()
630 tcp->connect->status = CONNECT_STAT_STOP; in tcp_recv_thread()
631 if (tcp->connect->node->status != NODE_STAT_OFFLINE) in tcp_recv_thread()
632 hmdfs_reget_connection(tcp->connect); in tcp_recv_thread()
640 hmdfs_info("Exiting. Now, sock state = %d", tcp->sock->state); in tcp_recv_thread()
642 connection_put(tcp->connect); in tcp_recv_thread()
646 static int tcp_send_message_sock_cipher(struct tcp_handle *tcp, in tcp_send_message_sock_cipher() argument
658 if (!tcp || !tcp->sock) { in tcp_send_message_sock_cipher()
659 hmdfs_err("encrypt tcp socket = NULL"); in tcp_send_message_sock_cipher()
671 hmdfs_err("tcp send message encrypt fail to alloc outdata"); in tcp_send_message_sock_cipher()
674 ret = aeadcipher_encrypt_buffer(tcp->connect, msg->data, msg->len, in tcp_send_message_sock_cipher()
684 mutex_lock(&tcp->send_mutex); in tcp_send_message_sock_cipher()
685 send_len = sendmsg_nofs(tcp->sock, &tcp_msg, iov, send_vec_cnt, in tcp_send_message_sock_cipher()
687 mutex_unlock(&tcp->send_mutex); in tcp_send_message_sock_cipher()
703 static int tcp_send_message_sock_tls(struct tcp_handle *tcp, in tcp_send_message_sock_tls() argument
712 if (!tcp || !tcp->sock) { in tcp_send_message_sock_tls()
713 hmdfs_err("tcp socket = NULL"); in tcp_send_message_sock_tls()
731 mutex_lock(&tcp->send_mutex); in tcp_send_message_sock_tls()
732 send_len = sendmsg_nofs(tcp->sock, &tcp_msg, iov, send_vec_cnt, in tcp_send_message_sock_tls()
734 mutex_unlock(&tcp->send_mutex); in tcp_send_message_sock_tls()
743 tcp->connect->stat.send_bytes += send_len; in tcp_send_message_sock_tls()
746 tcp->connect->stat.send_bytes += send_len; in tcp_send_message_sock_tls()
747 tcp->connect->stat.send_message_count++; in tcp_send_message_sock_tls()
756 struct tcp_handle *tcp = connect->connect_handle; in tcp_send_rekey_request() local
788 ret = tcp_send_message_sock_tls(tcp, &msg); in tcp_send_rekey_request()
803 struct tcp_handle *tcp = NULL; in tcp_send_message() local
806 hmdfs_err("tcp connection = NULL "); in tcp_send_message()
817 tcp = (struct tcp_handle *)(connect->connect_handle); in tcp_send_message()
824 ret = tcp_send_message_sock_tls(tcp, msg); in tcp_send_message()
826 ret = tcp_send_message_sock_cipher(tcp, msg); in tcp_send_message()
846 void tcp_close_socket(struct tcp_handle *tcp) in tcp_close_socket() argument
849 if (!tcp) in tcp_close_socket()
851 mutex_lock(&tcp->close_mutex); in tcp_close_socket()
852 if (tcp->recv_task) { in tcp_close_socket()
853 ret = kthread_stop(tcp->recv_task); in tcp_close_socket()
856 connection_put(tcp->connect); in tcp_close_socket()
857 tcp->recv_task = NULL; in tcp_close_socket()
859 mutex_unlock(&tcp->close_mutex); in tcp_close_socket()
890 static bool is_tcp_socket(struct tcp_handle *tcp) in is_tcp_socket() argument
894 if (!tcp || !tcp->sock || !tcp->sock->sk) { in is_tcp_socket()
895 hmdfs_err("invalid tcp handle"); in is_tcp_socket()
899 lock_sock(tcp->sock->sk); in is_tcp_socket()
900 if (tcp->sock->sk->sk_protocol != IPPROTO_TCP || in is_tcp_socket()
901 tcp->sock->type != SOCK_STREAM || in is_tcp_socket()
902 tcp->sock->sk->sk_family != AF_INET) { in is_tcp_socket()
904 release_sock(tcp->sock->sk); in is_tcp_socket()
908 icsk = inet_csk(tcp->sock->sk); in is_tcp_socket()
911 release_sock(tcp->sock->sk); in is_tcp_socket()
915 release_sock(tcp->sock->sk); in is_tcp_socket()
919 static int tcp_update_socket(struct tcp_handle *tcp, int fd, in tcp_update_socket() argument
928 tcp->sock = socket; in tcp_update_socket()
929 tcp->fd = fd; in tcp_update_socket()
931 if (!is_tcp_socket(tcp)) { in tcp_update_socket()
936 if (!tcp_handle_is_available(tcp)) { in tcp_update_socket()
945 tcp->recv_cache = kmem_cache_create("hmdfs_socket", in tcp_update_socket()
946 tcp->recvbuf_maxsize, in tcp_update_socket()
948 if (!tcp->recv_cache) { in tcp_update_socket()
955 hmdfs_err("tcp set timeout error"); in tcp_update_socket()
960 memcpy(tcp->connect->master_key, master_key, HMDFS_KEY_SIZE); in tcp_update_socket()
961 memcpy(tcp->connect->send_key, master_key, HMDFS_KEY_SIZE); in tcp_update_socket()
962 memcpy(tcp->connect->recv_key, master_key, HMDFS_KEY_SIZE); in tcp_update_socket()
963 tcp->connect->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); in tcp_update_socket()
964 if (IS_ERR(tcp->connect->tfm)) { in tcp_update_socket()
965 err = PTR_ERR(tcp->connect->tfm); in tcp_update_socket()
966 tcp->connect->tfm = NULL; in tcp_update_socket()
971 err = set_tfm(master_key, tcp->connect->tfm); in tcp_update_socket()
977 connection_get(tcp->connect); in tcp_update_socket()
979 node = tcp->connect->node; in tcp_update_socket()
980 tcp->recv_task = kthread_create(tcp_recv_thread, (void *)tcp, in tcp_update_socket()
983 if (IS_ERR(tcp->recv_task)) { in tcp_update_socket()
984 err = PTR_ERR(tcp->recv_task); in tcp_update_socket()
985 hmdfs_err("tcp->rcev_task %d", err); in tcp_update_socket()
992 tcp->recv_task = NULL; in tcp_update_socket()
993 connection_put(tcp->connect); in tcp_update_socket()
995 crypto_free_aead(tcp->connect->tfm); in tcp_update_socket()
996 tcp->connect->tfm = NULL; in tcp_update_socket()
998 kmem_cache_destroy(tcp->recv_cache); in tcp_update_socket()
999 tcp->recv_cache = NULL; in tcp_update_socket()
1001 tcp->sock = NULL; in tcp_update_socket()
1002 tcp->fd = 0; in tcp_update_socket()
1011 struct tcp_handle *tcp = kzalloc(sizeof(*tcp), GFP_KERNEL); in tcp_alloc_handle() local
1013 if (!tcp) in tcp_alloc_handle()
1015 tcp->connect = connect; in tcp_alloc_handle()
1016 tcp->connect->connect_handle = (void *)tcp; in tcp_alloc_handle()
1017 tcp->recvbuf_maxsize = MAX_RECV_SIZE; in tcp_alloc_handle()
1018 tcp->recv_task = NULL; in tcp_alloc_handle()
1019 tcp->recv_cache = NULL; in tcp_alloc_handle()
1020 tcp->sock = NULL; in tcp_alloc_handle()
1021 mutex_init(&tcp->close_mutex); in tcp_alloc_handle()
1022 mutex_init(&tcp->send_mutex); in tcp_alloc_handle()
1023 ret = tcp_update_socket(tcp, socket_fd, master_key, socket); in tcp_alloc_handle()
1025 kfree(tcp); in tcp_alloc_handle()
1028 return tcp; in tcp_alloc_handle()
1047 struct tcp_handle *tcp = NULL; in connection_notify_to_close() local
1049 tcp = conn->connect_handle; in connection_notify_to_close()
1054 param.fd = tcp->fd; in connection_notify_to_close()
1061 struct tcp_handle *tcp = NULL; in hmdfs_reget_connection() local
1086 tcp = conn->connect_handle; in hmdfs_reget_connection()
1087 if (tcp) { in hmdfs_reget_connection()
1088 recv_task = tcp->recv_task; in hmdfs_reget_connection()
1098 if (tcp) { in hmdfs_reget_connection()
1099 if (tcp->sock) { in hmdfs_reget_connection()
1101 tcp->fd, file_count(tcp->sock->file), in hmdfs_reget_connection()
1103 kernel_sock_shutdown(tcp->sock, SHUT_RDWR); in hmdfs_reget_connection()
1107 tcp_close_socket(tcp); in hmdfs_reget_connection()
1109 if (tcp->fd != INVALID_SOCKET_FD) in hmdfs_reget_connection()
1119 struct tcp_handle *tcp = NULL; in lookup_conn_by_socketfd_unsafe() local
1123 tcp = (struct tcp_handle *)(tcp_conn->connect_handle); in lookup_conn_by_socketfd_unsafe()
1124 if (tcp->sock == socket) { in lookup_conn_by_socketfd_unsafe()
1200 struct tcp_handle *tcp = NULL; in hmdfs_get_conn_tcp() local
1213 hmdfs_info("Got a existing tcp conn: fsocket_fd = %d", in hmdfs_get_conn_tcp()
1221 hmdfs_info("Failed to alloc a tcp conn, socket_fd %d", fd); in hmdfs_get_conn_tcp()
1229 tcp = tcp_conn->connect_handle; in hmdfs_get_conn_tcp()
1231 hmdfs_info("Got a newly allocated tcp conn: socket_fd = %d", fd); in hmdfs_get_conn_tcp()
1232 wake_up_process(tcp->recv_task); in hmdfs_get_conn_tcp()
1238 hmdfs_info("Got a existing tcp conn: socket_fd = %d", fd); in hmdfs_get_conn_tcp()
1239 tcp->fd = INVALID_SOCKET_FD; in hmdfs_get_conn_tcp()
1240 tcp_close_socket(tcp); in hmdfs_get_conn_tcp()