mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
synced 2026-04-17 22:23:45 -04:00
skmsg: Move sk_redir from TCP_SKB_CB to skb
Currently TCP_SKB_CB() is hard-coded in skmsg code, it certainly does not work for any other non-TCP protocols. We can move them to skb ext, but it introduces a memory allocation on fast path. Fortunately, we only need to a word-size to store all the information, because the flags actually only contains 1 bit so can be just packed into the lowest bit of the "pointer", which is stored as unsigned long. Inside struct sk_buff, '_skb_refdst' can be reused because skb dst is no longer needed after ->sk_data_ready() so we can just drop it. Signed-off-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Jakub Sitnicki <jakub@cloudflare.com> Link: https://lore.kernel.org/bpf/20210223184934.6054-5-xiyou.wangcong@gmail.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
16137b09a6
commit
e3526bb92a
@@ -455,4 +455,42 @@ static inline bool sk_psock_strp_enabled(struct sk_psock *psock)
|
||||
return false;
|
||||
return !!psock->saved_data_ready;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_NET_SOCK_MSG)
|
||||
|
||||
/* We only have one bit so far. */
|
||||
#define BPF_F_PTR_MASK ~(BPF_F_INGRESS)
|
||||
|
||||
static inline bool skb_bpf_ingress(const struct sk_buff *skb)
|
||||
{
|
||||
unsigned long sk_redir = skb->_sk_redir;
|
||||
|
||||
return sk_redir & BPF_F_INGRESS;
|
||||
}
|
||||
|
||||
static inline void skb_bpf_set_ingress(struct sk_buff *skb)
|
||||
{
|
||||
skb->_sk_redir |= BPF_F_INGRESS;
|
||||
}
|
||||
|
||||
static inline void skb_bpf_set_redir(struct sk_buff *skb, struct sock *sk_redir,
|
||||
bool ingress)
|
||||
{
|
||||
skb->_sk_redir = (unsigned long)sk_redir;
|
||||
if (ingress)
|
||||
skb->_sk_redir |= BPF_F_INGRESS;
|
||||
}
|
||||
|
||||
static inline struct sock *skb_bpf_redirect_fetch(const struct sk_buff *skb)
|
||||
{
|
||||
unsigned long sk_redir = skb->_sk_redir;
|
||||
|
||||
return (struct sock *)(sk_redir & BPF_F_PTR_MASK);
|
||||
}
|
||||
|
||||
static inline void skb_bpf_redirect_clear(struct sk_buff *skb)
|
||||
{
|
||||
skb->_sk_redir = 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_SOCK_MSG */
|
||||
#endif /* _LINUX_SKMSG_H */
|
||||
|
||||
Reference in New Issue
Block a user