netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 1/2] net:  Support RX-ALL feature flag.
@ 2012-02-07 23:07 greearb
  2012-02-07 23:07 ` [RFC 2/2] e1000e: Support RXALL " greearb
  0 siblings, 1 reply; 5+ messages in thread
From: greearb @ 2012-02-07 23:07 UTC (permalink / raw)
  To: netdev; +Cc: Ben Greear

From: Ben Greear <greearb@candelatech.com>

This flag requests that network devices pass all
received frames up the stack, even ones with errors
such as invalid FCS (frame check sum).  This will
allow sniffers to see bad packets and perhaps
give the user some idea how to fix the problem.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 0bc0d37... 127acee... M	Documentation/networking/netdev-features.txt
:100644 100644 3bae320... ad963d0... M	include/linux/netdev_features.h
:100644 100644 cf81ccf... 68eff5a... M	net/core/ethtool.c
 Documentation/networking/netdev-features.txt |    6 ++++++
 include/linux/netdev_features.h              |    2 ++
 net/core/ethtool.c                           |    1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/Documentation/networking/netdev-features.txt b/Documentation/networking/netdev-features.txt
index 0bc0d37..127acee 100644
--- a/Documentation/networking/netdev-features.txt
+++ b/Documentation/networking/netdev-features.txt
@@ -167,3 +167,9 @@ for packets flagged to use this feature.  Instead, the NIC will use the last
 with custom (including mal-formed) Ethernet FCS.  Probably most useful for
 sniffers.  Note that in addition to enabling this device flag, a socket option
 or similar must be used to flag specific SKBs as wanting to use this behaviour.
+
+*  rx-all
+
+This requests that the NIC receive all possible frames, including errored
+frames (such as bad FCS, etc).  This can be helpful when sniffing a link with
+bad packets on it.
diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h
index 3bae320..ad963d0 100644
--- a/include/linux/netdev_features.h
+++ b/include/linux/netdev_features.h
@@ -56,6 +56,7 @@ enum {
 	NETIF_F_LOOPBACK_BIT,		/* Enable loopback */
 	NETIF_F_RXFCS_BIT,		/* Append FCS to skb pkt data */
 	NETIF_F_NOFCS_BIT,		/* Use last 4 bytes of skb as tx FCS */
+	NETIF_F_RXALL_BIT,		/* Receive errored frames too */
 
 	/*
 	 * Add your fresh new feature above and remember to update
@@ -102,6 +103,7 @@ enum {
 #define NETIF_F_VLAN_CHALLENGED	__NETIF_F(VLAN_CHALLENGED)
 #define NETIF_F_RXFCS		__NETIF_F(RXFCS)
 #define NETIF_F_NOFCS		__NETIF_F(NOFCS)
+#define NETIF_F_RXALL		__NETIF_F(RXALL)
 
 /* Features valid for ethtool to change */
 /* = all defined minus driver/device-class-related */
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index cf81ccf..68eff5a 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -75,6 +75,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_LOOPBACK_BIT] =         "loopback",
 	[NETIF_F_RXFCS_BIT] =            "rx-fcs",
 	[NETIF_F_NOFCS_BIT] =            "no-fcs",
+	[NETIF_F_RXALL_BIT] =            "rx-all",
 };
 
 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 2/2] e1000e:  Support RXALL feature flag.
  2012-02-07 23:07 [RFC 1/2] net: Support RX-ALL feature flag greearb
@ 2012-02-07 23:07 ` greearb
  2012-02-08  0:06   ` Michał Mirosław
  0 siblings, 1 reply; 5+ messages in thread
From: greearb @ 2012-02-07 23:07 UTC (permalink / raw)
  To: netdev; +Cc: Ben Greear

From: Ben Greear <greearb@candelatech.com>

This allows the NIC to receive all frames available, including
those with bad FCS, un-matched vlans, ethernet control frames,
and more.

Tested by sending frames with bad FCS.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 1af30b9... 3a50259... M	drivers/net/ethernet/intel/e1000e/defines.h
:100644 100644 22bafbd... 48cf317... M	drivers/net/ethernet/intel/e1000e/netdev.c
 drivers/net/ethernet/intel/e1000e/defines.h |    1 +
 drivers/net/ethernet/intel/e1000e/netdev.c  |   40 ++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
index 1af30b9..3a50259 100644
--- a/drivers/net/ethernet/intel/e1000e/defines.h
+++ b/drivers/net/ethernet/intel/e1000e/defines.h
@@ -177,6 +177,7 @@
 #define E1000_RCTL_VFE            0x00040000    /* vlan filter enable */
 #define E1000_RCTL_CFIEN          0x00080000    /* canonical form enable */
 #define E1000_RCTL_CFI            0x00100000    /* canonical form indicator */
+#define E1000_RCTL_DPF            0x00400000    /* Discard Pause Frames */
 #define E1000_RCTL_PMCF           0x00800000    /* pass MAC control frames */
 #define E1000_RCTL_BSEX           0x02000000    /* Buffer size extension */
 #define E1000_RCTL_SECRC          0x04000000    /* Strip Ethernet CRC */
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 22bafbd..48cf317 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -930,9 +930,11 @@ static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
 		}
 
 		if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
-			/* recycle */
-			buffer_info->skb = skb;
-			goto next_desc;
+			if (!(netdev->features & NETIF_F_RXALL)) {
+				/* recycle */
+				buffer_info->skb = skb;
+				goto next_desc;
+			}
 		}
 
 		/* adjust length to remove Ethernet CRC */
@@ -1259,8 +1261,10 @@ static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
 		}
 
 		if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
-			dev_kfree_skb_irq(skb);
-			goto next_desc;
+			if (!(netdev->features & NETIF_F_RXALL)) {
+				dev_kfree_skb_irq(skb);
+				goto next_desc;
+			}
 		}
 
 		length = le16_to_cpu(rx_desc->wb.middle.length0);
@@ -1451,7 +1455,8 @@ static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
 
 		/* errors is only valid for DD + EOP descriptors */
 		if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
-			     (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
+			     ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
+			      !(netdev->features & NETIF_F_RXALL)))) {
 			/* recycle both page and skb */
 			buffer_info->skb = skb;
 			/* an error means any chain goes out the window too */
@@ -2996,6 +3001,25 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
 		ew32(PSRCTL, psrctl);
 	}
 
+	/* This is useful for sniffing bad packets. */
+	if (adapter->netdev->features & NETIF_F_RXALL) {
+		rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
+			 E1000_RCTL_UPE | /* RX all Unicast Pkts */
+			 E1000_RCTL_MPE | /* RX all Mcast Pkts */
+			 E1000_RCTL_BAM | /* RX All Bcast Pkts Pkts */
+			 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
+
+		rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
+			  E1000_RCTL_DPF | /* Allow filtered pause */
+			  E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
+		/* disable VLAN tagging/striping */
+		/* SKIP This, it also affects transmit side and
+		   screws up VLANs --Ben. */
+		/* ctrl = er32(CTRL); */
+		/* ctrl &= ~E1000_CTRL_VME; */
+		/* ew32(CTRL, ctrl); */
+	}
+
 	ew32(RFCTL, rfctl);
 	ew32(RCTL, rctl);
 	/* just started the receive unit, no need to restart */
@@ -6002,7 +6026,8 @@ static int e1000_set_features(struct net_device *netdev,
 		adapter->flags |= FLAG_TSO_FORCE;
 
 	if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
-			 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS)))
+			 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
+			 NETIF_F_RXALL)))
 		return 0;
 
 	/*
@@ -6230,6 +6255,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
 	/* Set user-changeable features (subset of all device features) */
 	netdev->hw_features = netdev->features;
 	netdev->hw_features |= NETIF_F_RXFCS;
+	netdev->hw_features |= NETIF_F_RXALL;
 
 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
 		netdev->features |= NETIF_F_HW_VLAN_FILTER;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC 2/2] e1000e: Support RXALL feature flag.
  2012-02-07 23:07 ` [RFC 2/2] e1000e: Support RXALL " greearb
