[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171110191709.13051-1-vlad@dumitrescu.ro>
Date: Fri, 10 Nov 2017 11:17:09 -0800
From: Vlad Dumitrescu <vlad@...itrescu.ro>
To: davem@...emloft.net, ast@...com, daniel@...earbox.net,
brakmo@...com
Cc: netdev@...r.kernel.org, kraigatgoog@...il.com
Subject: [PATCH net-next] bpf: expose sk_priority through struct bpf_sock_ops
From: Vlad Dumitrescu <vladum@...gle.com>
Allows BPF_PROG_TYPE_SOCK_OPS programs to read sk_priority.
Signed-off-by: Vlad Dumitrescu <vladum@...gle.com>
---
include/uapi/linux/bpf.h | 1 +
net/core/filter.c | 11 +++++++++++
tools/include/uapi/linux/bpf.h | 1 +
3 files changed, 13 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e880ae6434ee..9757a2002513 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -947,6 +947,7 @@ struct bpf_sock_ops {
__u32 local_ip6[4]; /* Stored in network byte order */
__u32 remote_port; /* Stored in network byte order */
__u32 local_port; /* stored in host byte order */
+ __u32 priority;
};
/* List of known BPF sock_ops operators.
diff --git a/net/core/filter.c b/net/core/filter.c
index 61c791f9f628..a6329642d047 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4449,6 +4449,17 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,
*insn++ = BPF_LDX_MEM(BPF_H, si->dst_reg, si->dst_reg,
offsetof(struct sock_common, skc_num));
break;
+
+ case offsetof(struct bpf_sock_ops, priority):
+ BUILD_BUG_ON(FIELD_SIZEOF(struct sock, sk_priority) != 4);
+
+ *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(
+ struct bpf_sock_ops_kern, sk),
+ si->dst_reg, si->src_reg,
+ offsetof(struct bpf_sock_ops_kern, sk));
+ *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
+ offsetof(struct sock, sk_priority));
+ break;
}
return insn - insn_buf;
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e880ae6434ee..9757a2002513 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -947,6 +947,7 @@ struct bpf_sock_ops {
__u32 local_ip6[4]; /* Stored in network byte order */
__u32 remote_port; /* Stored in network byte order */
__u32 local_port; /* stored in host byte order */
+ __u32 priority;
};
/* List of known BPF sock_ops operators.
--
2.15.0.448.gf294e3d99a-goog
Powered by blists - more mailing lists