From patchwork Tue Nov 30 08:00:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 73581 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EC8951007D1 for ; Tue, 30 Nov 2010 19:00:37 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754235Ab0K3IAd (ORCPT ); Tue, 30 Nov 2010 03:00:33 -0500 Received: from smtp-out.google.com ([216.239.44.51]:1889 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753480Ab0K3IAc convert rfc822-to-8bit (ORCPT ); Tue, 30 Nov 2010 03:00:32 -0500 Received: from hpaq13.eem.corp.google.com (hpaq13.eem.corp.google.com [172.25.149.13]) by smtp-out.google.com with ESMTP id oAU80U8q009477 for ; Tue, 30 Nov 2010 00:00:31 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1291104031; bh=PoQfNh6wTvBsYwn9YN+mJ4k03Is=; h=MIME-Version:Date:Message-ID:Subject:From:To:Content-Type: Content-Transfer-Encoding; b=klI5cSHNLFoyXwIc6ZsvJ24nny0YBuDlKjThCcFEXvIo90s/lB7ggTU7WNd13vGLz zjPklZ3SZYqy6CHgUdY6Q== Received: from bwz4 (bwz4.prod.google.com [10.188.26.4]) by hpaq13.eem.corp.google.com with ESMTP id oAU7xpdH025209 for ; Tue, 30 Nov 2010 00:00:30 -0800 Received: by bwz4 with SMTP id 4so4710451bwz.11 for ; Tue, 30 Nov 2010 00:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=F9o+ZJYdmaNmSjGbA5VCdYCv2Ok2ZNFj4Kmvj8zRDAs=; b=qMVmtvM9FD6rwK6dW8VxHBzQad5jW0WPVh33thMGe5ZzrKWdvqlgUTq9A5jX66M32S fWAxCzoYS/l+A2tDbTdQ== DomainKey-Signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=EGLwHqd6p+rdpbrabL8gztf7mKrc4G1+UrG8I+zkZ9J+24UfcSPlKQXkT9pQxE+IiE Wwvsz2ckbmkjkx229pGQ== MIME-Version: 1.0 Received: by 10.204.76.18 with SMTP id a18mr6097411bkk.179.1291104029692; Tue, 30 Nov 2010 00:00:29 -0800 (PST) Received: by 10.204.29.18 with HTTP; Tue, 30 Nov 2010 00:00:29 -0800 (PST) Date: Tue, 30 Nov 2010 00:00:29 -0800 Message-ID: Subject: [PATCH] Net-ethtool : Allow ethtool to set interface in loopback mode. From: Mahesh Bandewar To: David Miller , linux-netdev X-System-Of-Record: true Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch enables ethtool to set the loopback mode on a given interface. This is the reworked version of earlier submit (which I don't have reference to). By configuring the interface in loopback mode in conjunction with a policy route / rule, a userland application can stress the egress / ingress path exposing the flows of the change in progress and potentially help developer(s) understand the impact of those changes without even sending a packet out on the network. Following set of commands illustrates one such example -     a) ifconfig eth1 192.168.1.1     b) ip -4 rule add from all iif eth1 lookup 250     c) ip -4 route add local 0/0 dev lo proto kernel scope host table 250     d) arp -Ds 192.168.1.100 eth1     e) arp -Ds 192.168.1.200 eth1     f) sysctl -w net.ipv4.ip_nonlocal_bind=1     g) sysctl -w net.ipv4.conf.all.accept_local=1     # Assuming that the machine has 8 cores     h) taskset 000f netserver -L 192.168.1.200     i) taskset 00f0 netperf -t TCP_CRR -L 192.168.1.100 -H 192.168.1.200 -l 30 Signed-off-by: Mahesh Bandewar ---  include/linux/ethtool.h |    4 ++++  net/core/ethtool.c      |   39 +++++++++++++++++++++++++++++++++++++++  2 files changed, 43 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 6628a50..7523d45 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -678,6 +678,8 @@ struct ethtool_ops {                                   struct ethtool_rxfh_indir *);         int     (*set_rxfh_indir)(struct net_device *,                                   const struct ethtool_rxfh_indir *); +       int     (*get_loopback)(struct net_device *, u32 *); +       int     (*set_loopback)(struct net_device *, u32);  };  #endif /* __KERNEL__ */ @@ -741,6 +743,8 @@ struct ethtool_ops {  #define ETHTOOL_GSSET_INFO     0x00000037 /* Get string set info */  #define ETHTOOL_GRXFHINDIR     0x00000038 /* Get RX flow hash indir'n table */  #define ETHTOOL_SRXFHINDIR     0x00000039 /* Set RX flow hash indir'n table */ +#define ETHTOOL_SLOOPBACK      0x0000003a /* Enable / Disable Loopback */ +#define ETHTOOL_GLOOPBACK      0x0000003b /* Get Loopback status */  /* compatibility with older code */  #define SPARC_ETH_GSET         ETHTOOL_GSET diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 956a9f4..5c87c93 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -1434,6 +1434,39 @@ static noinline_for_stack int ethtool_flash_device(struct         return dev->ethtool_ops->flash_device(dev, &efl);  } +static int ethtool_set_loopback(struct net_device *dev, void __user *useraddr) +{ +       struct ethtool_value edata; +       const struct ethtool_ops *ops = dev->ethtool_ops; + +       if (!ops || !ops->set_loopback) +               return -EOPNOTSUPP; + +       if (copy_from_user(&edata, useraddr, sizeof(edata))) +               return -EFAULT; + +       return ops->set_loopback(dev, edata.data); +} + +static int ethtool_get_loopback(struct net_device *dev, void __user *useraddr) +{ +       struct ethtool_value edata; +       const struct ethtool_ops *ops = dev->ethtool_ops; +       int err; + +       if (!ops || !ops->get_loopback) +               return -EOPNOTSUPP; + +       err = ops->get_loopback(dev, &edata.data); +       if (err) +               return (err); + +       if (copy_to_user(useraddr, &edata, sizeof(edata))) +               return -EFAULT; + +       return 0; +} +  /* The main entry point in this file.  Called from net/core/dev.c */  int dev_ethtool(struct net *net, struct ifreq *ifr) @@ -1678,6 +1711,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)         case ETHTOOL_SRXFHINDIR:                 rc = ethtool_set_rxfh_indir(dev, useraddr);                 break; +       case ETHTOOL_SLOOPBACK: +               rc = ethtool_set_loopback(dev, useraddr); +               break; +       case ETHTOOL_GLOOPBACK: +               rc = ethtool_get_loopback(dev, useraddr); +               break;         default:                 rc = -EOPNOTSUPP;         }