Lines Matching +full:route +full:- +full:ptp
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
13 * Corey Minyard <wf-rch!minyard@relay.EU.net>
14 * Florian La Roche <flla@stud.uni-sb.de>
57 #include <linux/cgroup-defs.h>
79 /* This is the per-socket lock. The spinlock provides a synchronization
81 * mini-semaphore synchronizes multiple users amongst themselves.
88 * We express the mutex-alike socket_lock semantics
106 * struct sock_common - minimal network layer representation of sockets
109 * @skc_addrpair: 8-byte-aligned __u64 union of @skc_daddr & @skc_rcv_saddr
123 * @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol
130 * @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol
238 * struct sock - network layer representation of sockets
246 * @sk_rx_dst: receive input route used by early demux
259 * @sk_reserved_mem: space reserved and non-reclaimable for the socket
269 * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO)
276 * @sk_backlog: always used with the per-socket spinlock held
306 * @sk_use_task_frag: allow sk_page_frag() to use current->task_frag.
309 * @sk_bind_phc: SO_TIMESTAMPING bind PHC index of PTP virtual clock
314 * @sk_user_data: RPC layer private data. Write-protected by @sk_callback_lock.
318 * @tcp_rtx_queue: TCP re-transmit queue [union with @sk_send_head]
335 * @sk_clockid: clockid used by time-based scheduling (SO_TXTIME)
345 * don't add nothing before this first member (__sk_common) --acme
390 * the per-socket spinlock held and requires low latency
562 * - SK_USER_DATA_NOCOPY: Pointer stored in sk_user_data might
567 * - SK_USER_DATA_BPF: Mark whether sk_user_data field is
571 * - SK_USER_DATA_PSOCK: Mark whether pointer stored in
582 * sk_user_data_is_nocopy - Test if sk_user_data pointer must not be copied
587 return ((uintptr_t)sk->sk_user_data & SK_USER_DATA_NOCOPY); in sk_user_data_is_nocopy()
590 #define __sk_user_data(sk) ((*((void __rcu **)&(sk)->sk_user_data)))
593 * __locked_read_sk_user_data_with_flags - return the pointer
600 * The caller must be holding sk->sk_callback_lock.
608 lockdep_is_held(&sk->sk_callback_lock)); in __locked_read_sk_user_data_with_flags()
618 * __rcu_dereference_sk_user_data_with_flags - return the pointer
655 return read_pnet(&sk->sk_net); in sock_net()
661 write_pnet(&sk->sk_net, net); in sock_net_set()
680 return READ_ONCE(sk->sk_peek_off); in sk_peek_offset()
688 s32 off = READ_ONCE(sk->sk_peek_off); in sk_peek_offset_bwd()
691 off = max_t(s32, off - val, 0); in sk_peek_offset_bwd()
692 WRITE_ONCE(sk->sk_peek_off, off); in sk_peek_offset_bwd()
698 sk_peek_offset_bwd(sk, -val); in sk_peek_offset_fwd()
711 return hlist_entry(head->first, struct sock, sk_node); in __sk_head()
721 return hlist_nulls_entry(head->first, struct sock, sk_nulls_node); in __sk_nulls_head()
731 return hlist_entry_safe(sk->sk_node.next, struct sock, sk_node); in sk_next()
736 return (!is_a_nulls(sk->sk_nulls_node.next)) ? in sk_nulls_next()
737 hlist_nulls_entry(sk->sk_nulls_node.next, in sk_nulls_next()
744 return hlist_unhashed(&sk->sk_node); in sk_unhashed()
754 node->pprev = NULL; in sk_node_init()
759 __hlist_del(&sk->sk_node); in __sk_del_node()
767 sk_node_init(&sk->sk_node); in __sk_del_node_init()
781 refcount_inc(&sk->sk_refcnt); in sock_hold()
789 refcount_dec(&sk->sk_refcnt); in __sock_put()
797 /* paranoid for a while -acme */ in sk_del_node_init()
798 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_del_node_init()
808 hlist_nulls_del_init_rcu(&sk->sk_nulls_node); in __sk_nulls_del_node_init_rcu()
819 /* paranoid for a while -acme */ in sk_nulls_del_node_init_rcu()
820 WARN_ON(refcount_read(&sk->sk_refcnt) == 1); in sk_nulls_del_node_init_rcu()
828 hlist_add_head(&sk->sk_node, list); in __sk_add_node()
840 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport && in sk_add_node_rcu()
841 sk->sk_family == AF_INET6) in sk_add_node_rcu()
842 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_rcu()
844 hlist_add_head_rcu(&sk->sk_node, list); in sk_add_node_rcu()
850 hlist_add_tail_rcu(&sk->sk_node, list); in sk_add_node_tail_rcu()
855 hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_rcu()
860 hlist_nulls_add_tail_rcu(&sk->sk_nulls_node, list); in __sk_nulls_add_node_tail_rcu()
871 __hlist_del(&sk->sk_bind_node); in __sk_del_bind_node()
877 hlist_add_head(&sk->sk_bind_node, list); in sk_add_bind_node()
891 if (__sk && ({ node = &(__sk)->sk_nulls_node; 1; })) \
901 * sk_for_each_entry_offset_rcu - iterate over a list at a given struct offset
911 ({ tpos = (typeof(*tpos) *)((void *)pos - offset); 1;}); \
920 return sk->sk_socket->file->f_cred->user_ns; in sk_user_ns()
934 SOCK_USE_WRITE_QUEUE, /* whether to call sk->sk_write_space in sock_wfree */
938 SOCK_LOCALROUTE, /* route locally only, %SO_DONTROUTE setting */
947 * user-space instead.
962 nsk->sk_flags = osk->sk_flags; in sock_copy_flags()
967 __set_bit(flag, &sk->sk_flags); in sock_set_flag()
972 __clear_bit(flag, &sk->sk_flags); in sock_reset_flag()
986 return test_bit(flag, &sk->sk_flags); in sock_flag()
1010 return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); in sk_gfp_mask()
1015 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog - 1); in sk_acceptq_removed()
1020 WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog + 1); in sk_acceptq_added()
1024 * return READ_ONCE(sk->sk_ack_backlog) >= READ_ONCE(sk->sk_max_ack_backlog);
1029 return READ_ONCE(sk->sk_ack_backlog) > READ_ONCE(sk->sk_max_ack_backlog); in sk_acceptq_is_full()
1037 return READ_ONCE(sk->sk_wmem_queued) >> 1; in sk_stream_min_wspace()
1042 return READ_ONCE(sk->sk_sndbuf) - READ_ONCE(sk->sk_wmem_queued); in sk_stream_wspace()
1047 WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val); in sk_wmem_queued_add()
1052 /* Paired with lockless reads of sk->sk_forward_alloc */ in sk_forward_alloc_add()
1053 WRITE_ONCE(sk->sk_forward_alloc, sk->sk_forward_alloc + val); in sk_forward_alloc_add()
1064 if (!sk->sk_backlog.tail) in __sk_add_backlog()
1065 WRITE_ONCE(sk->sk_backlog.head, skb); in __sk_add_backlog()
1067 sk->sk_backlog.tail->next = skb; in __sk_add_backlog()
1069 WRITE_ONCE(sk->sk_backlog.tail, skb); in __sk_add_backlog()
1070 skb->next = NULL; in __sk_add_backlog()
1080 unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc); in sk_rcvqueues_full()
1085 /* The per-socket spinlock must be held here. */
1090 return -ENOBUFS; in sk_add_backlog()
1098 return -ENOMEM; in sk_add_backlog()
1101 sk->sk_backlog.len += skb->truesize; in sk_add_backlog()
1115 return INDIRECT_CALL_INET(sk->sk_backlog_rcv, in sk_backlog_rcv()
1125 if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu)) in sk_incoming_cpu_update()
1126 WRITE_ONCE(sk->sk_incoming_cpu, cpu); in sk_incoming_cpu_update()
1137 if (unlikely(READ_ONCE(sk->sk_rxhash) != skb->hash)) in sock_rps_save_rxhash()
1138 WRITE_ONCE(sk->sk_rxhash, skb->hash); in sock_rps_save_rxhash()
1146 WRITE_ONCE(sk->sk_rxhash, 0); in sock_rps_reset_rxhash()
1151 ({ int __rc, __dis = __sk->sk_disconnects; \
1161 __rc = __dis == __sk->sk_disconnects ? __condition : -EPIPE; \
1177 if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { in sk_flush_backlog()
1196 * un-modified. Special care is taken when initializing object to zero.
1202 memset(&sk->sk_node.pprev, 0, in sk_prot_clear_nulls()
1203 size - offsetof(struct sock, sk_node.pprev)); in sk_prot_clear_nulls()
1214 * socket layer -> transport layer interface
1347 if (sk->sk_prot->forward_alloc_get) in sk_forward_alloc_get()
1348 return sk->sk_prot->forward_alloc_get(sk); in sk_forward_alloc_get()
1350 return READ_ONCE(sk->sk_forward_alloc); in sk_forward_alloc_get()
1355 if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf)) in __sk_stream_memory_free()
1358 return sk->sk_prot->stream_memory_free ? in __sk_stream_memory_free()
1359 INDIRECT_CALL_INET_1(sk->sk_prot->stream_memory_free, in __sk_stream_memory_free()
1383 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), in sk_under_cgroup_hierarchy()
1386 return -ENOTSUPP; in sk_under_cgroup_hierarchy()
1394 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, -1, in sk_sockets_allocated_dec()
1400 percpu_counter_add_batch(sk->sk_prot->sockets_allocated, 1, in sk_sockets_allocated_inc()
1407 return percpu_counter_read_positive(sk->sk_prot->sockets_allocated); in sk_sockets_allocated_read_positive()
1413 return percpu_counter_sum_positive(prot->sockets_allocated); in proto_sockets_allocated_sum_positive()
1426 this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); in sock_prot_inuse_add()
1431 this_cpu_add(net->core.prot_inuse->all, val); in sock_inuse_add()
1448 /* With per-bucket locks this operation is not-atomic, so that
1453 sk->sk_prot->unhash(sk); in __sk_prot_rehash()
1454 return sk->sk_prot->hash(sk); in __sk_prot_rehash()
1460 /* Sockets 0-1023 can't be bound to unless you are superuser */
1477 return &container_of(inode, struct socket_alloc, vfs_inode)->socket; in SOCKET_I()
1482 return &container_of(socket, struct socket_alloc, socket)->vfs_inode; in SOCK_INODE()
1499 return READ_ONCE(sk->sk_prot->sysctl_mem[index]); in sk_prot_mem_limits()
1504 return (amt + PAGE_SIZE - 1) >> PAGE_SHIFT; in sk_mem_pages()
1510 return !!sk->sk_prot->memory_allocated; in sk_has_account()
1519 delta = size - sk->sk_forward_alloc; in sk_wmem_schedule()
1530 delta = size - sk->sk_forward_alloc; in sk_rmem_schedule()
1539 if (likely(!sk->sk_reserved_mem)) in sk_unused_reserved_mem()
1542 unused_mem = sk->sk_reserved_mem - sk->sk_wmem_queued - in sk_unused_reserved_mem()
1543 atomic_read(&sk->sk_rmem_alloc); in sk_unused_reserved_mem()
1555 reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk); in sk_mem_reclaim()
1563 sk->sk_reserved_mem = 0; in sk_mem_reclaim_final()
1571 sk_forward_alloc_add(sk, -size); in sk_mem_charge()
1587 * per-address-family lock class.
1591 sk->sk_lock.owned = 0; \
1592 init_waitqueue_head(&sk->sk_lock.wq); \
1593 spin_lock_init(&(sk)->sk_lock.slock); \
1594 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1595 sizeof((sk)->sk_lock)); \
1596 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1598 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1603 return lockdep_is_held(&sk->sk_lock) || in lockdep_sock_is_held()
1604 lockdep_is_held(&sk->sk_lock.slock); in lockdep_sock_is_held()
1619 #define bh_lock_sock(__sk) spin_lock(&((__sk)->sk_lock.slock))
1621 spin_lock_nested(&((__sk)->sk_lock.slock), \
1623 #define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock))
1625 bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock);
1628 * lock_sock_fast - fast version of lock_sock
1643 mutex_acquire(&sk->sk_lock.dep_map, 0, 0, _RET_IP_); in lock_sock_fast()
1651 mutex_acquire(&sk->sk_lock.dep_map, SINGLE_DEPTH_NESTING, 0, _RET_IP_); in lock_sock_fast_nested()
1657 * unlock_sock_fast - complement of lock_sock_fast
1665 __releases(&sk->sk_lock.slock) in unlock_sock_fast()
1669 __release(&sk->sk_lock.slock); in unlock_sock_fast()
1671 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in unlock_sock_fast()
1672 spin_unlock_bh(&sk->sk_lock.slock); in unlock_sock_fast()
1712 return sk->sk_lock.owned; in sock_owned_by_user()
1717 return sk->sk_lock.owned; in sock_owned_by_user_nocheck()
1723 sk->sk_lock.owned = 0; in sock_release_ownership()
1726 mutex_release(&sk->sk_lock.dep_map, _RET_IP_); in sock_release_ownership()
1735 !spin_is_locked(&sk->sk_lock.slock); in sock_allow_reclassification()
1792 if (sk->sk_socket) in sock_replace_proto()
1793 clear_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); in sock_replace_proto()
1794 WRITE_ONCE(sk->sk_prot, proto); in sock_replace_proto()
1807 .tsflags = READ_ONCE(sk->sk_tsflags) in sockcm_init()
1870 * it is called, socket has no references from outside -> sk_free
1887 if (refcount_dec_and_test(&sk->sk_refcnt)) in sock_put()
1905 /* sk_tx_queue_mapping accept only upto a 16-bit value */ in sk_tx_queue_set()
1911 WRITE_ONCE(sk->sk_tx_queue_mapping, tx_queue); in sk_tx_queue_set()
1921 WRITE_ONCE(sk->sk_tx_queue_mapping, NO_QUEUE_MAPPING); in sk_tx_queue_clear()
1930 int val = READ_ONCE(sk->sk_tx_queue_mapping); in sk_tx_queue_get()
1935 return -1; in sk_tx_queue_get()
1947 unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) in __sk_rx_queue_set()
1948 WRITE_ONCE(sk->sk_rx_queue_mapping, rx_queue); in __sk_rx_queue_set()
1966 WRITE_ONCE(sk->sk_rx_queue_mapping, NO_QUEUE_MAPPING); in sk_rx_queue_clear()
1974 int res = READ_ONCE(sk->sk_rx_queue_mapping); in sk_rx_queue_get()
1981 return -1; in sk_rx_queue_get()
1986 sk->sk_socket = sock; in sk_set_socket()
1992 return &rcu_dereference_raw(sk->sk_wq)->wait; in sk_sleep()
2003 write_lock_bh(&sk->sk_callback_lock); in sock_orphan()
2006 sk->sk_wq = NULL; in sock_orphan()
2007 write_unlock_bh(&sk->sk_callback_lock); in sock_orphan()
2012 WARN_ON(parent->sk); in sock_graft()
2013 write_lock_bh(&sk->sk_callback_lock); in sock_graft()
2014 rcu_assign_pointer(sk->sk_wq, &parent->wq); in sock_graft()
2015 parent->sk = sk; in sock_graft()
2017 sk->sk_uid = SOCK_INODE(parent)->i_uid; in sock_graft()
2019 write_unlock_bh(&sk->sk_callback_lock); in sock_graft()
2028 return sk ? sk->sk_uid : make_kuid(net->user_ns, 0); in sock_net_uid()
2041 WRITE_ONCE(sk->sk_txhash, net_tx_rndhash()); in sk_set_txhash()
2046 if (sk->sk_txhash && sk->sk_txrehash == SOCK_TXREHASH_ENABLED) { in sk_rethink_txhash()
2056 return rcu_dereference_check(sk->sk_dst_cache, in __sk_dst_get()
2066 dst = rcu_dereference(sk->sk_dst_cache); in sk_dst_get()
2067 if (dst && !rcuref_get(&dst->__rcuref)) in sk_dst_get()
2077 if (dst && dst->ops->negative_advice) in __dst_negative_advice()
2078 dst->ops->negative_advice(sk, dst); in __dst_negative_advice()
2093 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in __sk_dst_set()
2094 old_dst = rcu_dereference_protected(sk->sk_dst_cache, in __sk_dst_set()
2096 rcu_assign_pointer(sk->sk_dst_cache, dst); in __sk_dst_set()
2106 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sk_dst_set()
2107 old_dst = unrcu_pointer(xchg(&sk->sk_dst_cache, RCU_INITIALIZER(dst))); in sk_dst_set()
2129 if (!READ_ONCE(sk->sk_dst_pending_confirm)) in sk_dst_confirm()
2130 WRITE_ONCE(sk->sk_dst_pending_confirm, 1); in sk_dst_confirm()
2136 struct sock *sk = skb->sk; in sock_confirm_neigh()
2138 if (sk && READ_ONCE(sk->sk_dst_pending_confirm)) in sock_confirm_neigh()
2139 WRITE_ONCE(sk->sk_dst_pending_confirm, 0); in sock_confirm_neigh()
2148 return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); in sk_can_gso()
2155 sk->sk_gso_disabled = 1; in sk_gso_disable()
2156 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; in sk_gso_disable()
2163 if (skb->ip_summed == CHECKSUM_NONE) { in skb_do_copy_data_nocache()
2166 return -EFAULT; in skb_do_copy_data_nocache()
2167 skb->csum = csum_block_add(skb->csum, csum, offset); in skb_do_copy_data_nocache()
2168 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { in skb_do_copy_data_nocache()
2170 return -EFAULT; in skb_do_copy_data_nocache()
2172 return -EFAULT; in skb_do_copy_data_nocache()
2180 int err, offset = skb->len; in skb_add_data_nocache()
2198 copy, skb->len); in skb_copy_to_page_nocache()
2209 * sk_wmem_alloc_get - returns write allocations
2216 return refcount_read(&sk->sk_wmem_alloc) - 1; in sk_wmem_alloc_get()
2220 * sk_rmem_alloc_get - returns read allocations
2227 return atomic_read(&sk->sk_rmem_alloc); in sk_rmem_alloc_get()
2231 * sk_has_allocations - check if allocations are outstanding
2242 * skwq_has_sleeper - check if there are any waiting processes
2255 * __add_wait_queue update tp->rcv_nxt
2257 * tp->rcv_nxt check sock_def_readable
2260 * wq = rcu_dereference(sk->sk_wq);
2261 * if (wq && waitqueue_active(&wq->wait))
2262 * wake_up_interruptible(&wq->wait)
2267 * in its cache, and so does the tp->rcv_nxt update on CPU2 side. The CPU1
2274 return wq && wq_has_sleeper(&wq->wait); in skwq_has_sleeper()
2278 * sock_poll_wait - place memory barrier behind the poll_wait call.
2289 poll_wait(filp, &sock->wq.wait, p); in sock_poll_wait()
2302 u32 txhash = READ_ONCE(sk->sk_txhash); in skb_set_hash_from_sk()
2305 skb->l4_hash = 1; in skb_set_hash_from_sk()
2306 skb->hash = txhash; in skb_set_hash_from_sk()
2323 skb->sk = sk; in skb_set_owner_r()
2324 skb->destructor = sock_rfree; in skb_set_owner_r()
2325 atomic_add(skb->truesize, &sk->sk_rmem_alloc); in skb_set_owner_r()
2326 sk_mem_charge(sk, skb->truesize); in skb_set_owner_r()
2331 if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { in skb_set_owner_sk_safe()
2333 skb->destructor = sock_efree; in skb_set_owner_sk_safe()
2334 skb->sk = sk; in skb_set_owner_sk_safe()
2344 if (sk_rmem_schedule(sk, skb, skb->truesize)) { in skb_clone_and_charge_r()
2355 if (skb->destructor != sock_wfree) { in skb_prepare_for_gro()
2359 skb->slow_gro = 1; in skb_prepare_for_gro()
2397 if (likely(data_race(!sk->sk_err))) in sock_error()
2400 err = xchg(&sk->sk_err, 0); in sock_error()
2401 return -err; in sock_error()
2410 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in sock_wspace()
2411 amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc); in sock_wspace()
2419 * We use sk->sk_wq_raw, from contexts knowing this
2428 set_bit(nr, &sk->sk_wq_raw->flags); in sk_set_bit()
2437 clear_bit(nr, &sk->sk_wq_raw->flags); in sk_clear_bit()
2444 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async()
2452 sock_wake_async(rcu_dereference(sk->sk_wq), how, band); in sk_wake_async_rcu()
2455 /* Since sk_{r,w}mem_alloc sums skb->truesize, even a small frame might
2469 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) in sk_stream_moderate_sndbuf()
2472 val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); in sk_stream_moderate_sndbuf()
2475 WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF)); in sk_stream_moderate_sndbuf()
2479 * sk_page_frag - return an appropriate page_frag
2496 if (sk->sk_use_task_frag) in sk_page_frag()
2497 return ¤t->task_frag; in sk_page_frag()
2499 return &sk->sk_frag; in sk_page_frag()
2509 return refcount_read(&sk->sk_wmem_alloc) < (READ_ONCE(sk->sk_sndbuf) >> 1); in sock_writeable()
2524 return noblock ? 0 : sk->sk_rcvtimeo; in sock_rcvtimeo()
2529 return noblock ? 0 : sk->sk_sndtimeo; in sock_sndtimeo()
2534 int v = waitall ? len : min_t(int, READ_ONCE(sk->sk_rcvlowat), len); in sock_rcvlowat()
2544 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; in sock_intr_errno()
2551 /* Store sock_skb_cb at the end of skb->cb[] so protocol families
2552 * using skb->cb[] would keep using it directly and utilize its
2555 #define SOCK_SKB_CB_OFFSET ((sizeof_field(struct sk_buff, cb) - \
2558 #define SOCK_SKB_CB(__skb) ((struct sock_skb_cb *)((__skb)->cb + \
2567 SOCK_SKB_CB(skb)->dropcount = sock_flag(sk, SOCK_RXQ_OVFL) ? in sock_skb_set_dropcount()
2568 atomic_read(&sk->sk_drops) : 0; in sock_skb_set_dropcount()
2573 int segs = max_t(u16, 1, skb_shinfo(skb)->gso_segs); in sk_drops_add()
2575 atomic_add(segs, &sk->sk_drops); in sk_drops_add()
2585 seq = read_seqbegin(&sk->sk_stamp_seq); in sock_read_timestamp()
2586 kt = sk->sk_stamp; in sock_read_timestamp()
2587 } while (read_seqretry(&sk->sk_stamp_seq, seq)); in sock_read_timestamp()
2591 return READ_ONCE(sk->sk_stamp); in sock_read_timestamp()
2598 write_seqlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2599 sk->sk_stamp = kt; in sock_write_timestamp()
2600 write_sequnlock(&sk->sk_stamp_seq); in sock_write_timestamp()
2602 WRITE_ONCE(sk->sk_stamp, kt); in sock_write_timestamp()
2615 u32 tsflags = READ_ONCE(sk->sk_tsflags); in sock_recv_timestamp()
2616 ktime_t kt = skb->tstamp; in sock_recv_timestamp()
2619 * - receive time stamping in software requested in sock_recv_timestamp()
2620 * - software time stamp available and wanted in sock_recv_timestamp()
2621 * - hardware time stamps available and wanted in sock_recv_timestamp()
2626 (hwtstamps->hwtstamp && in sock_recv_timestamp()
2639 #define SK_DEFAULT_STAMP (-1L * NSEC_PER_SEC)
2649 if (sk->sk_flags & FLAGS_RECV_CMSGS || in sock_recv_cmsgs()
2650 READ_ONCE(sk->sk_tsflags) & TSFLAGS_ANY) in sock_recv_cmsgs()
2653 sock_write_timestamp(sk, skb->tstamp); in sock_recv_cmsgs()
2661 * _sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
2676 *tskey = atomic_inc_return(&sk->sk_tskey) - 1; in _sock_tx_timestamp()
2690 _sock_tx_timestamp(skb->sk, tsflags, &skb_shinfo(skb)->tx_flags, in skb_setup_tx_timestamp()
2691 &skb_shinfo(skb)->tskey); in skb_setup_tx_timestamp()
2696 int family = READ_ONCE(sk->sk_family); in sk_is_inet()
2704 sk->sk_type == SOCK_STREAM && in sk_is_tcp()
2705 sk->sk_protocol == IPPROTO_TCP; in sk_is_tcp()
2711 sk->sk_type == SOCK_DGRAM && in sk_is_udp()
2712 sk->sk_protocol == IPPROTO_UDP; in sk_is_udp()
2717 return sk->sk_family == AF_UNIX && sk->sk_type == SOCK_STREAM; in sk_is_stream_unix()
2722 return sk->sk_family == AF_VSOCK; in sk_is_vsock()
2726 * sk_eat_skb - Release a skb if it is no longer needed
2735 __skb_unlink(skb, &sk->sk_receive_queue); in sk_eat_skb()
2743 return skb->destructor == sock_pfree; in skb_sk_is_prefetched()
2754 return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); in sk_fullsock()
2760 /* Only full sockets have sk->sk_flags. */ in sk_is_refcounted()
2772 struct sock *sk = skb->sk; in sk_validate_xmit_skb()
2774 if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) { in sk_validate_xmit_skb()
2775 skb = sk->sk_validate_xmit_skb(sk, dev, skb); in sk_validate_xmit_skb()
2777 pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n"); in sk_validate_xmit_skb()
2791 return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); in sk_listener()
2806 * determination of these values, since that is non-constant across
2829 if (proto->sysctl_wmem_offset) in sk_get_wmem0()
2830 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_wmem_offset)); in sk_get_wmem0()
2832 return READ_ONCE(*proto->sysctl_wmem); in sk_get_wmem0()
2838 if (proto->sysctl_rmem_offset) in sk_get_rmem0()
2839 return READ_ONCE(*(int *)((void *)sock_net(sk) + proto->sysctl_rmem_offset)); in sk_get_rmem0()
2841 return READ_ONCE(*proto->sysctl_rmem); in sk_get_rmem0()
2850 if (!sk || !sk_fullsock(sk) || READ_ONCE(sk->sk_pacing_shift) == val) in sk_pacing_shift_update()
2852 WRITE_ONCE(sk->sk_pacing_shift, val); in sk_pacing_shift_update()
2862 int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); in sk_dev_equal_l3scope()
2903 if (sk->sk_prot->sock_is_readable) in sk_is_readable()
2904 return sk->sk_prot->sock_is_readable(sk); in sk_is_readable()