Ethernet low-level frame debugging support.
Subsystems (15)
v2 cover Ethernet low-level frame debugging support.
From: Ben Greear <[email protected]>
This builds on the previous patches to allow receiving the Ethernet FCS.
These patches let one receive errored frames up the stack and generate frames with customized FCS. This allows one to generate and receive frames with bad CRC for testing and sniffing purposes.
I'll finish send/rcv support for e100,e1000, and e1000e if these patches are acceptable.
v2: Change 'kludge' to fcs_len in af_packet.c
Add SO_NOFCS to the rest of the various arch socket.h files.
*** BLURB HERE ***
Ben Greear (5):
net: Support ethtool ops for rx of errored frames.
net: Add pkt-type PACKET_INVALID
e100: Support receiving errored frames.
net: Support sending frame with specified FCS.
e1000e: Support sending frame with custom FCS.
arch/alpha/include/asm/socket.h | 1 + arch/arm/include/asm/socket.h | 1 + arch/avr32/include/asm/socket.h | 1 + arch/cris/include/asm/socket.h | 1 + arch/frv/include/asm/socket.h | 1 + arch/h8300/include/asm/socket.h | 1 + arch/ia64/include/asm/socket.h | 1 + arch/m32r/include/asm/socket.h | 1 + arch/m68k/include/asm/socket.h | 1 + arch/mips/include/asm/socket.h | 1 + arch/mn10300/include/asm/socket.h | 1 + arch/parisc/include/asm/socket.h | 1 + arch/powerpc/include/asm/socket.h | 1 + arch/s390/include/asm/socket.h | 1 + arch/sparc/include/asm/socket.h | 1 + arch/xtensa/include/asm/socket.h | 1 + drivers/net/e100.c | 42 +++++++++++++++++++++++++++++++++++- drivers/net/e1000e/netdev.c | 11 +++++++++ include/asm-generic/socket.h | 7 ++++++ include/linux/ethtool.h | 7 ++++++ include/linux/if_packet.h | 7 ++++- include/linux/skbuff.h | 5 +++- include/net/sock.h | 6 +++++ net/core/ethtool.c | 8 +++++++ net/core/skbuff.c | 1 + net/core/sock.c | 7 ++++++ net/packet/af_packet.c | 18 ++++++++++++++- 27 files changed, 128 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.3.4
PATCH v2 1/5 net: Support ethtool ops for rx of errored frames.
From: Ben Greear <[email protected]>
This can be useful when sniffing dodgy networks.
---
:100644 100644 675ddc0... fb0fac9... M include/linux/ethtool.h
:100644 100644 0e01860... 443a63c... M net/core/ethtool.c
include/linux/ethtool.h | 7 +++++++ net/core/ethtool.c | 8 ++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
include/linux/ethtool.h +7 -0
@@ -880,6 +880,9 @@ bool ethtool_invalid_flags(struct net_device *dev, u32 data, u32 supported);* @set_save_rxfcs: Set flag to save (1), or discard (0), the Ethernet * Frame Checksum for received packets. * @get_save_rxfcs: Get current value for Save RX-FCS flag. +* @set_save_rxerr: Set flag to save (1), or discard (0), received Ethernet +* frames with errors (bad checksum, etc) +* @get_save_rxerr: Get current value for Save RX-ERR flag. * * All operations are optional (i.e. the function pointer may be set * to %NULL) and callers must take this into account. Callers must
@@ -960,6 +963,8 @@ struct ethtool_ops {int (*set_dump)(struct net_device *,struct ethtool_dump *);int (*set_save_rxfcs)(struct net_device *,u32 );u32 (*get_save_rxfcs)(struct net_device *); +int (*set_save_rxerr)(struct net_device *,u32 ); + u32 (*get_save_rxerr)(struct net_device *); };#endif /* __KERNEL__ */
@@ -1036,6 +1041,8 @@ struct ethtool_ops {#define ETHTOOL_GET_DUMP_DATA 0x00000040/* Get dump data */ #define ETHTOOL_GET_SAVE_RXFCS 0x00000041/* Get RX Save Frame Checksum */ #define ETHTOOL_SET_SAVE_RXFCS 0x00000042/* Set RX Save Frame Checksum */ +#define ETHTOOL_GET_SAVE_RXERR 0x00000043/* Get RX Save Errored Frames */ +#define ETHTOOL_SET_SAVE_RXERR 0x00000044/* Set RX Save Errored Frames */ /* compatibility with older code */
net/core/ethtool.c +8 -0
@@ -2160,6 +2160,14 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) rc =ethtool_get_value (dev, useraddr, ethcmd, dev->ethtool_ops->get_save_rxfcs);break ; +case ETHTOOL_SET_SAVE_RXERR : + rc =ethtool_set_value (dev, useraddr, + dev->ethtool_ops->set_save_rxerr); +break ; +case ETHTOOL_GET_SAVE_RXERR : + rc =ethtool_get_value (dev, useraddr, ethcmd, + dev->ethtool_ops->get_save_rxerr); +break ;default : rc = -EOPNOTSUPP ; }
Signature · 1 line
1.7.3.4
Re: [PATCH v2 1/5] net: Support ethtool ops for rx of errored frames.
[email protected] <[email protected]> :
[...]
Quoted 1 line
This can be useful when sniffing dodgy networks.
Do you plan to add something similar - i.e. not per packet - for the Tx path ?
Signature · 1 line
Ueimor
Re: [PATCH v2 1/5] net: Support ethtool ops for rx of errored frames.
Quoted 5 lines · Francois Romieu
[email protected]<[email protected]> :
[...]Quoted 1 line
This can be useful when sniffing dodgy networks.
Do you plan to add something similar - i.e. not per packet - for the Tx path ?
Ability to tx errored frames? I posted a patch to enable sending frames with custom (ie, invalid) Ethernet FCS, but you have to enable it per-socket, and it will only work with AF_PACKET sockets.
Can you offer more details on what you are asking for?
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Re: [PATCH v2 1/5] net: Support ethtool ops for rx of errored frames.
Ben Greear <[email protected]> :
Quoted 5 lines · Francois Romieu
Quoted 4 lines
[email protected]<[email protected]> :
[...]Quoted 1 line
This can be useful when sniffing dodgy networks.
Quoted 7 lines
Quoted 1 line
Do you plan to add something similar - i.e. not per packet - for the Tx path ?
Ability to tx errored frames? I posted a patch to enable sending frames with custom (ie, invalid) Ethernet FCS, but you have to enable it per-socket, and it will only work with
AF_PACKETsockets.Can you offer more details on what you are asking for?
Realtek's 816[89] and 810[23] have no room in their Tx descriptors to control ethernet checksum generation. There is a global register (TxConfig) though. Before looking at the per-socket information, the driver would need to be instructed to disable Tx hardware ethernet checksumming globally.
Signature · 1 line
Ueimor
Re: [PATCH v2 1/5] net: Support ethtool ops for rx of errored frames.
Quoted 12 lines · Francois Romieu
Ben Greear<[email protected]> :
Quoted 11 lines · Francois Romieu
Quoted 5 lines
[email protected]<[email protected]> :
[...]Quoted 1 line
This can be useful when sniffing dodgy networks.
Do you plan to add something similar - i.e. not per packet - for the Tx path ?
Ability to tx errored frames? I posted a patch to enable sending frames with custom (ie, invalid) Ethernet FCS, but you have to enable it per-socket, and it will only work with
AF_PACKETsockets.
Quoted 6 lines
Quoted 1 line
Can you offer more details on what you are asking for?
Realtek's 816[89] and 810[23] have no room in their Tx descriptors to control ethernet checksum generation. There is a global register (TxConfig) though. Before looking at the per-socket information, the driver would need to be instructed to disable Tx hardware ethernet checksumming globally.
Ok. I think I'll take a stab at adding a more general low-level-flags API to ethtool, with a bitfield that can be used to twiddle these sorts of things. That way, we won't have to add new methods every time we poke a new feature in.
This would be separate from the 'features' patches that are floating around.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
David Miller
maintainerRe: [PATCH v2 1/5] net: Support ethtool ops for rx of errored frames.
From: Ben Greear <[email protected]>
Date: Sun, 19 Jun 2011 16:15:56 -0700
Quoted 2 lines
This would be separate from the 'features' patches that are floating around.
netdev->features is how you should implement your patch, please don't create new facilities.
With netdev->features they can be validated against netdev->hw_features which, in this case, r8169 would have this feature bit clear.
That's how all of this stuff is designed to work, the driver says what the hardware can do and thus ethtool generically can validate attempts to turn on features.
No new facilities are necessary at all.
PATCH v2 2/5 net: Add pkt-type PACKET_INVALID
In reply to [email protected]From: Ben Greear <[email protected]>
This will be used for errored frames received from NICs. It re-uses the un-used PACKET_FASTROUTE value, but leaves that define in just in case some user-space app requires it.
---
:100644 100644 7b31863... 86f06e4... M include/linux/if_packet.h
include/linux/if_packet.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
include/linux/if_packet.h +5 -2
@@ -26,9 +26,12 @@ struct sockaddr_ll {#define PACKET_MULTICAST 2/* To group */ #define PACKET_OTHERHOST 3/* To someone else */ #define PACKET_OUTGOING 4/* Outgoing of any type */ -/* These ones are invisible by user level */ +/* This one is invisible by user level */ #define PACKET_LOOPBACK 5/* MC/BRD frame looped back */ -#define PACKET_FASTROUTE 6/* Fastrouted frame */ +#define PACKET_FASTROUTE 6/* Fastrouted frame, not used */ +#define PACKET_INVALID 6/* Packet has errors, perhaps +* received with bad FCS +*/ /* Packet socket options */
Signature · 1 line
1.7.3.4
PATCH v2 3/5 e100: Support receiving errored frames.
In reply to [email protected]From: Ben Greear <[email protected]>
This can be helpful when sniffing dodgy networks.
---
:100644 100644 647d8c6... aad303d... M drivers/net/e100.c
drivers/net/e100.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-)
drivers/net/e100.c +40 -2
@@ -588,6 +588,7 @@ struct nic { wol_magic = (1 <<3 ), ich_10h_workaround = (1 <<4 ), save_rxfcs = (1 <<5 ), + save_rxerr = (1 <<6 ), } flags ____cacheline_aligned;enum mac mac;
@@ -1126,9 +1127,13 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) config->full_duplex_force =0x1 ;/* 1=force, 0=auto */ if (nic->flags & promiscuous || nic->loopback) { + config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ + } + +if (nic->flags & save_rxerr) { + config->rx_discard_overruns =0x1 ;/* 1=save, 0=discard */ config->rx_save_bad_frames =0x1 ;/* 1=save, 0=discard */ config->rx_discard_short_frames =0x0 ;/* 1=discard, 0=save */ - config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ }if (nic->flags & save_rxfcs)
@@ -1983,7 +1988,18 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,skb_put (skb, actual_size); skb->protocol =eth_type_trans (skb, nic->netdev); -if (unlikely (!(rfd_status & cb_ok))) { +if (unlikely (nic->flags & save_rxerr)) { +if (!(rfd_status & cb_ok)) { + skb->pkt_type =PACKET_INVALID ; + }else if (actual_size > +ETH_DATA_LEN +VLAN_ETH_HLEN + rxfcs_pad) { + nic->rx_over_length_errors++; + skb->pkt_type =PACKET_INVALID ; + } + goto process_skb; + } + +if (unlikely ((nic->flags & save_rxerr) && !(rfd_status & cb_ok))) {/* Don't indicate if hardware indicates errors */ dev_kfree_skb_any (skb); }else if (actual_size >ETH_DATA_LEN +VLAN_ETH_HLEN + rxfcs_pad) {
@@ -1991,6 +2007,7 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx, nic->rx_over_length_errors++;dev_kfree_skb_any (skb); }else { +process_skb: dev->stats.rx_packets++; dev->stats.rx_bytes += actual_size;netif_receive_skb (skb);
@@ -2397,6 +2414,25 @@ static u32 e100_get_save_rxfcs(struct net_device *netdev)return !!(nic->flags & save_rxfcs); } +static int e100_set_save_rxerr (struct net_device *netdev,u32 data) +{ +struct nic *nic =netdev_priv (netdev); +if (data) + nic->flags |= save_rxerr; +else + nic->flags &= ~save_rxerr; + +e100_exec_cb (nic,NULL , e100_configure); + +return 0 ; +} + +static u32 e100_get_save_rxerr (struct net_device *netdev) +{ +struct nic *nic =netdev_priv (netdev); +return !!(nic->flags & save_rxerr); +} +static void e100_get_drvinfo (struct net_device *netdev,struct ethtool_drvinfo *info) {
@@ -2718,6 +2754,8 @@ static const struct ethtool_ops e100_ethtool_ops = { .get_sset_count = e100_get_sset_count, .set_save_rxfcs = e100_set_save_rxfcs, .get_save_rxfcs = e100_get_save_rxfcs, + .set_save_rxerr = e100_set_save_rxerr, + .get_save_rxerr = e100_get_save_rxerr, };static int e100_do_ioctl (struct net_device *netdev,struct ifreq *ifr,int cmd)
Signature · 1 line
1.7.3.4
Re: [PATCH v2 3/5] e100: Support receiving errored frames.
Quoted 23 lines · On Sat, 2011-06-18 at 13:47 -0700, [email protected] wrote:
From: Ben Greear <[email protected]>
This can be helpful when sniffing dodgy networks.
Signed-off-by Ben Greear <[email protected]>---
:100644 100644 647d8c6... aad303d... Mdrivers/net/e100.cdrivers/net/e100.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-)drivers/net/e100.c +1
-0@@ -588,6 +588,7 @@ struct nic { wol_magic = (1 <<3 ), ich_10h_workaround = (1 <<4 ), save_rxfcs = (1 <<5 ), + save_rxerr = (1 <<6 ), } flags ____cacheline_aligned;enum mac mac;
drivers/net/e100.c static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) · line 1136
Quoted 10 lines
drivers/net/e100.c +5
-0@@ -1126,9 +1127,13 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) config->full_duplex_force =0x1 ;/* 1=force, 0=auto */ if (nic->flags & promiscuous || nic->loopback) { + config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ + } + +if (nic->flags & save_rxerr) { + config->rx_discard_overruns =0x1 ;/* 1=save, 0=discard */ config->rx_save_bad_frames =0x1 ;/* 1=save, 0=discard */ config->rx_discard_short_frames =0x0 ;/* 1=discard, 0=save */
Any idea why these were previously set in promiscuous or loopback mode?
Quoted 11 lines
drivers/net/e100.c +2
-2- config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ }if (nic->flags & save_rxfcs)@@ -1983,7 +1988,18 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,skb_put (skb, actual_size); skb->protocol =eth_type_trans (skb, nic->netdev); -if (unlikely (!(rfd_status & cb_ok))) { +if (unlikely (nic->flags & save_rxerr)) { +if (!(rfd_status & cb_ok)) {
drivers/net/e100.c static int e100_rx_indicate(struct nic *nic, struct rx *rx, · line 2002
Quoted 10 lines
drivers/net/e100.c +10
-0+ skb->pkt_type =PACKET_INVALID ; + }else if (actual_size > +ETH_DATA_LEN +VLAN_ETH_HLEN + rxfcs_pad) { + nic->rx_over_length_errors++; + skb->pkt_type =PACKET_INVALID ; + } + goto process_skb; + } + +if (unlikely ((nic->flags & save_rxerr) && !(rfd_status & cb_ok))) {
[...]
You're adding an if-statement to cover the save_rxerr case, and the existing if-else-statement should cover the !save_rxerr case - so you are missing a '!'. But since the new if-statement's body ends with a goto, there should be no need to change the condition for the existing if-else statement at all.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v2 3/5] e100: Support receiving errored frames.
Quoted 26 lines · Ben Hutchings
Quoted 25 lines · On Sat, 2011-06-18 at 13:47 -0700, [email protected] wrote:
From: Ben Greear<[email protected]>
This can be helpful when sniffing dodgy networks.
Signed-off-by Ben Greear<[email protected]>---
:100644 100644 647d8c6... aad303d... Mdrivers/net/e100.cdrivers/net/e100.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-)drivers/net/e100.c +1
-0@@ -588,6 +588,7 @@ struct nic { wol_magic = (1 <<3 ), ich_10h_workaround = (1 <<4 ), save_rxfcs = (1 <<5 ), + save_rxerr = (1 <<6 ), } flags ____cacheline_aligned;enum mac mac;@@ -1126,9 +1127,13 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) config->full_duplex_force =0x1 ;/* 1=force, 0=auto */
Quoted 10 lines
drivers/net/e100.c static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) · line 1136
Quoted 8 lines
drivers/net/e100.c +5
-0if (nic->flags& promiscuous || nic->loopback) { + config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ + } + +if (nic->flags& save_rxerr) { + config->rx_discard_overruns =0x1 ;/* 1=save, 0=discard */ config->rx_save_bad_frames =0x1 ;/* 1=save, 0=discard */ config->rx_discard_short_frames =0x0 ;/* 1=discard, 0=save */ Any idea why these were previously set in promiscuous or loopback mode?
No, but it appears they would have been thrown away anyway, so I think this change is safe.
Quoted 23 lines
Quoted 21 lines
drivers/net/e100.c +12
-2- config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ }if (nic->flags& save_rxfcs)@@ -1983,7 +1988,18 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,skb_put (skb, actual_size); skb->protocol =eth_type_trans (skb, nic->netdev); -if (unlikely (!(rfd_status& cb_ok))) { +if (unlikely (nic->flags& save_rxerr)) { +if (!(rfd_status& cb_ok)) { + skb->pkt_type =PACKET_INVALID ; + }else if (actual_size> +ETH_DATA_LEN +VLAN_ETH_HLEN + rxfcs_pad) { + nic->rx_over_length_errors++; + skb->pkt_type =PACKET_INVALID ; + } + goto process_skb; + } + +if (unlikely ((nic->flags& save_rxerr)&& !(rfd_status& cb_ok))) {[...]
Quoted 5 lines
You're adding an if-statement to cover the
save_rxerrcase, and the existing if-else-statement should cover the !save_rxerr case - so you are missing a '!'. But since the new if-statement's body ends with a goto, there should be no need to change the condition for the existing if-else statement at all.
Right..I will fix that. I forgot to back that last chunk out of some previous attempts at that code.
I'm going to have to re-spin this entire series after somehow dealing with the FEATURES extension, so it will likely be a while.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
PATCH v2 4/5 net: Support sending frame with specified FCS.
In reply to [email protected]From: Ben Greear <[email protected]>
This allows user-space to send a packet with the ethernet FCS appended to the end. Supporting NICs will know to disable their own FCS calculations and send frame as is.
This is useful for injecting bad frames on a network for testing.
---
:100644 100644 06edfef... 655fbe7... M arch/alpha/include/asm/socket.h
:100644 100644 90ffd04... 4aa1c92... M arch/arm/include/asm/socket.h
:100644 100644 c8d1fae... b70cfa3... M arch/avr32/include/asm/socket.h
:100644 100644 1a4a619... 54d2d2b... M arch/cris/include/asm/socket.h
:100644 100644 a6b2688... c77015c... M arch/frv/include/asm/socket.h
:100644 100644 04c0f45... 5c8a75d... M arch/h8300/include/asm/socket.h
:100644 100644 51427ea... f0062e6... M arch/ia64/include/asm/socket.h
:100644 100644 469787c3.. a259a66... M arch/m32r/include/asm/socket.h
:100644 100644 9bf49c8... 2442b97... M arch/m68k/include/asm/socket.h
:100644 100644 9de5190... 9b1fe294.. M arch/mips/include/asm/socket.h
:100644 100644 4e60c42... 1eb5bf5... M arch/mn10300/include/asm/socket.h
:100644 100644 225b7d6... 22538f0... M arch/parisc/include/asm/socket.h
:100644 100644 866f760... d1ecf79... M arch/powerpc/include/asm/socket.h
:100644 100644 fdff1e9... c4ab6ea... M arch/s390/include/asm/socket.h
:100644 100644 9d3fefc... af8b622... M arch/sparc/include/asm/socket.h
:100644 100644 cbdf2ff... 4c0cf9c... M arch/xtensa/include/asm/socket.h
:100644 100644 9a6115e... 22193a2... M include/asm-generic/socket.h
:100644 100644 c0a4f3a... 05b15be... M include/linux/skbuff.h
:100644 100644 f2046e4... d7e0d88... M include/net/sock.h
:100644 100644 46cbd28... a552560... M net/core/skbuff.c
:100644 100644 6e81978... 0c5f827... M net/core/sock.c
:100644 100644 c0c3cda... 7b39092... M net/packet/af_packet.c
arch/alpha/include/asm/socket.h | 1 + arch/arm/include/asm/socket.h | 1 + arch/avr32/include/asm/socket.h | 1 + arch/cris/include/asm/socket.h | 1 + arch/frv/include/asm/socket.h | 1 + arch/h8300/include/asm/socket.h | 1 + arch/ia64/include/asm/socket.h | 1 + arch/m32r/include/asm/socket.h | 1 + arch/m68k/include/asm/socket.h | 1 + arch/mips/include/asm/socket.h | 1 + arch/mn10300/include/asm/socket.h | 1 + arch/parisc/include/asm/socket.h | 1 + arch/powerpc/include/asm/socket.h | 1 + arch/s390/include/asm/socket.h | 1 + arch/sparc/include/asm/socket.h | 1 + arch/xtensa/include/asm/socket.h | 1 + include/asm-generic/socket.h | 7 +++++++ include/linux/skbuff.h | 5 ++++- include/net/sock.h | 6 ++++++ net/core/skbuff.c | 1 + net/core/sock.c | 7 +++++++ net/packet/af_packet.c | 18 ++++++++++++++++-- 22 files changed, 57 insertions(+), 3 deletions(-)
arch/alpha/include/asm/socket.h +1 -0
@@ -68,6 +68,7 @@#define SCM_TIMESTAMPING SO_TIMESTAMPING#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41/* O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here.
arch/arm/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/avr32/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* __ASM_AVR32_SOCKET_H */
arch/cris/include/asm/socket.h +1 -0
@@ -63,6 +63,7 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/frv/include/asm/socket.h +1 -0
@@ -61,6 +61,7 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/h8300/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/ia64/include/asm/socket.h +1 -0
@@ -70,5 +70,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_IA64_SOCKET_H */
arch/m32r/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_M32R_SOCKET_H */
arch/m68k/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/mips/include/asm/socket.h +1 -0
@@ -81,6 +81,7 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */#define SCM_TIMESTAMPING SO_TIMESTAMPING#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#ifdef __KERNEL__
arch/mn10300/include/asm/socket.h +1 -0
@@ -61,5 +61,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/parisc/include/asm/socket.h +1 -0
@@ -60,6 +60,7 @@#define SCM_TIMESTAMPING SO_TIMESTAMPING#define SO_RXQ_OVFL 0x4021 +#define SO_NOFCS 0x4022/* O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here.
arch/powerpc/include/asm/socket.h +1 -0
@@ -68,5 +68,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_POWERPC_SOCKET_H */
arch/s390/include/asm/socket.h +1 -0
@@ -69,5 +69,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _ASM_SOCKET_H */
arch/sparc/include/asm/socket.h +1 -0
@@ -57,6 +57,7 @@#define SCM_TIMESTAMPING SO_TIMESTAMPING#define SO_RXQ_OVFL 0x0024 +#define SO_NOFCS 0x0025/* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x5001
arch/xtensa/include/asm/socket.h +1 -0
@@ -72,5 +72,6 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 +#define SO_NOFCS 41#endif /* _XTENSA_SOCKET_H */
include/asm-generic/socket.h +7 -0
@@ -64,4 +64,11 @@#define SO_DOMAIN 39#define SO_RXQ_OVFL 40 + +/* Instruct lower device to not calculate the frame +* checksum. Useful for generating Ethernet frames +* with custom checksums. +*/ +#define SO_NOFCS 41 +#endif /* __ASM_GENERIC_SOCKET_H */
include/linux/skbuff.h +4 -1
@@ -307,6 +307,8 @@ typedef unsigned char *sk_buff_data_t;* @peeked: this packet has been seen already, so stats have been * done for it, don't do them again * @nf_trace: netfilter packet trace flag +* @use_specified_ether_crc: skb is Ethernet frame with FCS already +* appended. Use that FCS. Requires special support in NIC. * @nfctinfo: Relationship of this skb to the connection * @nfct_reasm: netfilter conntrack re-assembly pointer * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
@@ -396,7 +398,8 @@ struct sk_buff {#ifdef CONFIG_IPV6_NDISC_NODETYPE __u8 ndisc_nodetype:2;#endif - __u8 ooo_okay:1; + __u8 ooo_okay:1, + use_specified_ether_crc:1;kmemcheck_bitfield_end (flags2);/* 0/13 bit hole */
include/net/sock.h +6 -0
@@ -563,6 +563,12 @@ enum sock_flags {SOCK_TIMESTAMPING_SYS_HARDWARE ,/* %SOF_TIMESTAMPING_SYS_HARDWARE */ SOCK_FASYNC ,/* fasync() active */ SOCK_RXQ_OVFL , + SOCK_DONT_DO_LL_FCS, /* Tell NIC not to do the Ethernet FCS. + * Will use last 4 bytes of packet sent from + * user-space instead. Requires special + * support in NIC. + */ + };static inline void sock_copy_flags (struct sock *nsk,struct sock *osk)
net/core/skbuff.c +1 -0
@@ -541,6 +541,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) new->tc_verd = old->tc_verd;#endif #endif + new->use_specified_ether_crc = old->use_specified_ether_crc; new->vlan_tci = old->vlan_tci;skb_copy_secmark (new, old);
net/core/sock.c +7 -0
@@ -641,6 +641,13 @@ set_rcvbuf:sock_warn_obsolete_bsdism ("setsockopt" );break ; +case SO_NOFCS : +if (valbool) + sk->sk_flags |=SOCK_DONT_DO_LL_FCS ; +else + sk->sk_flags &= ~(SOCK_DONT_DO_LL_FCS ); +break ; +case SO_PASSCRED :if (valbool)set_bit (SOCK_PASSCRED , &sock->flags);
net/packet/af_packet.c +16 -2
@@ -430,6 +430,10 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,struct net_device *dev;__be16 proto =0 ;int err; +int fcs_len =0 ; + +if (unlikely (sk->sk_flags &SOCK_DONT_DO_LL_FCS )) + fcs_len =4 ;/* We're doing our own FCS */ /* * Get and verify the address.
@@ -465,7 +469,7 @@ retry:*/ err = -EMSGSIZE ; -if (len > dev->mtu + dev->hard_header_len +VLAN_HLEN ) +if (len > dev->mtu + dev->hard_header_len +VLAN_HLEN + fcs_len) goto out_unlock;if (!skb) {
@@ -518,6 +522,9 @@ retry:if (err <0 ) goto out_unlock; +if (unlikely (sk->sk_flags &SOCK_DONT_DO_LL_FCS )) + skb->use_specified_ether_crc =1 ; +dev_queue_xmit (skb);rcu_read_unlock ();return len;
@@ -1134,6 +1141,10 @@ static int packet_snd(struct socket *sock,int vnet_hdr_len;struct packet_sock *po =pkt_sk (sk);unsigned short gso_type =0 ; +int fcs_len =0 ; + +if (unlikely (sk->sk_flags &SOCK_DONT_DO_LL_FCS )) + fcs_len =4 ;/* We're doing our own Ethernet FCS */ /* * Get and verify the address.
@@ -1215,7 +1226,7 @@ static int packet_snd(struct socket *sock, } err = -EMSGSIZE ; -if (!gso_type && (len > dev->mtu + reserve +VLAN_HLEN )) +if (!gso_type && (len > dev->mtu + reserve +VLAN_HLEN + fcs_len)) goto out_unlock; err = -ENOBUFS ;
@@ -1278,6 +1289,9 @@ static int packet_snd(struct socket *sock, len += vnet_hdr_len; } +if (unlikely (sk->sk_flags &SOCK_DONT_DO_LL_FCS )) + skb->use_specified_ether_crc =1 ; +/* * Now send it */
Signature · 1 line
1.7.3.4
PATCH v2 5/5 e1000e: Support sending frame with custom FCS.
In reply to [email protected]From: Ben Greear <[email protected]>
This is good for testing by injecting frames with invalid FCS onto a network.
---
:100644 100644 3310c3d... 011a95f... M drivers/net/e1000e/netdev.c
drivers/net/e1000e/netdev.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/net/e1000e/netdev.c +11 -0
@@ -4417,6 +4417,7 @@ link_up:#define E1000_TX_FLAGS_VLAN 0x00000002#define E1000_TX_FLAGS_TSO 0x00000004#define E1000_TX_FLAGS_IPV4 0x00000008 +#define E1000_TX_FLAGS_NO_FCS 0x00000010#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000#define E1000_TX_FLAGS_VLAN_SHIFT 16
@@ -4681,6 +4682,9 @@ static void e1000_tx_queue(struct e1000_adapter *adapter, txd_upper |= (tx_flags &E1000_TX_FLAGS_VLAN_MASK ); } +if (unlikely (tx_flags &E1000_TX_FLAGS_NO_FCS )) + txd_lower &= ~(E1000_TXD_CMD_IFCS ); + i = tx_ring->next_to_use; do {
@@ -4698,6 +4702,10 @@ static void e1000_tx_queue(struct e1000_adapter *adapter, tx_desc->lower.data |=cpu_to_le32 (adapter->txd_cmd); +/* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ +if (unlikely (tx_flags &E1000_TX_FLAGS_NO_FCS )) + tx_desc->lower.data &= ~(cpu_to_le32 (E1000_TXD_CMD_IFCS )); +/* * Force memory writes to complete before letting h/w * know there are new descriptors to fetch. (Only
@@ -4900,6 +4908,9 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,if (skb->protocol ==htons (ETH_P_IP )) tx_flags |=E1000_TX_FLAGS_IPV4 ; +if (unlikely (skb->use_specified_ether_crc)) + tx_flags |=E1000_TX_FLAGS_NO_FCS ; +/* if count is 0 then mapping error has occurred */ count =e1000_tx_map (adapter, skb, first, max_per_txd, nr_frags, mss);if (count) {
Signature · 1 line
1.7.3.4