Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp59163pxu; Tue, 5 Jan 2021 05:14:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmiBTb510QHayvja81vmP8/y3bDuqGU3Cm3VLP+KkWEg6WAMvv0k5fW8Bw57IzvDr5M++Q X-Received: by 2002:a17:906:dc1:: with SMTP id p1mr71872701eji.9.1609852490398; Tue, 05 Jan 2021 05:14:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609852490; cv=none; d=google.com; s=arc-20160816; b=OHbEDGMnWeHVGdStIAuwofYTBbnqN0jcteGVVHSXH1TUCXNkDWQnRyV9KljhT1jyIm zGKRiMz7f980sMANu0YR0zZM7vu46KRT841/qDeZ4YpkFtILeF7VF0DMNgWhu1HrSC3/ OKtUb6ofeRQrvdbfYZQte1IryNAZ5DKFbX+avLXlfyTFXMTPwcF5HewGuCh317y9igCB DHSmpjF6eT+XnB58nzeVDHGjhLA+ALNlGc9VjnXsHBTfOAZbJPi+CcjxCiMpjJsUnafu gz9g8bR4TgdF5OofvP9/JD77J+FjRWgxvqI5l7gET3GjthpAQZGtlCYmXhdw0RUx0buC GKOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=ZIRhmzhJTza1eg/duDC8aSWDJ8wELCNq6nzGwLtOGgE=; b=nWqWVaCrUXPXAgshqCoNucyfghrDhUwBuNUaDeuqRdFj9qZWE7nBeIjr3pZUY0bFC3 48bM/wQ/6VuDluf1wchZXn6s3mbMGgBbW3Y3eAAz90q3VOVWQvpRClMSDWFvdxACYGcq iooeBv0p2FQuniTkqwYm7pjjH0UaR9/fYQVCj4fRB2ai6jMQKYVB6zMWBMVr6M65rT1a yq09DJ+ArfN5XxkfMlVrebe+85GRlb3LkAv/6GsoDgPjvLrpjz9I9cYKNS0L8eBwslq8 ifPeuWEamOz3Ipm3yAVORlCAy/WoPuQzaEw1tfVEsSjCjTkgWlSXcr1ABFyJ4IDB0C6e TDXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20150623.gappssmtp.com header.s=20150623 header.b=oM7Uaab4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay21si33321406edb.575.2021.01.05.05.14.27; Tue, 05 Jan 2021 05:14:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@daynix-com.20150623.gappssmtp.com header.s=20150623 header.b=oM7Uaab4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729135AbhAEMZ6 (ORCPT + 99 others); Tue, 5 Jan 2021 07:25:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728874AbhAEMZz (ORCPT ); Tue, 5 Jan 2021 07:25:55 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF82C0617A9 for ; Tue, 5 Jan 2021 04:24:37 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id v14so2859113wml.1 for ; Tue, 05 Jan 2021 04:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZIRhmzhJTza1eg/duDC8aSWDJ8wELCNq6nzGwLtOGgE=; b=oM7Uaab4ruWgkghbIDEOJNIaXwqhUApJ0Q1qI8YZ7j2FgLmvh+kbEF87EClI/IK6yY yzjECu0tIzEYKTcKptZaeGef9Tu2KzA64wGHRRhZc93RzR6IxBp0KTOxPJULx4GwghGG sWD+qdT2OHiG+Pk/wZ5gUJYyoOtL2PuW+nTQwoxHRhhI3wHRR98wd0bb9UrUoZ74qBI5 xoOzlWrzQxH6A1m8YE/qrHaW/WAzS5sUozTF1XzxT0BhELThcof6y2efIbU3iq6/RycR qnpBb8vk3foVmiig+dknBebuqWRau1IWgxnJfww81uTk7HSLNbG9Q68be0v5UZAIJQ3+ 8SfA== 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; bh=ZIRhmzhJTza1eg/duDC8aSWDJ8wELCNq6nzGwLtOGgE=; b=XOQVMLwXTuoZZsrpYlzLu1jK5cImpcQQa+ZdKjOMrkNff693aTtUHjYxUEjIEsaIMm xiO9eWT/vqZO0Zr0ylWijxeKyR+cZDBCJp7wpy1U6rKmC3iEWHKfhJ1gINa1ygjFU7t4 PbtusM7qvqfliZ5jOo64elRW14ZD7JjhYIlYpsaK6LXCe5ZNp3u8ks2Hre1Sau9zooxX lwViADEt65yya9p98Z4PvUPwE2FcOR2npM6gBwPZSYCXsM/PqTfVniw8eD1G9ED1J4/i 8quStXSKxMrzv0jUzIFrCUt0Rbh+OJBk2VWzDh5rXcjBd8dntar6rKuderzfiQQpwVK/ ASQQ== X-Gm-Message-State: AOAM532Wym8pwJZd026VFoRxxnGfiGTB5hrNWkkAwj/2cpyPU+ErsEtz e/VpLSyc3moUyDlNpV7aZh4hQw== X-Received: by 2002:a1c:2288:: with SMTP id i130mr3350183wmi.78.1609849476766; Tue, 05 Jan 2021 04:24:36 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id 138sm4242281wma.41.2021.01.05.04.24.34 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jan 2021 04:24:36 -0800 (PST) From: Yuri Benditovich To: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Cc: yan@daynix.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [RFC PATCH 5/7] tun: add ioctl code TUNSETHASHPOPULATION Date: Tue, 5 Jan 2021 14:24:14 +0200 Message-Id: <20210105122416.16492-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210105122416.16492-1-yuri.benditovich@daynix.com> References: <20210105122416.16492-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org User mode program calls this ioctl before loading of BPF program to inform the tun that the BPF program has extended functionality, i.e. sets hash value and returns the virtqueue number in the lower 16 bits and the type of the hash report in the upper 16 bits. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 12 +++++++++++- include/uapi/linux/if_tun.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 18c1baf1a6c1..45f4f04a4a3e 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -197,6 +197,7 @@ struct tun_struct { struct sock_fprog fprog; /* protected by rtnl lock */ bool filter_attached; + bool bpf_populates_hash; u32 msg_enable; spinlock_t lock; struct hlist_head flows[TUN_NUM_FLOW_ENTRIES]; @@ -2765,6 +2766,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) tun->align = NET_SKB_PAD; tun->filter_attached = false; + tun->bpf_populates_hash = false; tun->sndbuf = tfile->socket.sk->sk_sndbuf; tun->rx_batched = 0; RCU_INIT_POINTER(tun->steering_prog, NULL); @@ -2997,7 +2999,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, struct net *net = sock_net(&tfile->sk); struct tun_struct *tun; void __user* argp = (void __user*)arg; - unsigned int ifindex, carrier; + unsigned int ifindex, carrier, populate_hash; struct ifreq ifr; kuid_t owner; kgid_t group; @@ -3298,6 +3300,14 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = open_related_ns(&net->ns, get_net_ns); break; + case TUNSETHASHPOPULATION: + ret = -EFAULT; + if (copy_from_user(&populate_hash, argp, sizeof(populate_hash))) + goto unlock; + tun->bpf_populates_hash = !!populate_hash; + ret = 0; + break; + default: ret = -EINVAL; break; diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 454ae31b93c7..0fd43533da26 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -61,6 +61,7 @@ #define TUNSETFILTEREBPF _IOR('T', 225, int) #define TUNSETCARRIER _IOW('T', 226, int) #define TUNGETDEVNETNS _IO('T', 227) +#define TUNSETHASHPOPULATION _IOR('T', 228, int) /* TUNSETIFF ifr flags */ #define IFF_TUN 0x0001 -- 2.17.1