From patchwork Wed Aug 28 07:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 1154258 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=cloudflare.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=cloudflare.com header.i=@cloudflare.com header.b="CY34KRJQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46JHJz1jc9z9sNF for ; Wed, 28 Aug 2019 17:23:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726395AbfH1HXO (ORCPT ); Wed, 28 Aug 2019 03:23:14 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40067 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726583AbfH1HXN (ORCPT ); Wed, 28 Aug 2019 03:23:13 -0400 Received: by mail-lf1-f68.google.com with SMTP id u29so1230193lfk.7 for ; Wed, 28 Aug 2019 00:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xgrCk7yvwW4trCdUCW/zs7DHG7RiYoZiMv11DkUjyPY=; b=CY34KRJQleGuq9nuA1YAqUn8YS3HTbEn1q0twwhIGS9StLWMQAlJxzcVct2vWV3XI6 GoFCz4YLy9TD8HxLRQ9ponUSE746YtDLvfsQ4QzpSoa91rGgTtT3qGGX8RQdb2IQdDZi 7d3vtPqxCBEWoEg8hK8r4N2ooxEYs62JesMy8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xgrCk7yvwW4trCdUCW/zs7DHG7RiYoZiMv11DkUjyPY=; b=CNRpjCG1eDhxj4VjPsBhgRGA3rG6v7GBbqDAzzptdSSeErqk1IPJ7DkwjpelcMRp8G UkQepKdceFvzY+ArsQGLb3iioIO9+oj/2WPxl4xqUYy9xebBx5udfjWX+7wl2TyMfZ23 Z9u1cN88nCUF+XlSTNp8RWbg2oxvi6JccoGl8TgmYZpRdNtoeEjZ0aG231KlIAReODTs IDYgqg60IKVTmmi1is7QjomMKlijETVgSh/zdFgiB/FiTmexrTGX2xd8QVIyJ2DxV18h Cvh/UWdJGYDzx7fVdZb5ZkfhxQqoMtHu5Q7OCUOiwujUQHhyxsUZtzklo3dJEMtw0UyB l4iw== X-Gm-Message-State: APjAAAW6tSuxcdSPbPuLH8EbxNTeTPx6EbdwQLW4ahEAWWgEgaE9CnZP bi72b6kjY4qd6OBwcN5y3BuzIYCOtg8Cvg== X-Google-Smtp-Source: APXvYqyBX2F/tdBVnKxaVnZMkDjWIB0d0VTIsmFxa//brkhx8eda4TM8CK9LaEGkmf2RxMZ+K1RyJQ== X-Received: by 2002:ac2:5637:: with SMTP id b23mr1729315lff.186.1566976991158; Wed, 28 Aug 2019 00:23:11 -0700 (PDT) Received: from cloudflare.com ([2a02:a310:c262:aa00:b35e:8938:2c2a:ba8b]) by smtp.gmail.com with ESMTPSA id j3sm593169lfp.34.2019.08.28.00.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 00:23:10 -0700 (PDT) From: Jakub Sitnicki To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: kernel-team@cloudflare.com, Lorenz Bauer , Marek Majkowski Subject: [RFCv2 bpf-next 10/12] bpf: Sync linux/bpf.h to tools/ Date: Wed, 28 Aug 2019 09:22:48 +0200 Message-Id: <20190828072250.29828-11-jakub@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190828072250.29828-1-jakub@cloudflare.com> References: <20190828072250.29828-1-jakub@cloudflare.com> MIME-Version: 1.0 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Newly added program, context type and helper is used by tests in a subsequent patch. Synchronize the header file. Reviewed-by: Lorenz Bauer Signed-off-by: Jakub Sitnicki --- 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 {