From patchwork Tue Oct 31 10:32:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 832324 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yR73P0mLRz9sRg for ; Tue, 31 Oct 2017 21:33:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753517AbdJaKcz (ORCPT ); Tue, 31 Oct 2017 06:32:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44984 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753391AbdJaKcb (ORCPT ); Tue, 31 Oct 2017 06:32:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0FD012B9; Tue, 31 Oct 2017 10:32:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0FD012B9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jasowang@redhat.com Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-23.pek2.redhat.com [10.72.12.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id B08B3600D1; Tue, 31 Oct 2017 10:32:28 +0000 (UTC) From: Jason Wang To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mst@redhat.com, willemdebruijn.kernel@gmail.com, tom@herbertland.com, Jason Wang Subject: [PATCH net-next V2 2/3] tun: introduce ioctls to set and get steering policies Date: Tue, 31 Oct 2017 18:32:17 +0800 Message-Id: <1509445938-4345-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1509445938-4345-1-git-send-email-jasowang@redhat.com> References: <1509445938-4345-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 31 Oct 2017 10:32:31 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introduces new ioctl for change packet steering policy for tun. Only automatic flow steering is supported, more policies will come. Signed-off-by: Jason Wang --- drivers/net/tun.c | 35 ++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 7 +++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index bff6259..ab109ff 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -122,7 +122,8 @@ do { \ #define TUN_VNET_BE 0x40000000 #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \ - IFF_MULTI_QUEUE | IFF_NAPI | IFF_NAPI_FRAGS) + IFF_MULTI_QUEUE | IFF_NAPI | IFF_NAPI_FRAGS | \ + IFF_MULTI_STEERING) #define GOODCOPY_LEN 128 @@ -2516,6 +2517,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, unsigned int ifindex; int le; int ret; + unsigned int steering; if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == SOCK_IOC_TYPE) { if (copy_from_user(&ifr, argp, ifreq_len)) @@ -2774,6 +2776,37 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = 0; break; + case TUNSETSTEERING: + ret = -EFAULT; + if (copy_from_user(&steering, argp, sizeof(steering))) + break; + ret = 0; + switch (steering) { + case TUN_STEERING_AUTOMQ: + tun->steering_ops = &tun_automq_ops; + break; + default: + ret = -EFAULT; + } + break; + + case TUNGETSTEERING: + ret = 0; + if (tun->steering_ops == &tun_automq_ops) + steering = TUN_STEERING_AUTOMQ; + else + BUG(); + if (copy_to_user(argp, &steering, sizeof(steering))) + ret = -EFAULT; + break; + + case TUNGETSTEERINGFEATURES: + ret = 0; + steering = TUN_STEERING_AUTOMQ; + if (copy_to_user(argp, &steering, sizeof(steering))) + ret = -EFAULT; + break; + default: ret = -EINVAL; break; diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 365ade5..109760e 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -56,6 +56,9 @@ */ #define TUNSETVNETBE _IOW('T', 222, int) #define TUNGETVNETBE _IOR('T', 223, int) +#define TUNSETSTEERING _IOW('T', 224, unsigned int) +#define TUNGETSTEERING _IOR('T', 225, unsigned int) +#define TUNGETSTEERINGFEATURES _IOR('T', 226, unsigned int) /* TUNSETIFF ifr flags */ #define IFF_TUN 0x0001 @@ -70,6 +73,8 @@ #define IFF_MULTI_QUEUE 0x0100 #define IFF_ATTACH_QUEUE 0x0200 #define IFF_DETACH_QUEUE 0x0400 +#define IFF_MULTI_STEERING 0x2000 + /* read-only flag */ #define IFF_PERSIST 0x0800 #define IFF_NOFILTER 0x1000 @@ -106,4 +111,6 @@ struct tun_filter { __u8 addr[0][ETH_ALEN]; }; +#define TUN_STEERING_AUTOMQ 0x01 /* Automatic flow steering */ + #endif /* _UAPI__IF_TUN_H */