Lines Matching refs:sk
78 void dccp_set_state(struct sock *sk, const int state) in dccp_set_state() argument
80 const int oldstate = sk->sk_state; in dccp_set_state()
82 dccp_pr_debug("%s(%p) %s --> %s\n", dccp_role(sk), sk, in dccp_set_state()
92 dccp_feat_list_purge(&dccp_sk(sk)->dccps_featneg); in dccp_set_state()
100 sk->sk_prot->unhash(sk); in dccp_set_state()
101 if (inet_csk(sk)->icsk_bind_hash != NULL && in dccp_set_state()
102 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) in dccp_set_state()
103 inet_put_port(sk); in dccp_set_state()
113 inet_sk_set_state(sk, state); in dccp_set_state()
118 static void dccp_finish_passive_close(struct sock *sk) in dccp_finish_passive_close() argument
120 switch (sk->sk_state) { in dccp_finish_passive_close()
123 dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED); in dccp_finish_passive_close()
124 dccp_set_state(sk, DCCP_CLOSED); in dccp_finish_passive_close()
131 dccp_send_close(sk, 1); in dccp_finish_passive_close()
132 dccp_set_state(sk, DCCP_CLOSING); in dccp_finish_passive_close()
136 void dccp_done(struct sock *sk) in dccp_done() argument
138 dccp_set_state(sk, DCCP_CLOSED); in dccp_done()
139 dccp_clear_xmit_timers(sk); in dccp_done()
141 sk->sk_shutdown = SHUTDOWN_MASK; in dccp_done()
143 if (!sock_flag(sk, SOCK_DEAD)) in dccp_done()
144 sk->sk_state_change(sk); in dccp_done()
146 inet_csk_destroy_sock(sk); in dccp_done()
174 void dccp_destruct_common(struct sock *sk) in dccp_destruct_common() argument
176 struct dccp_sock *dp = dccp_sk(sk); in dccp_destruct_common()
178 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); in dccp_destruct_common()
183 static void dccp_sk_destruct(struct sock *sk) in dccp_sk_destruct() argument
185 dccp_destruct_common(sk); in dccp_sk_destruct()
186 inet_sock_destruct(sk); in dccp_sk_destruct()
189 int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized) in dccp_init_sock() argument
191 struct dccp_sock *dp = dccp_sk(sk); in dccp_init_sock()
192 struct inet_connection_sock *icsk = inet_csk(sk); in dccp_init_sock()
196 sk->sk_state = DCCP_CLOSED; in dccp_init_sock()
197 sk->sk_write_space = dccp_write_space; in dccp_init_sock()
198 sk->sk_destruct = dccp_sk_destruct; in dccp_init_sock()
206 dccp_init_xmit_timers(sk); in dccp_init_sock()
211 return dccp_feat_init(sk); in dccp_init_sock()
217 void dccp_destroy_sock(struct sock *sk) in dccp_destroy_sock() argument
219 struct dccp_sock *dp = dccp_sk(sk); in dccp_destroy_sock()
221 __skb_queue_purge(&sk->sk_write_queue); in dccp_destroy_sock()
222 if (sk->sk_send_head != NULL) { in dccp_destroy_sock()
223 kfree_skb(sk->sk_send_head); in dccp_destroy_sock()
224 sk->sk_send_head = NULL; in dccp_destroy_sock()
228 if (inet_csk(sk)->icsk_bind_hash != NULL) in dccp_destroy_sock()
229 inet_put_port(sk); in dccp_destroy_sock()
238 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); in dccp_destroy_sock()
247 static inline int dccp_listen_start(struct sock *sk, int backlog) in dccp_listen_start() argument
249 struct dccp_sock *dp = dccp_sk(sk); in dccp_listen_start()
255 return inet_csk_listen_start(sk, backlog); in dccp_listen_start()
264 int dccp_disconnect(struct sock *sk, int flags) in dccp_disconnect() argument
266 struct inet_connection_sock *icsk = inet_csk(sk); in dccp_disconnect()
267 struct inet_sock *inet = inet_sk(sk); in dccp_disconnect()
268 struct dccp_sock *dp = dccp_sk(sk); in dccp_disconnect()
269 const int old_state = sk->sk_state; in dccp_disconnect()
272 dccp_set_state(sk, DCCP_CLOSED); in dccp_disconnect()
279 inet_csk_listen_stop(sk); in dccp_disconnect()
281 dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED); in dccp_disconnect()
282 sk->sk_err = ECONNRESET; in dccp_disconnect()
284 sk->sk_err = ECONNRESET; in dccp_disconnect()
286 dccp_clear_xmit_timers(sk); in dccp_disconnect()
287 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); in dccp_disconnect()
290 __skb_queue_purge(&sk->sk_receive_queue); in dccp_disconnect()
291 __skb_queue_purge(&sk->sk_write_queue); in dccp_disconnect()
292 if (sk->sk_send_head != NULL) { in dccp_disconnect()
293 __kfree_skb(sk->sk_send_head); in dccp_disconnect()
294 sk->sk_send_head = NULL; in dccp_disconnect()
299 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) in dccp_disconnect()
300 inet_reset_saddr(sk); in dccp_disconnect()
302 sk->sk_shutdown = 0; in dccp_disconnect()
303 sock_reset_flag(sk, SOCK_DONE); in dccp_disconnect()
306 inet_csk_delack_init(sk); in dccp_disconnect()
307 __sk_dst_reset(sk); in dccp_disconnect()
311 sk->sk_error_report(sk); in dccp_disconnect()
327 struct sock *sk = sock->sk; in dccp_poll() local
334 state = inet_sk_state_load(sk); in dccp_poll()
336 return inet_csk_listen_poll(sk); in dccp_poll()
344 if (READ_ONCE(sk->sk_err)) in dccp_poll()
346 shutdown = READ_ONCE(sk->sk_shutdown); in dccp_poll()
355 if (atomic_read(&sk->sk_rmem_alloc) > 0) in dccp_poll()
359 if (sk_stream_is_writeable(sk)) { in dccp_poll()
362 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); in dccp_poll()
363 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in dccp_poll()
369 if (sk_stream_is_writeable(sk)) in dccp_poll()
378 int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg) in dccp_ioctl() argument
382 lock_sock(sk); in dccp_ioctl()
384 if (sk->sk_state == DCCP_LISTEN) in dccp_ioctl()
389 int amount = sk_wmem_alloc_get(sk); in dccp_ioctl()
401 skb = skb_peek(&sk->sk_receive_queue); in dccp_ioctl()
417 release_sock(sk); in dccp_ioctl()
423 static int dccp_setsockopt_service(struct sock *sk, const __be32 service, in dccp_setsockopt_service() argument
426 struct dccp_sock *dp = dccp_sk(sk); in dccp_setsockopt_service()
447 lock_sock(sk); in dccp_setsockopt_service()
453 release_sock(sk); in dccp_setsockopt_service()
457 static int dccp_setsockopt_cscov(struct sock *sk, int cscov, bool rx) in dccp_setsockopt_cscov() argument
481 rc = dccp_feat_register_sp(sk, DCCPF_MIN_CSUM_COVER, rx, list, len); in dccp_setsockopt_cscov()
485 dccp_sk(sk)->dccps_pcrlen = cscov; in dccp_setsockopt_cscov()
487 dccp_sk(sk)->dccps_pcslen = cscov; in dccp_setsockopt_cscov()
493 static int dccp_setsockopt_ccid(struct sock *sk, int type, in dccp_setsockopt_ccid() argument
506 lock_sock(sk); in dccp_setsockopt_ccid()
508 rc = dccp_feat_register_sp(sk, DCCPF_CCID, 1, val, optlen); in dccp_setsockopt_ccid()
511 rc = dccp_feat_register_sp(sk, DCCPF_CCID, 0, val, optlen); in dccp_setsockopt_ccid()
512 release_sock(sk); in dccp_setsockopt_ccid()
518 static int do_dccp_setsockopt(struct sock *sk, int level, int optname, in do_dccp_setsockopt() argument
521 struct dccp_sock *dp = dccp_sk(sk); in do_dccp_setsockopt()
535 return dccp_setsockopt_ccid(sk, optname, optval, optlen); in do_dccp_setsockopt()
545 return dccp_setsockopt_service(sk, val, optval, optlen); in do_dccp_setsockopt()
547 lock_sock(sk); in do_dccp_setsockopt()
556 err = dccp_setsockopt_cscov(sk, val, false); in do_dccp_setsockopt()
559 err = dccp_setsockopt_cscov(sk, val, true); in do_dccp_setsockopt()
562 if (sk->sk_state != DCCP_CLOSED) in do_dccp_setsockopt()
579 release_sock(sk); in do_dccp_setsockopt()
584 int dccp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, in dccp_setsockopt() argument
588 return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level, in dccp_setsockopt()
591 return do_dccp_setsockopt(sk, level, optname, optval, optlen); in dccp_setsockopt()
596 static int dccp_getsockopt_service(struct sock *sk, int len, in dccp_getsockopt_service() argument
600 const struct dccp_sock *dp = dccp_sk(sk); in dccp_getsockopt_service()
604 lock_sock(sk); in dccp_getsockopt_service()
620 release_sock(sk); in dccp_getsockopt_service()
624 static int do_dccp_getsockopt(struct sock *sk, int level, int optname, in do_dccp_getsockopt() argument
636 dp = dccp_sk(sk); in do_dccp_getsockopt()
643 return dccp_getsockopt_service(sk, len, in do_dccp_getsockopt()
649 return ccid_getsockopt_builtin_ccids(sk, len, optval, optlen); in do_dccp_getsockopt()
676 return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname, in do_dccp_getsockopt()
679 return ccid_hc_tx_getsockopt(dp->dccps_hc_tx_ccid, sk, optname, in do_dccp_getsockopt()
692 int dccp_getsockopt(struct sock *sk, int level, int optname, in dccp_getsockopt() argument
696 return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level, in dccp_getsockopt()
699 return do_dccp_getsockopt(sk, level, optname, optval, optlen); in dccp_getsockopt()
728 !dccp_qpolicy_param_ok(skb->sk, cmsg->cmsg_type)) in dccp_msghdr_parse()
744 int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) in dccp_sendmsg() argument
746 const struct dccp_sock *dp = dccp_sk(sk); in dccp_sendmsg()
753 trace_dccp_probe(sk, len); in dccp_sendmsg()
758 lock_sock(sk); in dccp_sendmsg()
760 timeo = sock_sndtimeo(sk, noblock); in dccp_sendmsg()
767 if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN)) in dccp_sendmsg()
768 if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0) in dccp_sendmsg()
771 size = sk->sk_prot->max_header + len; in dccp_sendmsg()
772 release_sock(sk); in dccp_sendmsg()
773 skb = sock_alloc_send_skb(sk, size, noblock, &rc); in dccp_sendmsg()
774 lock_sock(sk); in dccp_sendmsg()
778 if (dccp_qpolicy_full(sk)) { in dccp_sendmsg()
783 if (sk->sk_state == DCCP_CLOSED) { in dccp_sendmsg()
794 skb_reserve(skb, sk->sk_prot->max_header); in dccp_sendmsg()
803 dccp_qpolicy_push(sk, skb); in dccp_sendmsg()
810 dccp_write_xmit(sk); in dccp_sendmsg()
812 release_sock(sk); in dccp_sendmsg()
821 int dccp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, in dccp_recvmsg() argument
827 lock_sock(sk); in dccp_recvmsg()
829 if (sk->sk_state == DCCP_LISTEN) { in dccp_recvmsg()
834 timeo = sock_rcvtimeo(sk, nonblock); in dccp_recvmsg()
837 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); in dccp_recvmsg()
852 dccp_finish_passive_close(sk); in dccp_recvmsg()
862 sk_eat_skb(sk, skb); in dccp_recvmsg()
865 if (sock_flag(sk, SOCK_DONE)) { in dccp_recvmsg()
870 if (sk->sk_err) { in dccp_recvmsg()
871 len = sock_error(sk); in dccp_recvmsg()
875 if (sk->sk_shutdown & RCV_SHUTDOWN) { in dccp_recvmsg()
880 if (sk->sk_state == DCCP_CLOSED) { in dccp_recvmsg()
881 if (!sock_flag(sk, SOCK_DONE)) { in dccp_recvmsg()
902 sk_wait_data(sk, &timeo, NULL); in dccp_recvmsg()
919 sk_eat_skb(sk, skb); in dccp_recvmsg()
923 release_sock(sk); in dccp_recvmsg()
931 struct sock *sk = sock->sk; in inet_dccp_listen() local
935 lock_sock(sk); in inet_dccp_listen()
941 old_state = sk->sk_state; in inet_dccp_listen()
945 WRITE_ONCE(sk->sk_max_ack_backlog, backlog); in inet_dccp_listen()
954 err = dccp_listen_start(sk, backlog); in inet_dccp_listen()
961 release_sock(sk); in inet_dccp_listen()
967 static void dccp_terminate_connection(struct sock *sk) in dccp_terminate_connection() argument
971 switch (sk->sk_state) { in dccp_terminate_connection()
974 dccp_finish_passive_close(sk); in dccp_terminate_connection()
977 dccp_pr_debug("Stop PARTOPEN timer (%p)\n", sk); in dccp_terminate_connection()
978 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); in dccp_terminate_connection()
981 dccp_send_close(sk, 1); in dccp_terminate_connection()
983 if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER && in dccp_terminate_connection()
984 !dccp_sk(sk)->dccps_server_timewait) in dccp_terminate_connection()
990 dccp_set_state(sk, next_state); in dccp_terminate_connection()
994 void dccp_close(struct sock *sk, long timeout) in dccp_close() argument
996 struct dccp_sock *dp = dccp_sk(sk); in dccp_close()
1001 lock_sock(sk); in dccp_close()
1003 sk->sk_shutdown = SHUTDOWN_MASK; in dccp_close()
1005 if (sk->sk_state == DCCP_LISTEN) { in dccp_close()
1006 dccp_set_state(sk, DCCP_CLOSED); in dccp_close()
1009 inet_csk_listen_stop(sk); in dccp_close()
1014 sk_stop_timer(sk, &dp->dccps_xmit_timer); in dccp_close()
1021 while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { in dccp_close()
1027 if (sk->sk_state == DCCP_CLOSED) in dccp_close()
1033 dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED); in dccp_close()
1034 dccp_set_state(sk, DCCP_CLOSED); in dccp_close()
1035 } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { in dccp_close()
1037 sk->sk_prot->disconnect(sk, 0); in dccp_close()
1038 } else if (sk->sk_state != DCCP_CLOSED) { in dccp_close()
1043 dccp_flush_write_queue(sk, &timeout); in dccp_close()
1044 dccp_terminate_connection(sk); in dccp_close()
1053 __skb_queue_purge(&sk->sk_write_queue); in dccp_close()
1055 sk_stream_wait_close(sk, timeout); in dccp_close()
1058 state = sk->sk_state; in dccp_close()
1059 sock_hold(sk); in dccp_close()
1060 sock_orphan(sk); in dccp_close()
1065 release_sock(sk); in dccp_close()
1071 bh_lock_sock(sk); in dccp_close()
1072 WARN_ON(sock_owned_by_user(sk)); in dccp_close()
1074 percpu_counter_inc(sk->sk_prot->orphan_count); in dccp_close()
1077 if (state != DCCP_CLOSED && sk->sk_state == DCCP_CLOSED) in dccp_close()
1080 if (sk->sk_state == DCCP_CLOSED) in dccp_close()
1081 inet_csk_destroy_sock(sk); in dccp_close()
1086 bh_unlock_sock(sk); in dccp_close()
1088 sock_put(sk); in dccp_close()
1093 void dccp_shutdown(struct sock *sk, int how) in dccp_shutdown() argument