Lines Matching refs:sk
86 #define SOCK_DEBUG(sk, msg...) do { if ((sk) && sock_flag((sk), SOCK_DBG)) \ argument
91 void SOCK_DEBUG(const struct sock *sk, const char *msg, ...) in SOCK_DEBUG() argument
494 void (*sk_state_change)(struct sock *sk);
495 void (*sk_data_ready)(struct sock *sk);
496 void (*sk_write_space)(struct sock *sk);
497 void (*sk_error_report)(struct sock *sk);
498 int (*sk_backlog_rcv)(struct sock *sk,
501 struct sk_buff* (*sk_validate_xmit_skb)(struct sock *sk,
505 void (*sk_destruct)(struct sock *sk);
516 #define __sk_user_data(sk) ((*((void __rcu **)&(sk)->sk_user_data))) argument
518 #define rcu_dereference_sk_user_data(sk) rcu_dereference(__sk_user_data((sk))) argument
519 #define rcu_assign_sk_user_data(sk, ptr) rcu_assign_pointer(__sk_user_data((sk)), ptr) argument
532 int sk_set_peek_off(struct sock *sk, int val);
534 static inline int sk_peek_offset(struct sock *sk, int flags) in sk_peek_offset() argument
537 return READ_ONCE(sk->sk_peek_off); in sk_peek_offset()
543 static inline void sk_peek_offset_bwd(struct sock *sk, int val) in sk_peek_offset_bwd() argument
545 s32 off = READ_ONCE(sk->sk_peek_off); in sk_peek_offset_bwd()
549 WRITE_ONCE(sk->sk_peek_off, off); in sk_peek_offset_bwd()
553 static inline void sk_peek_offset_fwd(struct sock *sk, int val) in sk_peek_offset_fwd() argument
555 sk_peek_offset_bwd(sk, -val); in sk_peek_offset_fwd()
586 static inline struct sock *sk_next(const struct sock *sk) in sk_next() argument
588 return hlist_entry_safe(sk->sk_node.next, struct sock, sk_node); in sk_next()
591 static inline struct sock *sk_nulls_next(const struct sock *sk) in sk_nulls_next() argument
593 return (!is_a_nulls(sk->sk_nulls_node.next)) ? in sk_nulls_next()
594 hlist_nulls_entry(sk->sk_nulls_node.next, in sk_nulls_next()
599 static inline bool sk_unhashed(const struct sock *sk) in sk_unhashed() argument
601 return hlist_unhashed(&sk->sk_node); in sk_unhashed()
604 static inline bool sk_hashed(const struct sock *sk) in sk_hashed() argument
606 return !sk_unhashed(sk); in sk_hashed()
619 static inline void __sk_del_node(struct sock *sk) in __sk_del_node() argument
621 __hlist_del(&sk->sk_node); in __sk_del_node()
625 static inline bool __sk_del_node_init(struct sock *sk) in __sk_del_node_init() argument
627 if (sk_hashed(sk)) { in __sk_del_node_init()
628 __sk_del_node(sk); in __sk_del_node_init()
629 sk_node_init(&sk->sk_node); in __sk_del_node_init()
641 static __always_inline void sock_hold(struct sock *sk) in sock_hold() argument
643 refcount_inc(&sk->sk_refcnt); in sock_hold()
649 static __always_inline void __sock_put(struct sock *sk) in __sock_put() argument
651 refcount_dec(&sk->sk_refcnt); in __sock_put()
654 static inline bool sk_del_node_init(struct sock *sk) in sk_del_node_init() argument
656 bool rc = __sk_del_node_init(sk); in sk_del_node_init()
660 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_del_node_init()
661 __sock_put(sk); in sk_del_node_init()
665 #define sk_del_node_init_rcu(sk) sk_del_node_init(sk) argument
667 static inline bool __sk_nulls_del_node_init_rcu(struct sock *sk) in __sk_nulls_del_node_init_rcu() argument
669 if (sk_hashed(sk)) { in __sk_nulls_del_node_init_rcu()
670 hlist_nulls_del_init_rcu(&sk->sk_nulls_node); in __sk_nulls_del_node_init_rcu()
676 static inline bool sk_nulls_del_node_init_rcu(struct sock *sk) in sk_nulls_del_node_init_rcu() argument
678 bool rc = __sk_nulls_del_node_init_rcu(sk); in sk_nulls_del_node_init_rcu()
682 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_nulls_del_node_init_rcu()
683 __sock_put(sk); in sk_nulls_del_node_init_rcu()
688 static inline void __sk_add_node(struct sock *sk, struct hlist_head *list) in __sk_add_node() argument
690 hlist_add_head(&sk->sk_node, list); in __sk_add_node()
693 static inline void sk_add_node(struct sock *sk, struct hlist_head *list) in sk_add_node() argument
695 sock_hold(sk); in sk_add_node()
696 __sk_add_node(sk, list); in sk_add_node()
699 static inline void sk_add_node_rcu(struct sock *sk, struct hlist_head *list) in sk_add_node_rcu() argument
701 sock_hold(sk); in sk_add_node_rcu()
702 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport && in sk_add_node_rcu()
703 sk->sk_family == AF_INET6) in sk_add_node_rcu()
704 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_rcu()
706 hlist_add_head_rcu(&sk->sk_node, list); in sk_add_node_rcu()
709 static inline void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) in __sk_nulls_add_node_rcu() argument
711 hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_rcu()
714 static inline void sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) in sk_nulls_add_node_rcu() argument
716 sock_hold(sk); in sk_nulls_add_node_rcu()
717 __sk_nulls_add_node_rcu(sk, list); in sk_nulls_add_node_rcu()
720 static inline void __sk_del_bind_node(struct sock *sk) in __sk_del_bind_node() argument
722 __hlist_del(&sk->sk_bind_node); in __sk_del_bind_node()
725 static inline void sk_add_bind_node(struct sock *sk, in sk_add_bind_node() argument
728 hlist_add_head(&sk->sk_bind_node, list); in sk_add_bind_node()
763 static inline struct user_namespace *sk_user_ns(struct sock *sk) in sk_user_ns() argument
769 return sk->sk_socket->file->f_cred->user_ns; in sk_user_ns()
812 static inline void sock_set_flag(struct sock *sk, enum sock_flags flag) in sock_set_flag() argument
814 __set_bit(flag, &sk->sk_flags); in sock_set_flag()
817 static inline void sock_reset_flag(struct sock *sk, enum sock_flags flag) in sock_reset_flag() argument
819 __clear_bit(flag, &sk->sk_flags); in sock_reset_flag()
822 static inline bool sock_flag(const struct sock *sk, enum sock_flags flag) in sock_flag() argument
824 return test_bit(flag, &sk->sk_flags); in sock_flag()
842 static inline gfp_t sk_gfp_mask(const struct sock *sk, gfp_t gfp_mask) in sk_gfp_mask() argument
844 return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); in sk_gfp_mask()
847 static inline void sk_acceptq_removed(struct sock *sk) in sk_acceptq_removed() argument
849 sk->sk_ack_backlog--; in sk_acceptq_removed()
852 static inline void sk_acceptq_added(struct sock *sk) in sk_acceptq_added() argument
854 sk->sk_ack_backlog++; in sk_acceptq_added()
857 static inline bool sk_acceptq_is_full(const struct sock *sk) in sk_acceptq_is_full() argument
859 return sk->sk_ack_backlog > sk->sk_max_ack_backlog; in sk_acceptq_is_full()
865 static inline int sk_stream_min_wspace(const struct sock *sk) in sk_stream_min_wspace() argument
867 return sk->sk_wmem_queued >> 1; in sk_stream_min_wspace()
870 static inline int sk_stream_wspace(const struct sock *sk) in sk_stream_wspace() argument
872 return sk->sk_sndbuf - sk->sk_wmem_queued; in sk_stream_wspace()
875 void sk_stream_write_space(struct sock *sk);
878 static inline void __sk_add_backlog(struct sock *sk, struct sk_buff *skb) in __sk_add_backlog() argument
883 if (!sk->sk_backlog.tail) in __sk_add_backlog()
884 sk->sk_backlog.head = skb; in __sk_add_backlog()
886 sk->sk_backlog.tail->next = skb; in __sk_add_backlog()
888 sk->sk_backlog.tail = skb; in __sk_add_backlog()
897 static inline bool sk_rcvqueues_full(const struct sock *sk, unsigned int limit) in sk_rcvqueues_full() argument
899 unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc); in sk_rcvqueues_full()
905 static inline __must_check int sk_add_backlog(struct sock *sk, struct sk_buff *skb, in sk_add_backlog() argument
908 if (sk_rcvqueues_full(sk, limit)) in sk_add_backlog()
916 if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC)) in sk_add_backlog()
919 __sk_add_backlog(sk, skb); in sk_add_backlog()
920 sk->sk_backlog.len += skb->truesize; in sk_add_backlog()
924 int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb);
926 static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb) in sk_backlog_rcv() argument
929 return __sk_backlog_rcv(sk, skb); in sk_backlog_rcv()
931 return sk->sk_backlog_rcv(sk, skb); in sk_backlog_rcv()
934 static inline void sk_incoming_cpu_update(struct sock *sk) in sk_incoming_cpu_update() argument
938 if (unlikely(sk->sk_incoming_cpu != cpu)) in sk_incoming_cpu_update()
939 sk->sk_incoming_cpu = cpu; in sk_incoming_cpu_update()
954 static inline void sock_rps_record_flow(const struct sock *sk) in sock_rps_record_flow() argument
968 if (sk->sk_state == TCP_ESTABLISHED) in sock_rps_record_flow()
969 sock_rps_record_flow_hash(sk->sk_rxhash); in sock_rps_record_flow()
974 static inline void sock_rps_save_rxhash(struct sock *sk, in sock_rps_save_rxhash() argument
978 if (unlikely(sk->sk_rxhash != skb->hash)) in sock_rps_save_rxhash()
979 sk->sk_rxhash = skb->hash; in sock_rps_save_rxhash()
983 static inline void sock_rps_reset_rxhash(struct sock *sk) in sock_rps_reset_rxhash() argument
986 sk->sk_rxhash = 0; in sock_rps_reset_rxhash()
1005 int sk_stream_wait_connect(struct sock *sk, long *timeo_p);
1006 int sk_stream_wait_memory(struct sock *sk, long *timeo_p);
1007 void sk_stream_wait_close(struct sock *sk, long timeo_p);
1008 int sk_stream_error(struct sock *sk, int flags, int err);
1009 void sk_stream_kill_queues(struct sock *sk);
1010 void sk_set_memalloc(struct sock *sk);
1011 void sk_clear_memalloc(struct sock *sk);
1013 void __sk_flush_backlog(struct sock *sk);
1015 static inline bool sk_flush_backlog(struct sock *sk) in sk_flush_backlog() argument
1017 if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { in sk_flush_backlog()
1018 __sk_flush_backlog(sk); in sk_flush_backlog()
1024 int sk_wait_data(struct sock *sk, long *timeo, const struct sk_buff *skb);
1037 static inline void sk_prot_clear_nulls(struct sock *sk, int size) in sk_prot_clear_nulls() argument
1040 memset(sk, 0, offsetof(struct sock, sk_node.next)); in sk_prot_clear_nulls()
1041 memset(&sk->sk_node.pprev, 0, in sk_prot_clear_nulls()
1049 void (*close)(struct sock *sk,
1051 int (*pre_connect)(struct sock *sk,
1054 int (*connect)(struct sock *sk,
1057 int (*disconnect)(struct sock *sk, int flags);
1059 struct sock * (*accept)(struct sock *sk, int flags, int *err,
1062 int (*ioctl)(struct sock *sk, int cmd,
1064 int (*init)(struct sock *sk);
1065 void (*destroy)(struct sock *sk);
1066 void (*shutdown)(struct sock *sk, int how);
1067 int (*setsockopt)(struct sock *sk, int level,
1070 int (*getsockopt)(struct sock *sk, int level,
1073 void (*keepalive)(struct sock *sk, int valbool);
1075 int (*compat_setsockopt)(struct sock *sk,
1079 int (*compat_getsockopt)(struct sock *sk,
1083 int (*compat_ioctl)(struct sock *sk,
1086 int (*sendmsg)(struct sock *sk, struct msghdr *msg,
1088 int (*recvmsg)(struct sock *sk, struct msghdr *msg,
1091 int (*sendpage)(struct sock *sk, struct page *page,
1093 int (*bind)(struct sock *sk,
1096 int (*backlog_rcv) (struct sock *sk,
1099 void (*release_cb)(struct sock *sk);
1102 int (*hash)(struct sock *sk);
1103 void (*unhash)(struct sock *sk);
1104 void (*rehash)(struct sock *sk);
1105 int (*get_port)(struct sock *sk, unsigned short snum);
1112 bool (*stream_memory_free)(const struct sock *sk);
1113 bool (*stream_memory_read)(const struct sock *sk);
1115 void (*enter_memory_pressure)(struct sock *sk);
1116 void (*leave_memory_pressure)(struct sock *sk);
1162 int (*diag_destroy)(struct sock *sk, int err);
1170 static inline void sk_refcnt_debug_inc(struct sock *sk) in sk_refcnt_debug_inc() argument
1172 atomic_inc(&sk->sk_prot->socks); in sk_refcnt_debug_inc()
1175 static inline void sk_refcnt_debug_dec(struct sock *sk) in sk_refcnt_debug_dec() argument
1177 atomic_dec(&sk->sk_prot->socks); in sk_refcnt_debug_dec()
1179 sk->sk_prot->name, sk, atomic_read(&sk->sk_prot->socks)); in sk_refcnt_debug_dec()
1182 static inline void sk_refcnt_debug_release(const struct sock *sk) in sk_refcnt_debug_release() argument
1184 if (refcount_read(&sk->sk_refcnt) != 1) in sk_refcnt_debug_release()
1186 sk->sk_prot->name, sk, refcount_read(&sk->sk_refcnt)); in sk_refcnt_debug_release()
1189 #define sk_refcnt_debug_inc(sk) do { } while (0) argument
1190 #define sk_refcnt_debug_dec(sk) do { } while (0) argument
1191 #define sk_refcnt_debug_release(sk) do { } while (0) argument
1194 static inline bool sk_stream_memory_free(const struct sock *sk) in sk_stream_memory_free() argument
1196 if (sk->sk_wmem_queued >= sk->sk_sndbuf) in sk_stream_memory_free()
1199 return sk->sk_prot->stream_memory_free ? in sk_stream_memory_free()
1200 sk->sk_prot->stream_memory_free(sk) : true; in sk_stream_memory_free()
1203 static inline bool sk_stream_is_writeable(const struct sock *sk) in sk_stream_is_writeable() argument
1205 return sk_stream_wspace(sk) >= sk_stream_min_wspace(sk) && in sk_stream_is_writeable()
1206 sk_stream_memory_free(sk); in sk_stream_is_writeable()
1209 static inline int sk_under_cgroup_hierarchy(struct sock *sk, in sk_under_cgroup_hierarchy() argument
1213 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), in sk_under_cgroup_hierarchy()
1220 static inline bool sk_has_memory_pressure(const struct sock *sk) in sk_has_memory_pressure() argument
1222 return sk->sk_prot->memory_pressure != NULL; in sk_has_memory_pressure()
1225 static inline bool sk_under_memory_pressure(const struct sock *sk) in sk_under_memory_pressure() argument
1227 if (!sk->sk_prot->memory_pressure) in sk_under_memory_pressure()
1230 if (mem_cgroup_sockets_enabled && sk->sk_memcg && in sk_under_memory_pressure()
1231 mem_cgroup_under_socket_pressure(sk->sk_memcg)) in sk_under_memory_pressure()
1234 return !!*sk->sk_prot->memory_pressure; in sk_under_memory_pressure()
1238 sk_memory_allocated(const struct sock *sk) in sk_memory_allocated() argument
1240 return atomic_long_read(sk->sk_prot->memory_allocated); in sk_memory_allocated()
1244 sk_memory_allocated_add(struct sock *sk, int amt) in sk_memory_allocated_add() argument
1246 return atomic_long_add_return(amt, sk->sk_prot->memory_allocated); in sk_memory_allocated_add()
1250 sk_memory_allocated_sub(struct sock *sk, int amt) in sk_memory_allocated_sub() argument
1252 atomic_long_sub(amt, sk->sk_prot->memory_allocated); in sk_memory_allocated_sub()
1255 static inline void sk_sockets_allocated_dec(struct sock *sk) in sk_sockets_allocated_dec() argument
1257 percpu_counter_dec(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_dec()
1260 static inline void sk_sockets_allocated_inc(struct sock *sk) in sk_sockets_allocated_inc() argument
1262 percpu_counter_inc(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_inc()
1266 sk_sockets_allocated_read_positive(struct sock *sk) in sk_sockets_allocated_read_positive() argument
1268 return percpu_counter_read_positive(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_read_positive()
1308 static inline int __sk_prot_rehash(struct sock *sk) in __sk_prot_rehash() argument
1310 sk->sk_prot->unhash(sk); in __sk_prot_rehash()
1311 return sk->sk_prot->hash(sk); in __sk_prot_rehash()
1347 int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind);
1348 int __sk_mem_schedule(struct sock *sk, int size, int kind);
1349 void __sk_mem_reduce_allocated(struct sock *sk, int amount);
1350 void __sk_mem_reclaim(struct sock *sk, int amount);
1361 static inline long sk_prot_mem_limits(const struct sock *sk, int index) in sk_prot_mem_limits() argument
1363 long val = sk->sk_prot->sysctl_mem[index]; in sk_prot_mem_limits()
1378 static inline bool sk_has_account(struct sock *sk) in sk_has_account() argument
1381 return !!sk->sk_prot->memory_allocated; in sk_has_account()
1384 static inline bool sk_wmem_schedule(struct sock *sk, int size) in sk_wmem_schedule() argument
1386 if (!sk_has_account(sk)) in sk_wmem_schedule()
1388 return size <= sk->sk_forward_alloc || in sk_wmem_schedule()
1389 __sk_mem_schedule(sk, size, SK_MEM_SEND); in sk_wmem_schedule()
1393 sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) in sk_rmem_schedule() argument
1395 if (!sk_has_account(sk)) in sk_rmem_schedule()
1397 return size<= sk->sk_forward_alloc || in sk_rmem_schedule()
1398 __sk_mem_schedule(sk, size, SK_MEM_RECV) || in sk_rmem_schedule()
1402 static inline void sk_mem_reclaim(struct sock *sk) in sk_mem_reclaim() argument
1404 if (!sk_has_account(sk)) in sk_mem_reclaim()
1406 if (sk->sk_forward_alloc >= SK_MEM_QUANTUM) in sk_mem_reclaim()
1407 __sk_mem_reclaim(sk, sk->sk_forward_alloc); in sk_mem_reclaim()
1410 static inline void sk_mem_reclaim_partial(struct sock *sk) in sk_mem_reclaim_partial() argument
1412 if (!sk_has_account(sk)) in sk_mem_reclaim_partial()
1414 if (sk->sk_forward_alloc > SK_MEM_QUANTUM) in sk_mem_reclaim_partial()
1415 __sk_mem_reclaim(sk, sk->sk_forward_alloc - 1); in sk_mem_reclaim_partial()
1418 static inline void sk_mem_charge(struct sock *sk, int size) in sk_mem_charge() argument
1420 if (!sk_has_account(sk)) in sk_mem_charge()
1422 sk->sk_forward_alloc -= size; in sk_mem_charge()
1425 static inline void sk_mem_uncharge(struct sock *sk, int size) in sk_mem_uncharge() argument
1427 if (!sk_has_account(sk)) in sk_mem_uncharge()
1429 sk->sk_forward_alloc += size; in sk_mem_uncharge()
1438 if (unlikely(sk->sk_forward_alloc >= 1 << 21)) in sk_mem_uncharge()
1439 __sk_mem_reclaim(sk, 1 << 20); in sk_mem_uncharge()
1442 static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb) in sk_wmem_free_skb() argument
1444 sock_set_flag(sk, SOCK_QUEUE_SHRUNK); in sk_wmem_free_skb()
1445 sk->sk_wmem_queued -= skb->truesize; in sk_wmem_free_skb()
1446 sk_mem_uncharge(sk, skb->truesize); in sk_wmem_free_skb()
1450 static inline void sock_release_ownership(struct sock *sk) in sock_release_ownership() argument
1452 if (sk->sk_lock.owned) { in sock_release_ownership()
1453 sk->sk_lock.owned = 0; in sock_release_ownership()
1456 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_); in sock_release_ownership()
1467 #define sock_lock_init_class_and_name(sk, sname, skey, name, key) \ argument
1469 sk->sk_lock.owned = 0; \
1470 init_waitqueue_head(&sk->sk_lock.wq); \
1471 spin_lock_init(&(sk)->sk_lock.slock); \
1472 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1473 sizeof((sk)->sk_lock)); \
1474 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1476 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1480 static inline bool lockdep_sock_is_held(const struct sock *sk) in lockdep_sock_is_held() argument
1482 return lockdep_is_held(&sk->sk_lock) || in lockdep_sock_is_held()
1483 lockdep_is_held(&sk->sk_lock.slock); in lockdep_sock_is_held()
1487 void lock_sock_nested(struct sock *sk, int subclass);
1489 static inline void lock_sock(struct sock *sk) in lock_sock() argument
1491 lock_sock_nested(sk, 0); in lock_sock()
1494 void release_sock(struct sock *sk);
1503 bool lock_sock_fast(struct sock *sk);
1512 static inline void unlock_sock_fast(struct sock *sk, bool slow) in unlock_sock_fast() argument
1515 release_sock(sk); in unlock_sock_fast()
1517 spin_unlock_bh(&sk->sk_lock.slock); in unlock_sock_fast()
1534 static inline void sock_owned_by_me(const struct sock *sk) in sock_owned_by_me() argument
1537 WARN_ON_ONCE(!lockdep_sock_is_held(sk) && debug_locks); in sock_owned_by_me()
1541 static inline bool sock_owned_by_user(const struct sock *sk) in sock_owned_by_user() argument
1543 sock_owned_by_me(sk); in sock_owned_by_user()
1544 return sk->sk_lock.owned; in sock_owned_by_user()
1547 static inline bool sock_owned_by_user_nocheck(const struct sock *sk) in sock_owned_by_user_nocheck() argument
1549 return sk->sk_lock.owned; in sock_owned_by_user_nocheck()
1555 struct sock *sk = (struct sock *)csk; in sock_allow_reclassification() local
1557 return !sk->sk_lock.owned && !spin_is_locked(&sk->sk_lock.slock); in sock_allow_reclassification()
1562 void sk_free(struct sock *sk);
1563 void sk_destruct(struct sock *sk);
1564 struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority);
1565 void sk_free_unlock_clone(struct sock *sk);
1567 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
1571 struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size,
1587 struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size,
1589 struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
1592 void *sock_kmalloc(struct sock *sk, int size, gfp_t priority);
1593 void sock_kfree_s(struct sock *sk, void *mem, int size);
1594 void sock_kzfree_s(struct sock *sk, void *mem, int size);
1595 void sk_send_sigurg(struct sock *sk);
1604 const struct sock *sk) in sockcm_init() argument
1606 *sockc = (struct sockcm_cookie) { .tsflags = sk->sk_tsflags }; in sockcm_init()
1609 int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg,
1611 int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
1629 int sock_no_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);
1635 ssize_t sock_no_sendpage_locked(struct sock *sk, struct page *page,
1653 void sk_common_release(struct sock *sk);
1660 void sock_init_data(struct socket *sock, struct sock *sk);
1688 static inline void sock_put(struct sock *sk) in sock_put() argument
1690 if (refcount_dec_and_test(&sk->sk_refcnt)) in sock_put()
1691 sk_free(sk); in sock_put()
1696 void sock_gen_put(struct sock *sk);
1698 int __sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested,
1700 static inline int sk_receive_skb(struct sock *sk, struct sk_buff *skb, in sk_receive_skb() argument
1703 return __sk_receive_skb(sk, skb, nested, 1, true); in sk_receive_skb()
1706 static inline void sk_tx_queue_set(struct sock *sk, int tx_queue) in sk_tx_queue_set() argument
1711 sk->sk_tx_queue_mapping = tx_queue; in sk_tx_queue_set()
1716 static inline void sk_tx_queue_clear(struct sock *sk) in sk_tx_queue_clear() argument
1718 sk->sk_tx_queue_mapping = NO_QUEUE_MAPPING; in sk_tx_queue_clear()
1721 static inline int sk_tx_queue_get(const struct sock *sk) in sk_tx_queue_get() argument
1723 if (sk && sk->sk_tx_queue_mapping != NO_QUEUE_MAPPING) in sk_tx_queue_get()
1724 return sk->sk_tx_queue_mapping; in sk_tx_queue_get()
1729 static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) in sk_rx_queue_set() argument
1738 sk->sk_rx_queue_mapping = rx_queue; in sk_rx_queue_set()
1743 static inline void sk_rx_queue_clear(struct sock *sk) in sk_rx_queue_clear() argument
1746 sk->sk_rx_queue_mapping = NO_QUEUE_MAPPING; in sk_rx_queue_clear()
1751 static inline int sk_rx_queue_get(const struct sock *sk) in sk_rx_queue_get() argument
1753 if (sk && sk->sk_rx_queue_mapping != NO_QUEUE_MAPPING) in sk_rx_queue_get()
1754 return sk->sk_rx_queue_mapping; in sk_rx_queue_get()
1760 static inline void sk_set_socket(struct sock *sk, struct socket *sock) in sk_set_socket() argument
1762 sk_tx_queue_clear(sk); in sk_set_socket()
1763 sk->sk_socket = sock; in sk_set_socket()
1766 static inline wait_queue_head_t *sk_sleep(struct sock *sk) in sk_sleep() argument
1769 return &rcu_dereference_raw(sk->sk_wq)->wait; in sk_sleep()
1778 static inline void sock_orphan(struct sock *sk) in sock_orphan() argument
1780 write_lock_bh(&sk->sk_callback_lock); in sock_orphan()
1781 sock_set_flag(sk, SOCK_DEAD); in sock_orphan()
1782 sk_set_socket(sk, NULL); in sock_orphan()
1783 sk->sk_wq = NULL; in sock_orphan()
1784 write_unlock_bh(&sk->sk_callback_lock); in sock_orphan()
1787 static inline void sock_graft(struct sock *sk, struct socket *parent) in sock_graft() argument
1789 WARN_ON(parent->sk); in sock_graft()
1790 write_lock_bh(&sk->sk_callback_lock); in sock_graft()
1791 rcu_assign_pointer(sk->sk_wq, parent->wq); in sock_graft()
1792 parent->sk = sk; in sock_graft()
1793 sk_set_socket(sk, parent); in sock_graft()
1794 sk->sk_uid = SOCK_INODE(parent)->i_uid; in sock_graft()
1795 security_sock_graft(sk, parent); in sock_graft()
1796 write_unlock_bh(&sk->sk_callback_lock); in sock_graft()
1799 kuid_t sock_i_uid(struct sock *sk);
1800 unsigned long sock_i_ino(struct sock *sk);
1802 static inline kuid_t sock_net_uid(const struct net *net, const struct sock *sk) in sock_net_uid() argument
1804 return sk ? sk->sk_uid : make_kuid(net->user_ns, 0); in sock_net_uid()
1814 static inline void sk_set_txhash(struct sock *sk) in sk_set_txhash() argument
1816 sk->sk_txhash = net_tx_rndhash(); in sk_set_txhash()
1819 static inline void sk_rethink_txhash(struct sock *sk) in sk_rethink_txhash() argument
1821 if (sk->sk_txhash) in sk_rethink_txhash()
1822 sk_set_txhash(sk); in sk_rethink_txhash()
1826 __sk_dst_get(struct sock *sk) in __sk_dst_get() argument
1828 return rcu_dereference_check(sk->sk_dst_cache, in __sk_dst_get()
1829 lockdep_sock_is_held(sk)); in __sk_dst_get()
1833 sk_dst_get(struct sock *sk) in sk_dst_get() argument
1838 dst = rcu_dereference(sk->sk_dst_cache); in sk_dst_get()
1845 static inline void dst_negative_advice(struct sock *sk) in dst_negative_advice() argument
1847 struct dst_entry *ndst, *dst = __sk_dst_get(sk); in dst_negative_advice()
1849 sk_rethink_txhash(sk); in dst_negative_advice()
1855 rcu_assign_pointer(sk->sk_dst_cache, ndst); in dst_negative_advice()
1856 sk_tx_queue_clear(sk); in dst_negative_advice()
1857 sk->sk_dst_pending_confirm = 0; in dst_negative_advice()
1863 __sk_dst_set(struct sock *sk, struct dst_entry *dst) in __sk_dst_set() argument
1867 sk_tx_queue_clear(sk); in __sk_dst_set()
1868 sk->sk_dst_pending_confirm = 0; in __sk_dst_set()
1869 old_dst = rcu_dereference_protected(sk->sk_dst_cache, in __sk_dst_set()
1870 lockdep_sock_is_held(sk)); in __sk_dst_set()
1871 rcu_assign_pointer(sk->sk_dst_cache, dst); in __sk_dst_set()
1876 sk_dst_set(struct sock *sk, struct dst_entry *dst) in sk_dst_set() argument
1880 sk_tx_queue_clear(sk); in sk_dst_set()
1881 sk->sk_dst_pending_confirm = 0; in sk_dst_set()
1882 old_dst = xchg((__force struct dst_entry **)&sk->sk_dst_cache, dst); in sk_dst_set()
1887 __sk_dst_reset(struct sock *sk) in __sk_dst_reset() argument
1889 __sk_dst_set(sk, NULL); in __sk_dst_reset()
1893 sk_dst_reset(struct sock *sk) in sk_dst_reset() argument
1895 sk_dst_set(sk, NULL); in sk_dst_reset()
1898 struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);
1900 struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie);
1902 static inline void sk_dst_confirm(struct sock *sk) in sk_dst_confirm() argument
1904 if (!sk->sk_dst_pending_confirm) in sk_dst_confirm()
1905 sk->sk_dst_pending_confirm = 1; in sk_dst_confirm()
1911 struct sock *sk = skb->sk; in sock_confirm_neigh() local
1917 if (sk && sk->sk_dst_pending_confirm) in sock_confirm_neigh()
1918 sk->sk_dst_pending_confirm = 0; in sock_confirm_neigh()
1922 bool sk_mc_loop(struct sock *sk);
1924 static inline bool sk_can_gso(const struct sock *sk) in sk_can_gso() argument
1926 return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); in sk_can_gso()
1929 void sk_setup_caps(struct sock *sk, struct dst_entry *dst);
1931 static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags) in sk_nocaps_add() argument
1933 sk->sk_route_nocaps |= flags; in sk_nocaps_add()
1934 sk->sk_route_caps &= ~flags; in sk_nocaps_add()
1937 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb, in skb_do_copy_data_nocache() argument
1946 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { in skb_do_copy_data_nocache()
1955 static inline int skb_add_data_nocache(struct sock *sk, struct sk_buff *skb, in skb_add_data_nocache() argument
1960 err = skb_do_copy_data_nocache(sk, skb, from, skb_put(skb, copy), in skb_add_data_nocache()
1968 static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *from, in skb_copy_to_page_nocache() argument
1975 err = skb_do_copy_data_nocache(sk, skb, from, page_address(page) + off, in skb_copy_to_page_nocache()
1983 sk->sk_wmem_queued += copy; in skb_copy_to_page_nocache()
1984 sk_mem_charge(sk, copy); in skb_copy_to_page_nocache()
1994 static inline int sk_wmem_alloc_get(const struct sock *sk) in sk_wmem_alloc_get() argument
1996 return refcount_read(&sk->sk_wmem_alloc) - 1; in sk_wmem_alloc_get()
2005 static inline int sk_rmem_alloc_get(const struct sock *sk) in sk_rmem_alloc_get() argument
2007 return atomic_read(&sk->sk_rmem_alloc); in sk_rmem_alloc_get()
2016 static inline bool sk_has_allocations(const struct sock *sk) in sk_has_allocations() argument
2018 return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); in sk_has_allocations()
2079 static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *sk) in skb_set_hash_from_sk() argument
2081 if (sk->sk_txhash) { in skb_set_hash_from_sk()
2083 skb->hash = sk->sk_txhash; in skb_set_hash_from_sk()
2087 void skb_set_owner_w(struct sk_buff *skb, struct sock *sk);
2097 static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk) in skb_set_owner_r() argument
2100 skb->sk = sk; in skb_set_owner_r()
2102 atomic_add(skb->truesize, &sk->sk_rmem_alloc); in skb_set_owner_r()
2103 sk_mem_charge(sk, skb->truesize); in skb_set_owner_r()
2106 void sk_reset_timer(struct sock *sk, struct timer_list *timer,
2109 void sk_stop_timer(struct sock *sk, struct timer_list *timer);
2111 int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue,
2113 void (*destructor)(struct sock *sk,
2115 int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
2116 int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
2118 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb);
2119 struct sk_buff *sock_dequeue_err_skb(struct sock *sk);
2125 static inline int sock_error(struct sock *sk) in sock_error() argument
2128 if (likely(!sk->sk_err)) in sock_error()
2130 err = xchg(&sk->sk_err, 0); in sock_error()
2134 static inline unsigned long sock_wspace(struct sock *sk) in sock_wspace() argument
2138 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in sock_wspace()
2139 amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc); in sock_wspace()
2150 static inline void sk_set_bit(int nr, struct sock *sk) in sk_set_bit() argument
2153 !sock_flag(sk, SOCK_FASYNC)) in sk_set_bit()
2156 set_bit(nr, &sk->sk_wq_raw->flags); in sk_set_bit()
2159 static inline void sk_clear_bit(int nr, struct sock *sk) in sk_clear_bit() argument
2162 !sock_flag(sk, SOCK_FASYNC)) in sk_clear_bit()
2165 clear_bit(nr, &sk->sk_wq_raw->flags); in sk_clear_bit()
2168 static inline void sk_wake_async(const struct sock *sk, int how, int band) in sk_wake_async() argument
2170 if (sock_flag(sk, SOCK_FASYNC)) { in sk_wake_async()
2172 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async()
2187 static inline void sk_stream_moderate_sndbuf(struct sock *sk) in sk_stream_moderate_sndbuf() argument
2189 if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) { in sk_stream_moderate_sndbuf()
2190 sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); in sk_stream_moderate_sndbuf()
2191 sk->sk_sndbuf = max_t(u32, sk->sk_sndbuf, SOCK_MIN_SNDBUF); in sk_stream_moderate_sndbuf()
2195 struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
2205 static inline struct page_frag *sk_page_frag(struct sock *sk) in sk_page_frag() argument
2207 if (gfpflags_allow_blocking(sk->sk_allocation)) in sk_page_frag()
2210 return &sk->sk_frag; in sk_page_frag()
2213 bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag);
2215 int sk_alloc_sg(struct sock *sk, int len, struct scatterlist *sg,
2222 static inline bool sock_writeable(const struct sock *sk) in sock_writeable() argument
2224 return refcount_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1); in sock_writeable()
2232 static inline long sock_rcvtimeo(const struct sock *sk, bool noblock) in sock_rcvtimeo() argument
2234 return noblock ? 0 : sk->sk_rcvtimeo; in sock_rcvtimeo()
2237 static inline long sock_sndtimeo(const struct sock *sk, bool noblock) in sock_sndtimeo() argument
2239 return noblock ? 0 : sk->sk_sndtimeo; in sock_sndtimeo()
2242 static inline int sock_rcvlowat(const struct sock *sk, int waitall, int len) in sock_rcvlowat() argument
2244 return (waitall ? len : min_t(int, sk->sk_rcvlowat, len)) ? : 1; in sock_rcvlowat()
2273 sock_skb_set_dropcount(const struct sock *sk, struct sk_buff *skb) in sock_skb_set_dropcount() argument
2275 SOCK_SKB_CB(skb)->dropcount = sock_flag(sk, SOCK_RXQ_OVFL) ? in sock_skb_set_dropcount()
2276 atomic_read(&sk->sk_drops) : 0; in sock_skb_set_dropcount()
2279 static inline void sk_drops_add(struct sock *sk, const struct sk_buff *skb) in sk_drops_add() argument
2283 atomic_add(segs, &sk->sk_drops); in sk_drops_add()
2286 void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
2288 void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
2292 sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) in sock_recv_timestamp() argument
2303 if (sock_flag(sk, SOCK_RCVTSTAMP) || in sock_recv_timestamp()
2304 (sk->sk_tsflags & SOF_TIMESTAMPING_RX_SOFTWARE) || in sock_recv_timestamp()
2305 (kt && sk->sk_tsflags & SOF_TIMESTAMPING_SOFTWARE) || in sock_recv_timestamp()
2307 (sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE))) in sock_recv_timestamp()
2308 __sock_recv_timestamp(msg, sk, skb); in sock_recv_timestamp()
2310 sk->sk_stamp = kt; in sock_recv_timestamp()
2312 if (sock_flag(sk, SOCK_WIFI_STATUS) && skb->wifi_acked_valid) in sock_recv_timestamp()
2313 __sock_recv_wifi_status(msg, sk, skb); in sock_recv_timestamp()
2316 void __sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
2320 static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk, in sock_recv_ts_and_drops() argument
2328 if (sk->sk_flags & FLAGS_TS_OR_DROPS || sk->sk_tsflags & TSFLAGS_ANY) in sock_recv_ts_and_drops()
2329 __sock_recv_ts_and_drops(msg, sk, skb); in sock_recv_ts_and_drops()
2330 else if (unlikely(sock_flag(sk, SOCK_TIMESTAMP))) in sock_recv_ts_and_drops()
2331 sk->sk_stamp = skb->tstamp; in sock_recv_ts_and_drops()
2332 else if (unlikely(sk->sk_stamp == SK_DEFAULT_STAMP)) in sock_recv_ts_and_drops()
2333 sk->sk_stamp = 0; in sock_recv_ts_and_drops()
2346 static inline void sock_tx_timestamp(const struct sock *sk, __u16 tsflags, in sock_tx_timestamp() argument
2351 if (unlikely(sock_flag(sk, SOCK_WIFI_STATUS))) in sock_tx_timestamp()
2363 static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb) in sk_eat_skb() argument
2365 __skb_unlink(skb, &sk->sk_receive_queue); in sk_eat_skb()
2370 struct net *sock_net(const struct sock *sk) in sock_net() argument
2372 return read_pnet(&sk->sk_net); in sock_net()
2376 void sock_net_set(struct sock *sk, struct net *net) in sock_net_set() argument
2378 write_pnet(&sk->sk_net, net); in sock_net_set()
2383 if (skb->sk) { in skb_steal_sock()
2384 struct sock *sk = skb->sk; in skb_steal_sock() local
2387 skb->sk = NULL; in skb_steal_sock()
2388 return sk; in skb_steal_sock()
2396 static inline bool sk_fullsock(const struct sock *sk) in sk_fullsock() argument
2398 return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); in sk_fullsock()
2408 struct sock *sk = skb->sk; in sk_validate_xmit_skb() local
2410 if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) in sk_validate_xmit_skb()
2411 skb = sk->sk_validate_xmit_skb(sk, dev, skb); in sk_validate_xmit_skb()
2420 static inline bool sk_listener(const struct sock *sk) in sk_listener() argument
2422 return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); in sk_listener()
2425 void sock_enable_timestamp(struct sock *sk, int flag);
2428 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level,
2431 bool sk_ns_capable(const struct sock *sk,
2433 bool sk_capable(const struct sock *sk, int cap);
2434 bool sk_net_capable(const struct sock *sk, int cap);
2436 void sk_get_meminfo(const struct sock *sk, u32 *meminfo);
2457 static inline int sk_get_wmem0(const struct sock *sk, const struct proto *proto) in sk_get_wmem0() argument
2461 return *(int *)((void *)sock_net(sk) + proto->sysctl_wmem_offset); in sk_get_wmem0()
2466 static inline int sk_get_rmem0(const struct sock *sk, const struct proto *proto) in sk_get_rmem0() argument
2470 return *(int *)((void *)sock_net(sk) + proto->sysctl_rmem_offset); in sk_get_rmem0()
2479 static inline void sk_pacing_shift_update(struct sock *sk, int val) in sk_pacing_shift_update() argument
2481 if (!sk || !sk_fullsock(sk) || sk->sk_pacing_shift == val) in sk_pacing_shift_update()
2483 sk->sk_pacing_shift = val; in sk_pacing_shift_update()
2491 static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif) in sk_dev_equal_l3scope() argument
2495 if (!sk->sk_bound_dev_if || sk->sk_bound_dev_if == dif) in sk_dev_equal_l3scope()
2498 mdif = l3mdev_master_ifindex_by_index(sock_net(sk), dif); in sk_dev_equal_l3scope()
2499 if (mdif && mdif == sk->sk_bound_dev_if) in sk_dev_equal_l3scope()