Skip to content

Commit 482dca9

Browse files
dsaherndavem330
authored andcommitted
bpf: Add mark and priority to sock options that can be set
Add socket mark and priority to fields that can be set by ebpf program when a socket is created. Signed-off-by: David Ahern <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e12f1a5 commit 482dca9

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ struct bpf_sock {
758758
__u32 family;
759759
__u32 type;
760760
__u32 protocol;
761+
__u32 mark;
762+
__u32 priority;
761763
};
762764

763765
#define XDP_PACKET_HEADROOM 256

net/core/filter.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,10 @@ static bool sock_filter_is_valid_access(int off, int size,
34553455
switch (off) {
34563456
case offsetof(struct bpf_sock, bound_dev_if):
34573457
break;
3458+
case offsetof(struct bpf_sock, mark):
3459+
break;
3460+
case offsetof(struct bpf_sock, priority):
3461+
break;
34583462
default:
34593463
return false;
34603464
}
@@ -3958,6 +3962,28 @@ static u32 sock_filter_convert_ctx_access(enum bpf_access_type type,
39583962
offsetof(struct sock, sk_bound_dev_if));
39593963
break;
39603964

3965+
case offsetof(struct bpf_sock, mark):
3966+
BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_mark) != 4);
3967+
3968+
if (type == BPF_WRITE)
3969+
*insn++ = BPF_STX_MEM(BPF_W, si->dst_reg, si->src_reg,
3970+
offsetof(struct sock, sk_mark));
3971+
else
3972+
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
3973+
offsetof(struct sock, sk_mark));
3974+
break;
3975+
3976+
case offsetof(struct bpf_sock, priority):
3977+
BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_priority) != 4);
3978+
3979+
if (type == BPF_WRITE)
3980+
*insn++ = BPF_STX_MEM(BPF_W, si->dst_reg, si->src_reg,
3981+
offsetof(struct sock, sk_priority));
3982+
else
3983+
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
3984+
offsetof(struct sock, sk_priority));
3985+
break;
3986+
39613987
case offsetof(struct bpf_sock, family):
39623988
BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_family) != 2);
39633989

0 commit comments

Comments
 (0)