Lines Matching refs:sk
441 void (*sk_data_ready)(struct sock *sk);
501 struct sk_buff* (*sk_validate_xmit_skb)(struct sock *sk,
564 void (*sk_state_change)(struct sock *sk);
565 void (*sk_write_space)(struct sock *sk);
566 void (*sk_error_report)(struct sock *sk);
567 int (*sk_backlog_rcv)(struct sock *sk,
569 void (*sk_destruct)(struct sock *sk);
620 static inline bool sk_user_data_is_nocopy(const struct sock *sk) in sk_user_data_is_nocopy() argument
622 return ((uintptr_t)sk->sk_user_data & SK_USER_DATA_NOCOPY); in sk_user_data_is_nocopy()
625 #define __sk_user_data(sk) ((*((void __rcu **)&(sk)->sk_user_data))) argument
638 __locked_read_sk_user_data_with_flags(const struct sock *sk, in __locked_read_sk_user_data_with_flags() argument
642 (uintptr_t)rcu_dereference_check(__sk_user_data(sk), in __locked_read_sk_user_data_with_flags()
643 lockdep_is_held(&sk->sk_callback_lock)); in __locked_read_sk_user_data_with_flags()
661 __rcu_dereference_sk_user_data_with_flags(const struct sock *sk, in __rcu_dereference_sk_user_data_with_flags() argument
664 uintptr_t sk_user_data = (uintptr_t)rcu_dereference(__sk_user_data(sk)); in __rcu_dereference_sk_user_data_with_flags()
673 #define rcu_dereference_sk_user_data(sk) \ argument
674 __rcu_dereference_sk_user_data_with_flags(sk, 0)
675 #define __rcu_assign_sk_user_data_with_flags(sk, ptr, flags) \ argument
681 rcu_assign_pointer(__sk_user_data((sk)), \
684 #define rcu_assign_sk_user_data(sk, ptr) \ argument
685 __rcu_assign_sk_user_data_with_flags(sk, ptr, 0)
688 struct net *sock_net(const struct sock *sk) in sock_net() argument
690 return read_pnet(&sk->sk_net); in sock_net()
694 void sock_net_set(struct sock *sk, struct net *net) in sock_net_set() argument
696 write_pnet(&sk->sk_net, net); in sock_net_set()
710 int sk_set_peek_off(struct sock *sk, int val);
712 static inline int sk_peek_offset(const struct sock *sk, int flags) in sk_peek_offset() argument
715 return READ_ONCE(sk->sk_peek_off); in sk_peek_offset()
721 static inline void sk_peek_offset_bwd(struct sock *sk, int val) in sk_peek_offset_bwd() argument
723 s32 off = READ_ONCE(sk->sk_peek_off); in sk_peek_offset_bwd()
727 WRITE_ONCE(sk->sk_peek_off, off); in sk_peek_offset_bwd()
731 static inline void sk_peek_offset_fwd(struct sock *sk, int val) in sk_peek_offset_fwd() argument
733 sk_peek_offset_bwd(sk, -val); in sk_peek_offset_fwd()
764 static inline struct sock *sk_next(const struct sock *sk) in sk_next() argument
766 return hlist_entry_safe(sk->sk_node.next, struct sock, sk_node); in sk_next()
769 static inline struct sock *sk_nulls_next(const struct sock *sk) in sk_nulls_next() argument
771 return (!is_a_nulls(sk->sk_nulls_node.next)) ? in sk_nulls_next()
772 hlist_nulls_entry(sk->sk_nulls_node.next, in sk_nulls_next()
777 static inline bool sk_unhashed(const struct sock *sk) in sk_unhashed() argument
779 return hlist_unhashed(&sk->sk_node); in sk_unhashed()
782 static inline bool sk_hashed(const struct sock *sk) in sk_hashed() argument
784 return !sk_unhashed(sk); in sk_hashed()
792 static inline void __sk_del_node(struct sock *sk) in __sk_del_node() argument
794 __hlist_del(&sk->sk_node); in __sk_del_node()
798 static inline bool __sk_del_node_init(struct sock *sk) in __sk_del_node_init() argument
800 if (sk_hashed(sk)) { in __sk_del_node_init()
801 __sk_del_node(sk); in __sk_del_node_init()
802 sk_node_init(&sk->sk_node); in __sk_del_node_init()
814 static __always_inline void sock_hold(struct sock *sk) in sock_hold() argument
816 refcount_inc(&sk->sk_refcnt); in sock_hold()
822 static __always_inline void __sock_put(struct sock *sk) in __sock_put() argument
824 refcount_dec(&sk->sk_refcnt); in __sock_put()
827 static inline bool sk_del_node_init(struct sock *sk) in sk_del_node_init() argument
829 bool rc = __sk_del_node_init(sk); in sk_del_node_init()
833 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_del_node_init()
834 __sock_put(sk); in sk_del_node_init()
838 #define sk_del_node_init_rcu(sk) sk_del_node_init(sk) argument
840 static inline bool __sk_nulls_del_node_init_rcu(struct sock *sk) in __sk_nulls_del_node_init_rcu() argument
842 if (sk_hashed(sk)) { in __sk_nulls_del_node_init_rcu()
843 hlist_nulls_del_init_rcu(&sk->sk_nulls_node); in __sk_nulls_del_node_init_rcu()
849 static inline bool sk_nulls_del_node_init_rcu(struct sock *sk) in sk_nulls_del_node_init_rcu() argument
851 bool rc = __sk_nulls_del_node_init_rcu(sk); in sk_nulls_del_node_init_rcu()
855 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_nulls_del_node_init_rcu()
856 __sock_put(sk); in sk_nulls_del_node_init_rcu()
861 static inline void __sk_add_node(struct sock *sk, struct hlist_head *list) in __sk_add_node() argument
863 hlist_add_head(&sk->sk_node, list); in __sk_add_node()
866 static inline void sk_add_node(struct sock *sk, struct hlist_head *list) in sk_add_node() argument
868 sock_hold(sk); in sk_add_node()
869 __sk_add_node(sk, list); in sk_add_node()
872 static inline void sk_add_node_rcu(struct sock *sk, struct hlist_head *list) in sk_add_node_rcu() argument
874 sock_hold(sk); in sk_add_node_rcu()
875 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport && in sk_add_node_rcu()
876 sk->sk_family == AF_INET6) in sk_add_node_rcu()
877 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_rcu()
879 hlist_add_head_rcu(&sk->sk_node, list); in sk_add_node_rcu()
882 static inline void sk_add_node_tail_rcu(struct sock *sk, struct hlist_head *list) in sk_add_node_tail_rcu() argument
884 sock_hold(sk); in sk_add_node_tail_rcu()
885 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_tail_rcu()
888 static inline void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) in __sk_nulls_add_node_rcu() argument
890 hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_rcu()
893 static inline void __sk_nulls_add_node_tail_rcu(struct sock *sk, struct hlist_nulls_head *list) in __sk_nulls_add_node_tail_rcu() argument
895 hlist_nulls_add_tail_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_tail_rcu()
898 static inline void sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) in sk_nulls_add_node_rcu() argument
900 sock_hold(sk); in sk_nulls_add_node_rcu()
901 __sk_nulls_add_node_rcu(sk, list); in sk_nulls_add_node_rcu()
904 static inline void __sk_del_bind_node(struct sock *sk) in __sk_del_bind_node() argument
906 __hlist_del(&sk->sk_bind_node); in __sk_del_bind_node()
909 static inline void sk_add_bind_node(struct sock *sk, in sk_add_bind_node() argument
912 hlist_add_head(&sk->sk_bind_node, list); in sk_add_bind_node()
949 static inline struct user_namespace *sk_user_ns(const struct sock *sk) in sk_user_ns() argument
955 return sk->sk_socket->file->f_cred->user_ns; in sk_user_ns()
1008 static inline void sock_set_flag(struct sock *sk, enum sock_flags flag) in sock_set_flag() argument
1010 __set_bit(flag, &sk->sk_flags); in sock_set_flag()
1013 static inline void sock_reset_flag(struct sock *sk, enum sock_flags flag) in sock_reset_flag() argument
1015 __clear_bit(flag, &sk->sk_flags); in sock_reset_flag()
1018 static inline void sock_valbool_flag(struct sock *sk, enum sock_flags bit, in sock_valbool_flag() argument
1022 sock_set_flag(sk, bit); in sock_valbool_flag()
1024 sock_reset_flag(sk, bit); in sock_valbool_flag()
1027 static inline bool sock_flag(const struct sock *sk, enum sock_flags flag) in sock_flag() argument
1029 return test_bit(flag, &sk->sk_flags); in sock_flag()
1051 static inline gfp_t sk_gfp_mask(const struct sock *sk, gfp_t gfp_mask) in sk_gfp_mask() argument
1053 return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); in sk_gfp_mask()
1056 static inline void sk_acceptq_removed(struct sock *sk) in sk_acceptq_removed() argument
1058 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog - 1); in sk_acceptq_removed()
1061 static inline void sk_acceptq_added(struct sock *sk) in sk_acceptq_added() argument
1063 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog + 1); in sk_acceptq_added()
1070 static inline bool sk_acceptq_is_full(const struct sock *sk) in sk_acceptq_is_full() argument
1072 return READ_ONCE(sk->sk_ack_backlog) > READ_ONCE(sk->sk_max_ack_backlog); in sk_acceptq_is_full()
1078 static inline int sk_stream_min_wspace(const struct sock *sk) in sk_stream_min_wspace() argument
1080 return READ_ONCE(sk->sk_wmem_queued) >> 1; in sk_stream_min_wspace()
1083 static inline int sk_stream_wspace(const struct sock *sk) in sk_stream_wspace() argument
1085 return READ_ONCE(sk->sk_sndbuf) - READ_ONCE(sk->sk_wmem_queued); in sk_stream_wspace()
1088 static inline void sk_wmem_queued_add(struct sock *sk, int val) in sk_wmem_queued_add() argument
1090 WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val); in sk_wmem_queued_add()
1093 static inline void sk_forward_alloc_add(struct sock *sk, int val) in sk_forward_alloc_add() argument
1096 WRITE_ONCE(sk->sk_forward_alloc, sk->sk_forward_alloc + val); in sk_forward_alloc_add()
1099 void sk_stream_write_space(struct sock *sk);
1102 static inline void __sk_add_backlog(struct sock *sk, struct sk_buff *skb) in __sk_add_backlog() argument
1107 if (!sk->sk_backlog.tail) in __sk_add_backlog()
1108 WRITE_ONCE(sk->sk_backlog.head, skb); in __sk_add_backlog()
1110 sk->sk_backlog.tail->next = skb; in __sk_add_backlog()
1112 WRITE_ONCE(sk->sk_backlog.tail, skb); in __sk_add_backlog()
1121 static inline bool sk_rcvqueues_full(const struct sock *sk, unsigned int limit) in sk_rcvqueues_full() argument
1123 unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc); in sk_rcvqueues_full()
1129 static inline __must_check int sk_add_backlog(struct sock *sk, struct sk_buff *skb, in sk_add_backlog() argument
1132 if (sk_rcvqueues_full(sk, limit)) in sk_add_backlog()
1140 if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC)) in sk_add_backlog()
1143 __sk_add_backlog(sk, skb); in sk_add_backlog()
1144 sk->sk_backlog.len += skb->truesize; in sk_add_backlog()
1148 int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb);
1150 INDIRECT_CALLABLE_DECLARE(int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb));
1151 INDIRECT_CALLABLE_DECLARE(int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb));
1153 static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb) in sk_backlog_rcv() argument
1156 return __sk_backlog_rcv(sk, skb); in sk_backlog_rcv()
1158 return INDIRECT_CALL_INET(sk->sk_backlog_rcv, in sk_backlog_rcv()
1161 sk, skb); in sk_backlog_rcv()
1164 static inline void sk_incoming_cpu_update(struct sock *sk) in sk_incoming_cpu_update() argument
1168 if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu)) in sk_incoming_cpu_update()
1169 WRITE_ONCE(sk->sk_incoming_cpu, cpu); in sk_incoming_cpu_update()
1173 static inline void sock_rps_save_rxhash(struct sock *sk, in sock_rps_save_rxhash() argument
1180 if (unlikely(READ_ONCE(sk->sk_rxhash) != skb->hash)) in sock_rps_save_rxhash()
1181 WRITE_ONCE(sk->sk_rxhash, skb->hash); in sock_rps_save_rxhash()
1185 static inline void sock_rps_reset_rxhash(struct sock *sk) in sock_rps_reset_rxhash() argument
1189 WRITE_ONCE(sk->sk_rxhash, 0); in sock_rps_reset_rxhash()
1208 int sk_stream_wait_connect(struct sock *sk, long *timeo_p);
1209 int sk_stream_wait_memory(struct sock *sk, long *timeo_p);
1210 void sk_stream_wait_close(struct sock *sk, long timeo_p);
1211 int sk_stream_error(struct sock *sk, int flags, int err);
1212 void sk_stream_kill_queues(struct sock *sk);
1213 void sk_set_memalloc(struct sock *sk);
1214 void sk_clear_memalloc(struct sock *sk);
1216 void __sk_flush_backlog(struct sock *sk);
1218 static inline bool sk_flush_backlog(struct sock *sk) in sk_flush_backlog() argument
1220 if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { in sk_flush_backlog()
1221 __sk_flush_backlog(sk); in sk_flush_backlog()
1227 int sk_wait_data(struct sock *sk, long *timeo, const struct sk_buff *skb);
1241 static inline void sk_prot_clear_nulls(struct sock *sk, int size) in sk_prot_clear_nulls() argument
1244 memset(sk, 0, offsetof(struct sock, sk_node.next)); in sk_prot_clear_nulls()
1245 memset(&sk->sk_node.pprev, 0, in sk_prot_clear_nulls()
1260 void (*close)(struct sock *sk,
1262 int (*pre_connect)(struct sock *sk,
1265 int (*connect)(struct sock *sk,
1268 int (*disconnect)(struct sock *sk, int flags);
1270 struct sock * (*accept)(struct sock *sk,
1273 int (*ioctl)(struct sock *sk, int cmd,
1275 int (*init)(struct sock *sk);
1276 void (*destroy)(struct sock *sk);
1277 void (*shutdown)(struct sock *sk, int how);
1278 int (*setsockopt)(struct sock *sk, int level,
1281 int (*getsockopt)(struct sock *sk, int level,
1284 void (*keepalive)(struct sock *sk, int valbool);
1286 int (*compat_ioctl)(struct sock *sk,
1289 int (*sendmsg)(struct sock *sk, struct msghdr *msg,
1291 int (*recvmsg)(struct sock *sk, struct msghdr *msg,
1294 int (*bind)(struct sock *sk,
1296 int (*bind_add)(struct sock *sk,
1299 int (*backlog_rcv) (struct sock *sk,
1304 void (*release_cb)(struct sock *sk);
1307 int (*hash)(struct sock *sk);
1308 void (*unhash)(struct sock *sk);
1309 void (*rehash)(struct sock *sk);
1310 int (*get_port)(struct sock *sk, unsigned short snum);
1311 void (*put_port)(struct sock *sk);
1313 int (*psock_update_sk_prot)(struct sock *sk,
1323 bool (*stream_memory_free)(const struct sock *sk, int wake);
1324 bool (*sock_is_readable)(struct sock *sk);
1326 void (*enter_memory_pressure)(struct sock *sk);
1327 void (*leave_memory_pressure)(struct sock *sk);
1372 int (*diag_destroy)(struct sock *sk, int err);
1379 INDIRECT_CALLABLE_DECLARE(bool tcp_stream_memory_free(const struct sock *sk, int wake));
1381 static inline bool __sk_stream_memory_free(const struct sock *sk, int wake) in __sk_stream_memory_free() argument
1383 if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf)) in __sk_stream_memory_free()
1386 return sk->sk_prot->stream_memory_free ? in __sk_stream_memory_free()
1387 INDIRECT_CALL_INET_1(sk->sk_prot->stream_memory_free, in __sk_stream_memory_free()
1388 tcp_stream_memory_free, sk, wake) : true; in __sk_stream_memory_free()
1391 static inline bool sk_stream_memory_free(const struct sock *sk) in sk_stream_memory_free() argument
1393 return __sk_stream_memory_free(sk, 0); in sk_stream_memory_free()
1396 static inline bool __sk_stream_is_writeable(const struct sock *sk, int wake) in __sk_stream_is_writeable() argument
1398 return sk_stream_wspace(sk) >= sk_stream_min_wspace(sk) && in __sk_stream_is_writeable()
1399 __sk_stream_memory_free(sk, wake); in __sk_stream_is_writeable()
1402 static inline bool sk_stream_is_writeable(const struct sock *sk) in sk_stream_is_writeable() argument
1404 return __sk_stream_is_writeable(sk, 0); in sk_stream_is_writeable()
1407 static inline int sk_under_cgroup_hierarchy(struct sock *sk, in sk_under_cgroup_hierarchy() argument
1411 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), in sk_under_cgroup_hierarchy()
1420 static inline void sk_sockets_allocated_dec(struct sock *sk) in sk_sockets_allocated_dec() argument
1422 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, -1, in sk_sockets_allocated_dec()
1426 static inline void sk_sockets_allocated_inc(struct sock *sk) in sk_sockets_allocated_inc() argument
1428 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, 1, in sk_sockets_allocated_inc()
1433 sk_sockets_allocated_read_positive(struct sock *sk) in sk_sockets_allocated_read_positive() argument
1435 return percpu_counter_read_positive(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_read_positive()
1479 static inline int __sk_prot_rehash(struct sock *sk) in __sk_prot_rehash() argument
1481 sk->sk_prot->unhash(sk); in __sk_prot_rehash()
1482 return sk->sk_prot->hash(sk); in __sk_prot_rehash()
1520 int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind);
1521 int __sk_mem_schedule(struct sock *sk, int size, int kind);
1522 void __sk_mem_reduce_allocated(struct sock *sk, int amount);
1523 void __sk_mem_reclaim(struct sock *sk, int amount);
1529 static inline long sk_prot_mem_limits(const struct sock *sk, int index) in sk_prot_mem_limits() argument
1531 return READ_ONCE(sk->sk_prot->sysctl_mem[index]); in sk_prot_mem_limits()
1539 static inline bool sk_has_account(struct sock *sk) in sk_has_account() argument
1542 return !!sk->sk_prot->memory_allocated; in sk_has_account()
1545 static inline bool sk_wmem_schedule(struct sock *sk, int size) in sk_wmem_schedule() argument
1549 if (!sk_has_account(sk)) in sk_wmem_schedule()
1551 delta = size - sk->sk_forward_alloc; in sk_wmem_schedule()
1552 return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); in sk_wmem_schedule()
1556 __sk_rmem_schedule(struct sock *sk, int size, bool pfmemalloc) in __sk_rmem_schedule() argument
1560 if (!sk_has_account(sk)) in __sk_rmem_schedule()
1562 delta = size - sk->sk_forward_alloc; in __sk_rmem_schedule()
1563 return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || in __sk_rmem_schedule()
1568 sk_rmem_schedule(struct sock *sk, const struct sk_buff *skb, int size) in sk_rmem_schedule() argument
1570 return __sk_rmem_schedule(sk, size, skb_pfmemalloc(skb)); in sk_rmem_schedule()
1573 static inline int sk_unused_reserved_mem(const struct sock *sk) in sk_unused_reserved_mem() argument
1577 if (likely(!sk->sk_reserved_mem)) in sk_unused_reserved_mem()
1580 unused_mem = sk->sk_reserved_mem - sk->sk_wmem_queued - in sk_unused_reserved_mem()
1581 atomic_read(&sk->sk_rmem_alloc); in sk_unused_reserved_mem()
1586 static inline void sk_mem_reclaim(struct sock *sk) in sk_mem_reclaim() argument
1590 if (!sk_has_account(sk)) in sk_mem_reclaim()
1593 reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk); in sk_mem_reclaim()
1596 __sk_mem_reclaim(sk, reclaimable); in sk_mem_reclaim()
1599 static inline void sk_mem_reclaim_final(struct sock *sk) in sk_mem_reclaim_final() argument
1601 sk->sk_reserved_mem = 0; in sk_mem_reclaim_final()
1602 sk_mem_reclaim(sk); in sk_mem_reclaim_final()
1605 static inline void sk_mem_charge(struct sock *sk, int size) in sk_mem_charge() argument
1607 if (!sk_has_account(sk)) in sk_mem_charge()
1609 sk_forward_alloc_add(sk, -size); in sk_mem_charge()
1612 static inline void sk_mem_uncharge(struct sock *sk, int size) in sk_mem_uncharge() argument
1614 if (!sk_has_account(sk)) in sk_mem_uncharge()
1616 sk_forward_alloc_add(sk, size); in sk_mem_uncharge()
1617 sk_mem_reclaim(sk); in sk_mem_uncharge()
1621 static inline void sk_owner_set(struct sock *sk, struct module *owner) in sk_owner_set() argument
1624 sk->sk_owner = owner; in sk_owner_set()
1627 static inline void sk_owner_clear(struct sock *sk) in sk_owner_clear() argument
1629 sk->sk_owner = NULL; in sk_owner_clear()
1632 static inline void sk_owner_put(struct sock *sk) in sk_owner_put() argument
1634 module_put(sk->sk_owner); in sk_owner_put()
1637 static inline void sk_owner_set(struct sock *sk, struct module *owner) in sk_owner_set() argument
1641 static inline void sk_owner_clear(struct sock *sk) in sk_owner_clear() argument
1645 static inline void sk_owner_put(struct sock *sk) in sk_owner_put() argument
1656 #define sock_lock_init_class_and_name(sk, sname, skey, name, key) \ argument
1658 sk_owner_set(sk, THIS_MODULE); \
1659 sk->sk_lock.owned = 0; \
1660 init_waitqueue_head(&sk->sk_lock.wq); \
1661 spin_lock_init(&(sk)->sk_lock.slock); \
1662 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1663 sizeof((sk)->sk_lock)); \
1664 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1666 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1669 static inline bool lockdep_sock_is_held(const struct sock *sk) in lockdep_sock_is_held() argument
1671 return lockdep_is_held(&sk->sk_lock) || in lockdep_sock_is_held()
1672 lockdep_is_held(&sk->sk_lock.slock); in lockdep_sock_is_held()
1675 void lock_sock_nested(struct sock *sk, int subclass);
1677 static inline void lock_sock(struct sock *sk) in lock_sock() argument
1679 lock_sock_nested(sk, 0); in lock_sock()
1682 void __lock_sock(struct sock *sk);
1683 void __release_sock(struct sock *sk);
1684 void release_sock(struct sock *sk);
1693 bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock);
1708 static inline bool lock_sock_fast(struct sock *sk) in lock_sock_fast() argument
1711 mutex_acquire(&sk->sk_lock.dep_map, 0, 0, _RET_IP_); in lock_sock_fast()
1713 return __lock_sock_fast(sk); in lock_sock_fast()
1717 static inline bool lock_sock_fast_nested(struct sock *sk) in lock_sock_fast_nested() argument
1719 mutex_acquire(&sk->sk_lock.dep_map, SINGLE_DEPTH_NESTING, 0, _RET_IP_); in lock_sock_fast_nested()
1721 return __lock_sock_fast(sk); in lock_sock_fast_nested()
1732 static inline void unlock_sock_fast(struct sock *sk, bool slow) in unlock_sock_fast() argument
1733 __releases(&sk->sk_lock.slock) in unlock_sock_fast()
1736 release_sock(sk); in unlock_sock_fast()
1737 __release(&sk->sk_lock.slock); in unlock_sock_fast()
1739 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in unlock_sock_fast()
1740 spin_unlock_bh(&sk->sk_lock.slock); in unlock_sock_fast()
1744 void sockopt_lock_sock(struct sock *sk);
1745 void sockopt_release_sock(struct sock *sk);
1763 static inline void sock_owned_by_me(const struct sock *sk) in sock_owned_by_me() argument
1766 WARN_ON_ONCE(!lockdep_sock_is_held(sk) && debug_locks); in sock_owned_by_me()
1770 static inline void sock_not_owned_by_me(const struct sock *sk) in sock_not_owned_by_me() argument
1773 WARN_ON_ONCE(lockdep_sock_is_held(sk) && debug_locks); in sock_not_owned_by_me()
1777 static inline bool sock_owned_by_user(const struct sock *sk) in sock_owned_by_user() argument
1779 sock_owned_by_me(sk); in sock_owned_by_user()
1780 return sk->sk_lock.owned; in sock_owned_by_user()
1783 static inline bool sock_owned_by_user_nocheck(const struct sock *sk) in sock_owned_by_user_nocheck() argument
1785 return sk->sk_lock.owned; in sock_owned_by_user_nocheck()
1788 static inline void sock_release_ownership(struct sock *sk) in sock_release_ownership() argument
1790 DEBUG_NET_WARN_ON_ONCE(!sock_owned_by_user_nocheck(sk)); in sock_release_ownership()
1791 sk->sk_lock.owned = 0; in sock_release_ownership()
1794 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in sock_release_ownership()
1800 struct sock *sk = (struct sock *)csk; in sock_allow_reclassification() local
1802 return !sock_owned_by_user_nocheck(sk) && in sock_allow_reclassification()
1803 !spin_is_locked(&sk->sk_lock.slock); in sock_allow_reclassification()
1808 void sk_free(struct sock *sk);
1809 void sk_net_refcnt_upgrade(struct sock *sk);
1810 void sk_destruct(struct sock *sk);
1811 struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority);
1813 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
1817 struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size,
1826 static inline void skb_set_owner_edemux(struct sk_buff *skb, struct sock *sk) in skb_set_owner_edemux() argument
1829 if (refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_edemux()
1830 skb->sk = sk; in skb_set_owner_edemux()
1838 int sk_setsockopt(struct sock *sk, int level, int optname,
1847 int sk_getsockopt(struct sock *sk, int level, int optname,
1851 struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
1855 static inline struct sk_buff *sock_alloc_send_skb(struct sock *sk, in sock_alloc_send_skb() argument
1859 return sock_alloc_send_pskb(sk, size, 0, noblock, errcode, 0); in sock_alloc_send_skb()
1862 void *sock_kmalloc(struct sock *sk, int size, gfp_t priority);
1863 void *sock_kmemdup(struct sock *sk, const void *src,
1865 void sock_kfree_s(struct sock *sk, void *mem, int size);
1866 void sock_kzfree_s(struct sock *sk, void *mem, int size);
1867 void sk_send_sigurg(struct sock *sk);
1869 static inline void sock_replace_proto(struct sock *sk, struct proto *proto) in sock_replace_proto() argument
1871 if (sk->sk_socket) in sock_replace_proto()
1872 clear_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); in sock_replace_proto()
1873 WRITE_ONCE(sk->sk_prot, proto); in sock_replace_proto()
1886 const struct sock *sk) in sockcm_init() argument
1889 .mark = READ_ONCE(sk->sk_mark), in sockcm_init()
1890 .tsflags = READ_ONCE(sk->sk_tsflags), in sockcm_init()
1891 .priority = READ_ONCE(sk->sk_priority), in sockcm_init()
1895 int __sock_cmsg_send(struct sock *sk, struct cmsghdr *cmsg,
1897 int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
1913 int sock_no_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);
1929 void sk_common_release(struct sock *sk);
1936 void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid);
1941 void sock_init_data(struct socket *sock, struct sock *sk);
1969 static inline void sock_put(struct sock *sk) in sock_put() argument
1971 if (refcount_dec_and_test(&sk->sk_refcnt)) in sock_put()
1972 sk_free(sk); in sock_put()
1977 void sock_gen_put(struct sock *sk);
1979 int __sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested,
1981 static inline int sk_receive_skb(struct sock *sk, struct sk_buff *skb, in sk_receive_skb() argument
1984 return __sk_receive_skb(sk, skb, nested, 1, true); in sk_receive_skb()
1987 static inline void sk_tx_queue_set(struct sock *sk, int tx_queue) in sk_tx_queue_set() argument
1995 WRITE_ONCE(sk->sk_tx_queue_mapping, tx_queue); in sk_tx_queue_set()
2000 static inline void sk_tx_queue_clear(struct sock *sk) in sk_tx_queue_clear() argument
2005 WRITE_ONCE(sk->sk_tx_queue_mapping, NO_QUEUE_MAPPING); in sk_tx_queue_clear()
2008 static inline int sk_tx_queue_get(const struct sock *sk) in sk_tx_queue_get() argument
2010 if (sk) { in sk_tx_queue_get()
2014 int val = READ_ONCE(sk->sk_tx_queue_mapping); in sk_tx_queue_get()
2022 static inline void __sk_rx_queue_set(struct sock *sk, in __sk_rx_queue_set() argument
2031 unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) in __sk_rx_queue_set()
2032 WRITE_ONCE(sk->sk_rx_queue_mapping, rx_queue); in __sk_rx_queue_set()
2037 static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) in sk_rx_queue_set() argument
2039 __sk_rx_queue_set(sk, skb, true); in sk_rx_queue_set()
2042 static inline void sk_rx_queue_update(struct sock *sk, const struct sk_buff *skb) in sk_rx_queue_update() argument
2044 __sk_rx_queue_set(sk, skb, false); in sk_rx_queue_update()
2047 static inline void sk_rx_queue_clear(struct sock *sk) in sk_rx_queue_clear() argument
2050 WRITE_ONCE(sk->sk_rx_queue_mapping, NO_QUEUE_MAPPING); in sk_rx_queue_clear()
2054 static inline int sk_rx_queue_get(const struct sock *sk) in sk_rx_queue_get() argument
2057 if (sk) { in sk_rx_queue_get()
2058 int res = READ_ONCE(sk->sk_rx_queue_mapping); in sk_rx_queue_get()
2068 static inline void sk_set_socket(struct sock *sk, struct socket *sock) in sk_set_socket() argument
2070 sk->sk_socket = sock; in sk_set_socket()
2072 WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid); in sk_set_socket()
2073 WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino); in sk_set_socket()
2076 WRITE_ONCE(sk->sk_ino, 0); in sk_set_socket()
2080 static inline wait_queue_head_t *sk_sleep(struct sock *sk) in sk_sleep() argument
2083 return &rcu_dereference_raw(sk->sk_wq)->wait; in sk_sleep()
2092 static inline void sock_orphan(struct sock *sk) in sock_orphan() argument
2094 write_lock_bh(&sk->sk_callback_lock); in sock_orphan()
2095 sock_set_flag(sk, SOCK_DEAD); in sock_orphan()
2096 sk_set_socket(sk, NULL); in sock_orphan()
2097 sk->sk_wq = NULL; in sock_orphan()
2098 write_unlock_bh(&sk->sk_callback_lock); in sock_orphan()
2101 static inline void sock_graft(struct sock *sk, struct socket *parent) in sock_graft() argument
2103 WARN_ON(parent->sk); in sock_graft()
2104 write_lock_bh(&sk->sk_callback_lock); in sock_graft()
2105 rcu_assign_pointer(sk->sk_wq, &parent->wq); in sock_graft()
2106 parent->sk = sk; in sock_graft()
2107 sk_set_socket(sk, parent); in sock_graft()
2108 security_sock_graft(sk, parent); in sock_graft()
2109 write_unlock_bh(&sk->sk_callback_lock); in sock_graft()
2112 static inline unsigned long sock_i_ino(const struct sock *sk) in sock_i_ino() argument
2115 return READ_ONCE(sk->sk_ino); in sock_i_ino()
2118 static inline kuid_t sk_uid(const struct sock *sk) in sk_uid() argument
2121 return READ_ONCE(sk->sk_uid); in sk_uid()
2124 static inline kuid_t sock_net_uid(const struct net *net, const struct sock *sk) in sock_net_uid() argument
2126 return sk ? sk_uid(sk) : make_kuid(net->user_ns, 0); in sock_net_uid()
2136 static inline void sk_set_txhash(struct sock *sk) in sk_set_txhash() argument
2139 WRITE_ONCE(sk->sk_txhash, net_tx_rndhash()); in sk_set_txhash()
2142 static inline bool sk_rethink_txhash(struct sock *sk) in sk_rethink_txhash() argument
2144 if (sk->sk_txhash && sk->sk_txrehash == SOCK_TXREHASH_ENABLED) { in sk_rethink_txhash()
2145 sk_set_txhash(sk); in sk_rethink_txhash()
2152 __sk_dst_get(const struct sock *sk) in __sk_dst_get() argument
2154 return rcu_dereference_check(sk->sk_dst_cache, in __sk_dst_get()
2155 lockdep_sock_is_held(sk)); in __sk_dst_get()
2159 sk_dst_get(const struct sock *sk) in sk_dst_get() argument
2164 dst = rcu_dereference(sk->sk_dst_cache); in sk_dst_get()
2171 static inline void __dst_negative_advice(struct sock *sk) in __dst_negative_advice() argument
2173 struct dst_entry *dst = __sk_dst_get(sk); in __dst_negative_advice()
2176 dst->ops->negative_advice(sk, dst); in __dst_negative_advice()
2179 static inline void dst_negative_advice(struct sock *sk) in dst_negative_advice() argument
2181 sk_rethink_txhash(sk); in dst_negative_advice()
2182 __dst_negative_advice(sk); in dst_negative_advice()
2186 __sk_dst_set(struct sock *sk, struct dst_entry *dst) in __sk_dst_set() argument
2190 sk_tx_queue_clear(sk); in __sk_dst_set()
2191 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in __sk_dst_set()
2192 old_dst = rcu_dereference_protected(sk->sk_dst_cache, in __sk_dst_set()
2193 lockdep_sock_is_held(sk)); in __sk_dst_set()
2194 rcu_assign_pointer(sk->sk_dst_cache, dst); in __sk_dst_set()
2199 sk_dst_set(struct sock *sk, struct dst_entry *dst) in sk_dst_set() argument
2203 sk_tx_queue_clear(sk); in sk_dst_set()
2204 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sk_dst_set()
2205 old_dst = unrcu_pointer(xchg(&sk->sk_dst_cache, RCU_INITIALIZER(dst))); in sk_dst_set()
2210 __sk_dst_reset(struct sock *sk) in __sk_dst_reset() argument
2212 __sk_dst_set(sk, NULL); in __sk_dst_reset()
2216 sk_dst_reset(struct sock *sk) in sk_dst_reset() argument
2218 sk_dst_set(sk, NULL); in sk_dst_reset()
2221 struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);
2223 struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie);
2225 static inline void sk_dst_confirm(struct sock *sk) in sk_dst_confirm() argument
2227 if (!READ_ONCE(sk->sk_dst_pending_confirm)) in sk_dst_confirm()
2228 WRITE_ONCE(sk->sk_dst_pending_confirm, 1); in sk_dst_confirm()
2234 struct sock *sk = skb->sk; in sock_confirm_neigh() local
2236 if (sk && READ_ONCE(sk->sk_dst_pending_confirm)) in sock_confirm_neigh()
2237 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sock_confirm_neigh()
2242 bool sk_mc_loop(const struct sock *sk);
2244 static inline bool sk_can_gso(const struct sock *sk) in sk_can_gso() argument
2246 return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); in sk_can_gso()
2249 void sk_setup_caps(struct sock *sk, struct dst_entry *dst);
2251 static inline void sk_gso_disable(struct sock *sk) in sk_gso_disable() argument
2253 sk->sk_gso_disabled = 1; in sk_gso_disable()
2254 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; in sk_gso_disable()
2257 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb, in skb_do_copy_data_nocache() argument
2266 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { in skb_do_copy_data_nocache()
2275 static inline int skb_add_data_nocache(struct sock *sk, struct sk_buff *skb, in skb_add_data_nocache() argument
2280 err = skb_do_copy_data_nocache(sk, skb, from, skb_put(skb, copy), in skb_add_data_nocache()
2288 static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *from, in skb_copy_to_page_nocache() argument
2295 err = skb_do_copy_data_nocache(sk, skb, from, page_address(page) + off, in skb_copy_to_page_nocache()
2301 sk_wmem_queued_add(sk, copy); in skb_copy_to_page_nocache()
2302 sk_mem_charge(sk, copy); in skb_copy_to_page_nocache()
2312 static inline int sk_wmem_alloc_get(const struct sock *sk) in sk_wmem_alloc_get() argument
2314 return refcount_read(&sk->sk_wmem_alloc) - 1; in sk_wmem_alloc_get()
2323 static inline int sk_rmem_alloc_get(const struct sock *sk) in sk_rmem_alloc_get() argument
2325 return atomic_read(&sk->sk_rmem_alloc); in sk_rmem_alloc_get()
2334 static inline bool sk_has_allocations(const struct sock *sk) in sk_has_allocations() argument
2336 return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); in sk_has_allocations()
2394 static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *sk) in skb_set_hash_from_sk() argument
2397 u32 txhash = READ_ONCE(sk->sk_txhash); in skb_set_hash_from_sk()
2405 void skb_set_owner_w(struct sk_buff *skb, struct sock *sk);
2415 static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk) in skb_set_owner_r() argument
2418 skb->sk = sk; in skb_set_owner_r()
2420 atomic_add(skb->truesize, &sk->sk_rmem_alloc); in skb_set_owner_r()
2421 sk_mem_charge(sk, skb->truesize); in skb_set_owner_r()
2424 static inline __must_check bool skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk) in skb_set_owner_sk_safe() argument
2426 if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_sk_safe()
2429 skb->sk = sk; in skb_set_owner_sk_safe()
2435 static inline struct sk_buff *skb_clone_and_charge_r(struct sk_buff *skb, struct sock *sk) in skb_clone_and_charge_r() argument
2437 skb = skb_clone(skb, sk_gfp_mask(sk, GFP_ATOMIC)); in skb_clone_and_charge_r()
2439 if (sk_rmem_schedule(sk, skb, skb->truesize)) { in skb_clone_and_charge_r()
2440 skb_set_owner_r(skb, sk); in skb_clone_and_charge_r()
2457 void sk_reset_timer(struct sock *sk, struct timer_list *timer,
2460 void sk_stop_timer(struct sock *sk, struct timer_list *timer);
2462 void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer);
2464 int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue,
2466 void (*destructor)(struct sock *sk,
2468 int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
2470 int sock_queue_rcv_skb_reason(struct sock *sk, struct sk_buff *skb,
2473 static inline int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) in sock_queue_rcv_skb() argument
2475 return sock_queue_rcv_skb_reason(sk, skb, NULL); in sock_queue_rcv_skb()
2478 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb);
2479 struct sk_buff *sock_dequeue_err_skb(struct sock *sk);
2485 static inline int sock_error(struct sock *sk) in sock_error() argument
2492 if (likely(data_race(!sk->sk_err))) in sock_error()
2495 err = xchg(&sk->sk_err, 0); in sock_error()
2499 void sk_error_report(struct sock *sk);
2501 static inline unsigned long sock_wspace(struct sock *sk) in sock_wspace() argument
2505 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in sock_wspace()
2506 amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc); in sock_wspace()
2517 static inline void sk_set_bit(int nr, struct sock *sk) in sk_set_bit() argument
2520 !sock_flag(sk, SOCK_FASYNC)) in sk_set_bit()
2523 set_bit(nr, &sk->sk_wq_raw->flags); in sk_set_bit()
2526 static inline void sk_clear_bit(int nr, struct sock *sk) in sk_clear_bit() argument
2529 !sock_flag(sk, SOCK_FASYNC)) in sk_clear_bit()
2532 clear_bit(nr, &sk->sk_wq_raw->flags); in sk_clear_bit()
2535 static inline void sk_wake_async(const struct sock *sk, int how, int band) in sk_wake_async() argument
2537 if (sock_flag(sk, SOCK_FASYNC)) { in sk_wake_async()
2539 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async()
2544 static inline void sk_wake_async_rcu(const struct sock *sk, int how, int band) in sk_wake_async_rcu() argument
2546 if (unlikely(sock_flag(sk, SOCK_FASYNC))) in sk_wake_async_rcu()
2547 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async_rcu()
2560 static inline void sk_stream_moderate_sndbuf(struct sock *sk) in sk_stream_moderate_sndbuf() argument
2564 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) in sk_stream_moderate_sndbuf()
2567 val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); in sk_stream_moderate_sndbuf()
2568 val = max_t(u32, val, sk_unused_reserved_mem(sk)); in sk_stream_moderate_sndbuf()
2570 WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF)); in sk_stream_moderate_sndbuf()
2589 static inline struct page_frag *sk_page_frag(struct sock *sk) in sk_page_frag() argument
2591 if (sk->sk_use_task_frag) in sk_page_frag()
2594 return &sk->sk_frag; in sk_page_frag()
2597 bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag);
2602 static inline bool sock_writeable(const struct sock *sk) in sock_writeable() argument
2604 return refcount_read(&sk->sk_wmem_alloc) < (READ_ONCE(sk->sk_sndbuf) >> 1); in sock_writeable()
2618 static inline struct mem_cgroup *mem_cgroup_from_sk(const struct sock *sk) in mem_cgroup_from_sk() argument
2620 return sk->sk_memcg; in mem_cgroup_from_sk()
2623 static inline bool mem_cgroup_sk_enabled(const struct sock *sk) in mem_cgroup_sk_enabled() argument
2625 return mem_cgroup_sockets_enabled && mem_cgroup_from_sk(sk); in mem_cgroup_sk_enabled()
2628 static inline bool mem_cgroup_sk_under_memory_pressure(const struct sock *sk) in mem_cgroup_sk_under_memory_pressure() argument
2630 struct mem_cgroup *memcg = mem_cgroup_from_sk(sk); in mem_cgroup_sk_under_memory_pressure()
2645 static inline struct mem_cgroup *mem_cgroup_from_sk(const struct sock *sk) in mem_cgroup_from_sk() argument
2650 static inline bool mem_cgroup_sk_enabled(const struct sock *sk) in mem_cgroup_sk_enabled() argument
2655 static inline bool mem_cgroup_sk_under_memory_pressure(const struct sock *sk) in mem_cgroup_sk_under_memory_pressure() argument
2661 static inline long sock_rcvtimeo(const struct sock *sk, bool noblock) in sock_rcvtimeo() argument
2663 return noblock ? 0 : READ_ONCE(sk->sk_rcvtimeo); in sock_rcvtimeo()
2666 static inline long sock_sndtimeo(const struct sock *sk, bool noblock) in sock_sndtimeo() argument
2668 return noblock ? 0 : READ_ONCE(sk->sk_sndtimeo); in sock_sndtimeo()
2671 static inline int sock_rcvlowat(const struct sock *sk, int waitall, int len) in sock_rcvlowat() argument
2673 int v = waitall ? len : min_t(int, READ_ONCE(sk->sk_rcvlowat), len); in sock_rcvlowat()
2703 static inline void sk_drops_add(struct sock *sk, int segs) in sk_drops_add() argument
2705 struct numa_drop_counters *ndc = sk->sk_drop_counters; in sk_drops_add()
2710 atomic_add(segs, &sk->sk_drops); in sk_drops_add()
2713 static inline void sk_drops_inc(struct sock *sk) in sk_drops_inc() argument
2715 sk_drops_add(sk, 1); in sk_drops_inc()
2718 static inline int sk_drops_read(const struct sock *sk) in sk_drops_read() argument
2720 const struct numa_drop_counters *ndc = sk->sk_drop_counters; in sk_drops_read()
2723 DEBUG_NET_WARN_ON_ONCE(atomic_read(&sk->sk_drops)); in sk_drops_read()
2726 return atomic_read(&sk->sk_drops); in sk_drops_read()
2729 static inline void sk_drops_reset(struct sock *sk) in sk_drops_reset() argument
2731 struct numa_drop_counters *ndc = sk->sk_drop_counters; in sk_drops_reset()
2735 atomic_set(&sk->sk_drops, 0); in sk_drops_reset()
2739 sock_skb_set_dropcount(const struct sock *sk, struct sk_buff *skb) in sock_skb_set_dropcount() argument
2741 SOCK_SKB_CB(skb)->dropcount = sock_flag(sk, SOCK_RXQ_OVFL) ? in sock_skb_set_dropcount()
2742 sk_drops_read(sk) : 0; in sock_skb_set_dropcount()
2745 static inline void sk_drops_skbadd(struct sock *sk, const struct sk_buff *skb) in sk_drops_skbadd() argument
2749 sk_drops_add(sk, segs); in sk_drops_skbadd()
2752 static inline ktime_t sock_read_timestamp(struct sock *sk) in sock_read_timestamp() argument
2759 seq = read_seqbegin(&sk->sk_stamp_seq); in sock_read_timestamp()
2760 kt = sk->sk_stamp; in sock_read_timestamp()
2761 } while (read_seqretry(&sk->sk_stamp_seq, seq)); in sock_read_timestamp()
2765 return READ_ONCE(sk->sk_stamp); in sock_read_timestamp()
2769 static inline void sock_write_timestamp(struct sock *sk, ktime_t kt) in sock_write_timestamp() argument
2772 write_seqlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2773 sk->sk_stamp = kt; in sock_write_timestamp()
2774 write_sequnlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2776 WRITE_ONCE(sk->sk_stamp, kt); in sock_write_timestamp()
2780 void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
2782 void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
2785 bool skb_has_tx_timestamp(struct sk_buff *skb, const struct sock *sk);
2786 int skb_get_tx_timestamp(struct sk_buff *skb, struct sock *sk,
2790 sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) in sock_recv_timestamp() argument
2793 u32 tsflags = READ_ONCE(sk->sk_tsflags); in sock_recv_timestamp()
2801 if (sock_flag(sk, SOCK_RCVTSTAMP) || in sock_recv_timestamp()
2806 __sock_recv_timestamp(msg, sk, skb); in sock_recv_timestamp()
2808 sock_write_timestamp(sk, kt); in sock_recv_timestamp()
2810 if (sock_flag(sk, SOCK_WIFI_STATUS) && skb_wifi_acked_valid(skb)) in sock_recv_timestamp()
2811 __sock_recv_wifi_status(msg, sk, skb); in sock_recv_timestamp()
2814 void __sock_recv_cmsgs(struct msghdr *msg, struct sock *sk,
2818 static inline void sock_recv_cmsgs(struct msghdr *msg, struct sock *sk, in sock_recv_cmsgs() argument
2829 if (READ_ONCE(sk->sk_flags) & FLAGS_RECV_CMSGS) in sock_recv_cmsgs()
2830 __sock_recv_cmsgs(msg, sk, skb); in sock_recv_cmsgs()
2831 else if (unlikely(sock_flag(sk, SOCK_TIMESTAMP))) in sock_recv_cmsgs()
2832 sock_write_timestamp(sk, skb->tstamp); in sock_recv_cmsgs()
2833 else if (unlikely(sock_read_timestamp(sk) == SK_DEFAULT_STAMP)) in sock_recv_cmsgs()
2834 sock_write_timestamp(sk, 0); in sock_recv_cmsgs()
2848 static inline void _sock_tx_timestamp(struct sock *sk, in _sock_tx_timestamp() argument
2861 *tskey = atomic_inc_return(&sk->sk_tskey) - 1; in _sock_tx_timestamp()
2866 static inline void sock_tx_timestamp(struct sock *sk, in sock_tx_timestamp() argument
2870 _sock_tx_timestamp(sk, sockc, tx_flags, NULL); in sock_tx_timestamp()
2876 _sock_tx_timestamp(skb->sk, sockc, &skb_shinfo(skb)->tx_flags, in skb_setup_tx_timestamp()
2880 static inline bool sk_is_inet(const struct sock *sk) in sk_is_inet() argument
2882 int family = READ_ONCE(sk->sk_family); in sk_is_inet()
2887 static inline bool sk_is_tcp(const struct sock *sk) in sk_is_tcp() argument
2889 return sk_is_inet(sk) && in sk_is_tcp()
2890 sk->sk_type == SOCK_STREAM && in sk_is_tcp()
2891 sk->sk_protocol == IPPROTO_TCP; in sk_is_tcp()
2894 static inline bool sk_is_udp(const struct sock *sk) in sk_is_udp() argument
2896 return sk_is_inet(sk) && in sk_is_udp()
2897 sk->sk_type == SOCK_DGRAM && in sk_is_udp()
2898 sk->sk_protocol == IPPROTO_UDP; in sk_is_udp()
2901 static inline bool sk_is_unix(const struct sock *sk) in sk_is_unix() argument
2903 return sk->sk_family == AF_UNIX; in sk_is_unix()
2906 static inline bool sk_is_stream_unix(const struct sock *sk) in sk_is_stream_unix() argument
2908 return sk_is_unix(sk) && sk->sk_type == SOCK_STREAM; in sk_is_stream_unix()
2911 static inline bool sk_is_vsock(const struct sock *sk) in sk_is_vsock() argument
2913 return sk->sk_family == AF_VSOCK; in sk_is_vsock()
2916 static inline bool sk_may_scm_recv(const struct sock *sk) in sk_may_scm_recv() argument
2918 return (IS_ENABLED(CONFIG_UNIX) && sk->sk_family == AF_UNIX) || in sk_may_scm_recv()
2919 sk->sk_family == AF_NETLINK || in sk_may_scm_recv()
2920 (IS_ENABLED(CONFIG_BT) && sk->sk_family == AF_BLUETOOTH); in sk_may_scm_recv()
2931 static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb) in sk_eat_skb() argument
2933 __skb_unlink(skb, &sk->sk_receive_queue); in sk_eat_skb()
2950 static inline bool sk_fullsock(const struct sock *sk) in sk_fullsock() argument
2952 return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); in sk_fullsock()
2956 sk_is_refcounted(struct sock *sk) in sk_is_refcounted() argument
2959 return !sk_fullsock(sk) || !sock_flag(sk, SOCK_RCU_FREE); in sk_is_refcounted()
2963 sk_requests_wifi_status(struct sock *sk) in sk_requests_wifi_status() argument
2965 return sk && sk_fullsock(sk) && sock_flag(sk, SOCK_WIFI_STATUS); in sk_requests_wifi_status()
2971 static inline bool sk_listener(const struct sock *sk) in sk_listener() argument
2973 return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); in sk_listener()
2980 static inline bool sk_listener_or_tw(const struct sock *sk) in sk_listener_or_tw() argument
2982 return (1 << READ_ONCE(sk->sk_state)) & in sk_listener_or_tw()
2986 void sock_enable_timestamp(struct sock *sk, enum sock_flags flag);
2987 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level,
2990 bool sk_ns_capable(const struct sock *sk,
2992 bool sk_capable(const struct sock *sk, int cap);
2993 bool sk_net_capable(const struct sock *sk, int cap);
2995 void sk_get_meminfo(const struct sock *sk, u32 *meminfo);
3016 static inline int sk_get_wmem0(const struct sock *sk, const struct proto *proto) in sk_get_wmem0() argument
3020 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_wmem_offset)); in sk_get_wmem0()
3025 static inline int sk_get_rmem0(const struct sock *sk, const struct proto *proto) in sk_get_rmem0() argument
3029 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_rmem_offset)); in sk_get_rmem0()
3038 static inline void sk_pacing_shift_update(struct sock *sk, int val) in sk_pacing_shift_update() argument
3040 if (!sk || !sk_fullsock(sk) || READ_ONCE(sk->sk_pacing_shift) == val) in sk_pacing_shift_update()
3042 WRITE_ONCE(sk->sk_pacing_shift, val); in sk_pacing_shift_update()
3050 static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif) in sk_dev_equal_l3scope() argument
3052 int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); in sk_dev_equal_l3scope()
3058 mdif = l3mdev_master_ifindex_by_index(sock_net(sk), dif); in sk_dev_equal_l3scope()
3065 void sock_def_readable(struct sock *sk);
3067 int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
3068 void sock_set_timestamp(struct sock *sk, int optname, bool valbool);
3069 int sock_set_timestamping(struct sock *sk, int optname,
3073 void bpf_skops_tx_timestamping(struct sock *sk, struct sk_buff *skb, int op);
3075 static inline void bpf_skops_tx_timestamping(struct sock *sk, struct sk_buff *skb, int op) in bpf_skops_tx_timestamping() argument
3079 void sock_no_linger(struct sock *sk);
3080 void sock_set_keepalive(struct sock *sk);
3081 void sock_set_priority(struct sock *sk, u32 priority);
3082 void sock_set_rcvbuf(struct sock *sk, int val);
3083 void sock_set_mark(struct sock *sk, u32 val);
3084 void sock_set_reuseaddr(struct sock *sk);
3085 void sock_set_reuseport(struct sock *sk);
3086 void sock_set_sndtimeo(struct sock *sk, s64 secs);
3088 int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
3094 int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
3096 int sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
3097 static inline bool sk_is_readable(struct sock *sk) in sk_is_readable() argument
3099 const struct proto *prot = READ_ONCE(sk->sk_prot); in sk_is_readable()
3102 return prot->sock_is_readable(sk); in sk_is_readable()