Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: remove SK_REDIRECT from UAPI

Now that SK_REDIRECT is no longer a valid return code. Remove it
from the UAPI completely. Then do a namespace remapping internal
to sockmap so SK_REDIRECT is no longer externally visible.

Patchs primary change is to do a namechange from SK_REDIRECT to
__SK_REDIRECT

Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

John Fastabend and committed by
David S. Miller
04686ef2 14fc0aba

+13 -7
-1
include/uapi/linux/bpf.h
··· 788 788 enum sk_action { 789 789 SK_DROP = 0, 790 790 SK_PASS, 791 - SK_REDIRECT, 792 791 }; 793 792 794 793 #define BPF_TAG_SIZE 8
+12 -4
kernel/bpf/sockmap.c
··· 101 101 TCP_SKB_CB(skb)->bpf.data_end = skb->data + skb_headlen(skb); 102 102 } 103 103 104 + enum __sk_action { 105 + __SK_DROP = 0, 106 + __SK_PASS, 107 + __SK_REDIRECT, 108 + }; 109 + 104 110 static int smap_verdict_func(struct smap_psock *psock, struct sk_buff *skb) 105 111 { 106 112 struct bpf_prog *prog = READ_ONCE(psock->bpf_verdict); 107 113 int rc; 108 114 109 115 if (unlikely(!prog)) 110 - return SK_DROP; 116 + return __SK_DROP; 111 117 112 118 skb_orphan(skb); 113 119 /* We need to ensure that BPF metadata for maps is also cleared ··· 128 122 preempt_enable(); 129 123 skb->sk = NULL; 130 124 125 + /* Moving return codes from UAPI namespace into internal namespace */ 131 126 return rc == SK_PASS ? 132 - (TCP_SKB_CB(skb)->bpf.map ? SK_REDIRECT : SK_PASS) : SK_DROP; 127 + (TCP_SKB_CB(skb)->bpf.map ? __SK_REDIRECT : __SK_PASS) : 128 + __SK_DROP; 133 129 } 134 130 135 131 static void smap_do_verdict(struct smap_psock *psock, struct sk_buff *skb) ··· 141 133 142 134 rc = smap_verdict_func(psock, skb); 143 135 switch (rc) { 144 - case SK_REDIRECT: 136 + case __SK_REDIRECT: 145 137 sk = do_sk_redirect_map(skb); 146 138 if (likely(sk)) { 147 139 struct smap_psock *peer = smap_psock_sk(sk); ··· 157 149 } 158 150 } 159 151 /* Fall through and free skb otherwise */ 160 - case SK_DROP: 152 + case __SK_DROP: 161 153 default: 162 154 kfree_skb(skb); 163 155 }
+1 -2
tools/include/uapi/linux/bpf.h
··· 576 576 * @map: pointer to sockmap 577 577 * @key: key to lookup sock in map 578 578 * @flags: reserved for future use 579 - * Return: SK_REDIRECT 579 + * Return: SK_PASS 580 580 * 581 581 * int bpf_sock_map_update(skops, map, key, flags) 582 582 * @skops: pointer to bpf_sock_ops ··· 789 789 enum sk_action { 790 790 SK_DROP = 0, 791 791 SK_PASS, 792 - SK_REDIRECT, 793 792 }; 794 793 795 794 #define BPF_TAG_SIZE 8