@ 2012-02-08  0:06   ` Michał Mirosław
  2012-02-08  0:19     ` Ben Greear
  0 siblings, 1 reply; 5+ messages in thread
From: Michał Mirosław @ 2012-02-08  0:06 UTC (permalink / raw)
  To: greearb; +Cc: netdev

2012/2/8  <greearb@candelatech.com>:
> From: Ben Greear <greearb@candelatech.com>
>
> This allows the NIC to receive all frames available, including
> those with bad FCS, un-matched vlans, ethernet control frames,
> and more.
>
> Tested by sending frames with bad FCS.

This should probably mark the bad packets somehow, so they are not
passed up the stack and mixed with correct traffic.

[...]
> @@ -2996,6 +3001,25 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
>                ew32(PSRCTL, psrctl);
>        }
>
> +       /* This is useful for sniffing bad packets. */
> +       if (adapter->netdev->features & NETIF_F_RXALL) {
> +               rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
> +                        E1000_RCTL_UPE | /* RX all Unicast Pkts */
> +                        E1000_RCTL_MPE | /* RX all Mcast Pkts */
> +                        E1000_RCTL_BAM | /* RX All Bcast Pkts Pkts */
> +                        E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
> +
> +               rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
> +                         E1000_RCTL_DPF | /* Allow filtered pause */
> +                         E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
> +               /* disable VLAN tagging/striping */
> +               /* SKIP This, it also affects transmit side and
> +                  screws up VLANs --Ben. */
> +               /* ctrl = er32(CTRL); */
> +               /* ctrl &= ~E1000_CTRL_VME; */
> +               /* ew32(CTRL, ctrl); */
> +       }
> +
[...]

Looks like it can be enabled independently of promisc mode: rx-all +
no-promisc would receive only bad packets destined for this host.

