Newly added program, context type and helper is used by tests in a
subsequent patch. Synchronize the header file.

Reviewed-by: Lorenz Bauer <l...@cloudflare.com>
Signed-off-by: Jakub Sitnicki <ja...@cloudflare.com>
---
 tools/include/uapi/linux/bpf.h | 58 +++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index b5889257cc33..58ee3d24a430 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -173,6 +173,7 @@ enum bpf_prog_type {
        BPF_PROG_TYPE_CGROUP_SYSCTL,
        BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
        BPF_PROG_TYPE_CGROUP_SOCKOPT,
+       BPF_PROG_TYPE_INET_LOOKUP,
 };
 
 enum bpf_attach_type {
@@ -199,6 +200,7 @@ enum bpf_attach_type {
        BPF_CGROUP_UDP6_RECVMSG,
        BPF_CGROUP_GETSOCKOPT,
        BPF_CGROUP_SETSOCKOPT,
+       BPF_INET_LOOKUP,
        __MAX_BPF_ATTACH_TYPE
 };
 
@@ -2747,6 +2749,33 @@ union bpf_attr {
  *             **-EOPNOTSUPP** kernel configuration does not enable SYN cookies
  *
  *             **-EPROTONOSUPPORT** IP packet version is not 4 or 6
+ *
+ * int bpf_redirect_lookup(struct bpf_inet_lookup_kern *ctx, struct bpf_map 
*sockarray, void *key, u64 flags)
+ *     Description
+ *             Select a socket referenced by *map* (of type
+ *             **BPF_MAP_TYPE_REUSEPORT_SOCKARRAY**) at index *key* to use as a
+ *             result of listening (TCP) or bound (UDP) socket lookup.
+ *
+ *             The IP family and L4 protocol in *ctx* object, populated from
+ *             the packet that triggered the lookup, must match the selected
+ *             socket's family and protocol. IP6_V6ONLY socket option is
+ *             honored.
+ *
+ *             To be used by **BPF_INET_LOOKUP** programs attached to the
+ *             network namespace. Program needs to return **BPF_REDIRECT**, the
+ *             helper's success return value, for the selected socket to be
+ *             actually used.
+ *
+ *     Return
+ *             **BPF_REDIRECT** on success, if the socket at index *key* was 
selected.
+ *
+ *             **-EINVAL** if *flags* are invalid (not zero).
+ *
+ *             **-ENOENT** if there is no socket at index *key*.
+ *
+ *             **-EPROTOTYPE** if *ctx->protocol* does not match the socket 
protocol.
+ *
+ *             **-EAFNOSUPPORT** if socket does not accept IP version in 
*ctx->family*.
  */
 #define __BPF_FUNC_MAPPER(FN)          \
        FN(unspec),                     \
@@ -2859,7 +2888,8 @@ union bpf_attr {
        FN(sk_storage_get),             \
        FN(sk_storage_delete),          \
        FN(send_signal),                \
-       FN(tcp_gen_syncookie),
+       FN(tcp_gen_syncookie),          \
+       FN(redirect_lookup),
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  * function eBPF program intends to call
@@ -3116,6 +3146,32 @@ struct bpf_tcp_sock {
        __u32 icsk_retransmits; /* Number of unrecovered [RTO] timeouts */
 };
 
+/* User accessible data for inet_lookup programs.
+ * New fields must be added at the end.
+ */
+struct bpf_inet_lookup {
+       __u32 family;           /* AF_INET, AF_INET6 */
+       __u32 protocol;         /* IPROTO_TCP, IPPROTO_UDP */
+       __u32 remote_ip4;       /* Allows 1,2,4-byte read but no write.
+                                * Stored in network byte order.
+                                */
+       __u32 local_ip4;        /* Allows 1,2,4-byte read and 4-byte write.
+                                * Stored in network byte order.
+                                */
+       __u32 remote_ip6[4];    /* Allows 1,2,4-byte read but no write.
+                                * Stored in network byte order.
+                                */
+       __u32 local_ip6[4];     /* Allows 1,2,4-byte read and 4-byte write.
+                                * Stored in network byte order.
+                                */
+       __u32 remote_port;      /* Allows 4-byte read but no write.
+                                * Stored in network byte order.
+                                */
+       __u32 local_port;       /* Allows 4-byte read and write.
+                                * Stored in host byte order.
+                                */
+};
+
 struct bpf_sock_tuple {
        union {
                struct {
-- 
2.20.1

Reply via email to