bpf: Add mark and priority to sock options that can be set
authorDavid Ahern <dsahern@gmail.com>
Thu, 31 Aug 2017 22:05:44 +0000 (15:05 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Sep 2017 05:05:15 +0000 (06:05 +0100)
Add socket mark and priority to fields that can be set by
ebpf program when a socket is created.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/bpf.h
net/core/filter.c

index 08c206a863e11d036e1cbf1e8c9af2dfaf18493e..ba848b761cfbf6e90f612e3d9a42c55d657f0ec0 100644 (file)
@@ -758,6 +758,8 @@ struct bpf_sock {
        __u32 family;
        __u32 type;
        __u32 protocol;
+       __u32 mark;
+       __u32 priority;
 };
 
 #define XDP_PACKET_HEADROOM 256
index c6a37fe0285b1615bea277472207e8c55ef885f0..f51b9690adf3e81c0191e23fd4329dc3df9142bb 100644 (file)
@@ -3455,6 +3455,10 @@ static bool sock_filter_is_valid_access(int off, int size,
                switch (off) {
                case offsetof(struct bpf_sock, bound_dev_if):
                        break;
+               case offsetof(struct bpf_sock, mark):
+                       break;
+               case offsetof(struct bpf_sock, priority):
+                       break;
                default:
                        return false;
                }
@@ -3958,6 +3962,28 @@ static u32 sock_filter_convert_ctx_access(enum bpf_access_type type,
                                      offsetof(struct sock, sk_bound_dev_if));
                break;
 
+       case offsetof(struct bpf_sock, mark):
+               BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_mark) != 4);
+
+               if (type == BPF_WRITE)
+                       *insn++ = BPF_STX_MEM(BPF_W, si->dst_reg, si->src_reg,
+                                       offsetof(struct sock, sk_mark));
+               else
+                       *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
+                                     offsetof(struct sock, sk_mark));
+               break;
+
+       case offsetof(struct bpf_sock, priority):
+               BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_priority) != 4);
+
+               if (type == BPF_WRITE)
+                       *insn++ = BPF_STX_MEM(BPF_W, si->dst_reg, si->src_reg,
+                                       offsetof(struct sock, sk_priority));
+               else
+                       *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
+                                     offsetof(struct sock, sk_priority));
+               break;
+
        case offsetof(struct bpf_sock, family):
                BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_family) != 2);