net: Support RX-ALL feature flag.
Subsystems (4)
RFC 1/2 net: Support RX-ALL feature flag.
From: Ben Greear <[email protected]>
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.
---
: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(-)
Documentation/networking/netdev-features.txt +6 -0
@@ -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.
include/linux/netdev_features.h +2 -0
@@ -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 */
net/core/ethtool.c +1 -0
@@ -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)
Signature · 1 line
1.7.3.4
RFC 2/2 e1000e: Support RXALL feature flag.
From: Ben Greear <[email protected]>
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.
---
: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(-)
drivers/net/ethernet/intel/e1000e/defines.h +1 -0
@@ -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 */
drivers/net/ethernet/intel/e1000e/netdev.c +33 -7
@@ -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 ;
Signature · 1 line
1.7.3.4
Re: [RFC 2/2] e1000e: Support RXALL feature flag.
2012/2/8 <[email protected]>:
Quoted 7 lines
From: Ben Greear <[email protected]>
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.
[...]
Quoted 13 lines
drivers/net/ethernet/intel/e1000e/netdev.c +9
-0@@ -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 */
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_setup_rctl(struct e1000_adapter *adapter) · line 3022
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +10
-0+ 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
Re: [RFC 2/2] e1000e: Support RXALL feature flag.
Quoted 11 lines · Michał Mirosław
2012/2/8<[email protected]>:
Quoted 7 lines
From: Ben Greear<[email protected]>
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?
Quoted 25 lines
Quoted 23 lines
drivers/net/ethernet/intel/e1000e/netdev.c +19
-0@@ -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); */ + } +[...]
Quoted 2 lines
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
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Re: [RFC 2/2] e1000e: Support RXALL feature flag.
W dniu 8 lutego 2012 01:19 użytkownik Ben Greear
Quoted 11 lines · <[email protected]> napisał:
Quoted 10 lines · Michał Mirosław
2012/2/8<[email protected]>:
Quoted 7 lines
From: Ben Greear<[email protected]>
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.
Quoted 8 lines
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_alllogic innetif_receive_skbhas 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