Best Regards,
Michał Mirosław

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 2/2] e1000e: Support RXALL feature flag.
  2012-02-08  0:06   ` Michał Mirosław
@ 2012-02-08  0:19     ` Ben Greear
  2012-02-08  9:31       ` Michał Mirosław
  0 siblings, 1 reply; 5+ messages in thread
From: Ben Greear @ 2012-02-08  0:19 UTC (permalink / raw)
  To: Michał Mirosław; +Cc: netdev

On 02/07/2012 04:06 PM, Michał Mirosław wrote:
> 2012/2/8<greearb@candelatech.com>:
>> From: Ben Greear<greearb@candelatech.com>
>>
>> This allows the NIC to receive all frames available, including
>> those with bad FCS, un-matched vlans, ethernet control frames,
>> and more.
>>
>> Tested by sending frames with bad FCS.
>
> This should probably mark the bad packets somehow, so they are not
> passed up the stack and mixed with correct traffic.

Anything that does higher-level checksumming should figure out the
problem, if it's real (ie, if not *just* a corrupted FCS).  Anything
that doesn't is open to abuse by something sending corrupted packets
with correct checksums anyway.

But, if you think it's really needed, I could add a flag to the skb and
then free the skb after the ptype_all logic in netif_receive_skb
has been called?

>> @@ -2996,6 +3001,25 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
>>                 ew32(PSRCTL, psrctl);
>>         }
>>
>> +       /* This is useful for sniffing bad packets. */
>> +       if (adapter->netdev->features&  NETIF_F_RXALL) {
>> +               rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
>> +                        E1000_RCTL_UPE | /* RX all Unicast Pkts */
>> +                        E1000_RCTL_MPE | /* RX all Mcast Pkts */
>> +                        E1000_RCTL_BAM | /* RX All Bcast Pkts Pkts */
>> +                        E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
>> +
>> +               rctl&= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
>> +                         E1000_RCTL_DPF | /* Allow filtered pause */
>> +                         E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
>> +               /* disable VLAN tagging/striping */
>> +               /* SKIP This, it also affects transmit side and
>> +                  screws up VLANs --Ben. */
>> +               /* ctrl = er32(CTRL); */
>> +               /* ctrl&= ~E1000_CTRL_VME; */
>> +               /* ew32(CTRL, ctrl); */
>> +       }
>> +
> [...]
>
> Looks like it can be enabled independently of promisc mode: rx-all +
> no-promisc would receive only bad packets destined for this host.

Sure, that seems useful.  I'll work on that for rev 2.

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 2/2] e1000e: Support RXALL feature flag.
  2012-02-08  0:19     ` Ben Greear
@ 2012-02-08  9:31       ` Michał Mirosław
  0 siblings, 0 replies; 5+ messages in thread
From: Michał Mirosław @ 2012-02-08  9:31 UTC (permalink / raw)
  To: Ben Greear; +Cc: netdev

W dniu 8 lutego 2012 01:19 użytkownik Ben Greear
<greearb@candelatech.com> napisał:
> On 02/07/2012 04:06 PM, Michał Mirosław wrote:
>> 2012/2/8<greearb@candelatech.com>:
>>> From: Ben Greear<greearb@candelatech.com>
>>>
>>> This allows the NIC to receive all frames available, including
>>> those with bad FCS, un-matched vlans, ethernet control frames,
>>> and more.
>>>
>>> Tested by sending frames with bad FCS.
>> This should probably mark the bad packets somehow, so they are not
>> passed up the stack and mixed with correct traffic.
> Anything that does higher-level checksumming should figure out the
> problem, if it's real (ie, if not *just* a corrupted FCS).  Anything
> that doesn't is open to abuse by something sending corrupted packets
> with correct checksums anyway.
>
> But, if you think it's really needed, I could add a flag to the skb and
> then free the skb after the ptype_all logic in netif_receive_skb
> has been called?

Hmm. Passing of possibly corrupted packets might be useful for
UDPlite, but for other IP protocols CRC32 is stronger than IP checksum
and ignoring the former would allow more silently broken packets to
pass through.

I'm not convinced either way, though - just opening a discussion, as
this might change the assumptions on IP over Ethernet people make in
their apps.

When IP checksum (incl. TCP/UDP) is ok and FCS is bad, then we have a
few possibilities:
 1. only some bits in FCS are bad,
 2. some 2 matching bits of IP/TCP/UDP checksum and payload are flipped,
 3. a lot of bits (at least 16) in packet's data or header are bad,
 4. some other corruption.

Best Regards,
Michał Mirosław

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-08  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-07 23:07 [RFC 1/2] net: Support RX-ALL feature flag greearb
2012-02-07 23:07 ` [RFC 2/2] e1000e: Support RXALL " greearb
2012-02-08  0:06   ` Michał Mirosław
2012-02-08  0:19     ` Ben Greear
2012-02-08  9:31       ` Michał Mirosław

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).