Skip to content

Commit

Permalink
bpf: remove SK_REDIRECT from UAPI
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: John Fastabend <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jrfastab authored and davem330 committed Nov 1, 2017
1 parent 14fc0ab commit 04686ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ struct xdp_md {
enum sk_action {
SK_DROP = 0,
SK_PASS,
SK_REDIRECT,
};

#define BPF_TAG_SIZE 8
Expand Down
16 changes: 12 additions & 4 deletions kernel/bpf/sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,19 @@ static inline void bpf_compute_data_end_sk_skb(struct sk_buff *skb)
TCP_SKB_CB(skb)->bpf.data_end = skb->data + skb_headlen(skb);
}

enum __sk_action {
__SK_DROP = 0,
__SK_PASS,
__SK_REDIRECT,
};

static int smap_verdict_func(struct smap_psock *psock, struct sk_buff *skb)
{
struct bpf_prog *prog = READ_ONCE(psock->bpf_verdict);
int rc;

if (unlikely(!prog))
return SK_DROP;
return __SK_DROP;

skb_orphan(skb);
/* We need to ensure that BPF metadata for maps is also cleared
Expand All @@ -122,8 +128,10 @@ static int smap_verdict_func(struct smap_psock *psock, struct sk_buff *skb)
preempt_enable();
skb->sk = NULL;

/* Moving return codes from UAPI namespace into internal namespace */
return rc == SK_PASS ?
(TCP_SKB_CB(skb)->bpf.map ? SK_REDIRECT : SK_PASS) : SK_DROP;
(TCP_SKB_CB(skb)->bpf.map ? __SK_REDIRECT : __SK_PASS) :
__SK_DROP;
}

static void smap_do_verdict(struct smap_psock *psock, struct sk_buff *skb)
Expand All @@ -133,7 +141,7 @@ static void smap_do_verdict(struct smap_psock *psock, struct sk_buff *skb)

rc = smap_verdict_func(psock, skb);
switch (rc) {
case SK_REDIRECT:
case __SK_REDIRECT:
sk = do_sk_redirect_map(skb);
if (likely(sk)) {
struct smap_psock *peer = smap_psock_sk(sk);
Expand All @@ -149,7 +157,7 @@ static void smap_do_verdict(struct smap_psock *psock, struct sk_buff *skb)
}
}
/* Fall through and free skb otherwise */
case SK_DROP:
case __SK_DROP:
default:
kfree_skb(skb);
}
Expand Down
3 changes: 1 addition & 2 deletions tools/include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ union bpf_attr {
* @map: pointer to sockmap
* @key: key to lookup sock in map
* @flags: reserved for future use
* Return: SK_REDIRECT
* Return: SK_PASS
*
* int bpf_sock_map_update(skops, map, key, flags)
* @skops: pointer to bpf_sock_ops
Expand Down Expand Up @@ -789,7 +789,6 @@ struct xdp_md {
enum sk_action {
SK_DROP = 0,
SK_PASS,
SK_REDIRECT,
};

#define BPF_TAG_SIZE 8
Expand Down

0 comments on commit 04686ef

Please sign in to comment.