Skip to contentSkip to conversation

Ethernet low-level frame debugging support.

RFC Superseded [email protected] 2 participants 9 messages Jun 18, 2011

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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.

 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       |   22 ++++++++++++++++++++--
 11 files changed, 116 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

RFC 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
index 675ddc0..fb0fac9 100644
@@ -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
index 0e01860..443a63c 100644
@@ -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
#2 lore raw

RFC 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
index 7b31863..86f06e4 100644
@@ -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
#3 lore raw

RFC 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
index 647d8c6..aad303d 100644
@@ -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
#4 lore raw

RFC 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 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... 0d29d68... M net/packet/af_packet.c

 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       |   22 ++++++++++++++++++++--
 6 files changed, 45 insertions(+), 3 deletions(-)
include/asm-generic/socket.h +7 -0
index 9a6115e..22193a2 100644
@@ -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
index c0a4f3a..05b15be 100644
@@ -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
index f2046e4..d7e0d88 100644
@@ -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
index 46cbd28..a552560 100644
@@ -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
index 6e81978..0c5f827 100644
@@ -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 +20 -2
index c0c3cda..0d29d68 100644
@@ -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 kludge = 0;
+
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		kludge = 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 + kludge)
 		goto out_unlock;
 
 	if (!skb) {
@@ -518,6 +522,11 @@ retry:
 	if (err < 0)
 		goto out_unlock;
 
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		skb->use_specified_ether_crc = 1;
+	else
+		skb->use_specified_ether_crc = 0;
+
 	dev_queue_xmit(skb);
 	rcu_read_unlock();
 	return len;
@@ -1134,6 +1143,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 kludge = 0;
+
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		kludge = 4; /* We're doing our own Ethernet FCS */
 
 	/*
 	 *	Get and verify the address.
@@ -1215,7 +1228,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 + kludge))
 		goto out_unlock;
 
 	err = -ENOBUFS;
@@ -1278,6 +1291,11 @@ 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;
+	else
+		skb->use_specified_ether_crc = 0;
+
 	/*
 	 *	Now send it
 	 */
Signature · 1 line
1.7.3.4
#5 lore raw

Re: [RFC 4/5] net: Support sending frame with specified FCS.

Le vendredi 17 juin 2011 à 17:09 -0700, [email protected] a écrit :

Quoted 31 lines

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 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... 0d29d68... M net/packet/af_packet.c

 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       |   22 ++++++++++++++++++++--
 6 files changed, 45 insertions(+), 3 deletions(-)
include/asm-generic/socket.h +0 -0
index 9a6115e..22193a2 100644

include/asm-generic/socket.h line 73

Quoted 10 lines
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
+

Please take a look at :

arch/*/include/asm/socket.h for many arches.

Quoted 96 lines
include/asm-generic/socket.h +0 -0
 #endif /* __ASM_GENERIC_SOCKET_H */
include/linux/skbuff.h +4 -1
index c0a4f3a..05b15be 100644
@@ -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
index f2046e4..d7e0d88 100644
@@ -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
index 46cbd28..a552560 100644
@@ -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
index 6e81978..0c5f827 100644
@@ -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 +5 -1
index c0c3cda..0d29d68 100644
@@ -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 kludge = 0;
+
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		kludge = 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 + kludge)
 		goto out_unlock;
 
 	if (!skb) {

net/packet/af_packet.c retry: · line 529

Quoted 8 lines
net/packet/af_packet.c +5 -0
@@ -518,6 +522,11 @@ retry:
 	if (err < 0)
 		goto out_unlock;
 
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		skb->use_specified_ether_crc = 1;
+	else
+		skb->use_specified_ether_crc = 0;
+

Manipulating a bit field is very expensive, and having an else branch is expensive as well, so please avoid setting crc to zero if its already guaranteed to be so.

Also I cant see where you actually _set_ the fcs value : that might trigger a kmemcheck warning later when we read it.

net/packet/af_packet.c static int packet_snd(struct socket *sock, · line 1149

Quoted 11 lines
net/packet/af_packet.c +4 -0
 	dev_queue_xmit(skb);
 	rcu_read_unlock();
 	return len;
@@ -1134,6 +1143,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 kludge = 0;
+
+	if (unlikely(sk->sk_flags & SOCK_DONT_DO_LL_FCS))
+		kludge = 4; /* We're doing our own Ethernet FCS */

kludge ? You mean fcs_len or something ? ;)

Quoted 13 lines
net/packet/af_packet.c +1 -1
 	/*
 	 *	Get and verify the address.
@@ -1215,7 +1228,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 + kludge))
 		goto out_unlock;
 
 	err = -ENOBUFS;

net/packet/af_packet.c static int packet_snd(struct socket *sock, · line 1297

Quoted 7 lines
net/packet/af_packet.c +4 -0
@@ -1278,6 +1291,11 @@ 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;
+	else
+		skb->use_specified_ether_crc = 0;

same remark here : ether_crc is already 0 here.

Quoted 4 lines
net/packet/af_packet.c +1 -0
+
 	/*
 	 *	Now send it
 	 */
author
#6 lore raw

Re: [RFC 4/5] net: Support sending frame with specified FCS.

Quoted 30 lines · Eric Dumazet

Le vendredi 17 juin 2011 à 17:09 -0700, [email protected] a écrit :

Quoted 15 lines

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.

include/asm-generic/socket.h +0 -0
index 9a6115e..22193a2 100644

include/asm-generic/socket.h line 73

Quoted 10 lines
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
+

Please take a look at :

Quoted 1 line

arch/*/include/asm/socket.h for many arches.

Do I need to update each file, or just make sure the value in asm-generic/socket.h is unique for all of them?

Quoted 9 lines

include/asm-generic/socket.h

Quoted 5 lines
include/asm-generic/socket.h +5 -0
+	if (unlikely(sk->sk_flags&  SOCK_DONT_DO_LL_FCS))
+		skb->use_specified_ether_crc = 1;
+	else
+		skb->use_specified_ether_crc = 0;
+

Manipulating a bit field is very expensive, and having an else branch is expensive as well, so please avoid setting crc to zero if its already guaranteed to be so.

Ok, I'll double-check that it is zero by default. and fix that.

Quoted 2 lines

Also I cant see where you actually _set_ the fcs value : that might trigger a kmemcheck warning later when we read it.

It is the last 4 bytes of the payload passed in from user-space.

Quoted 5 lines
Quoted 5 lines
  	dev_queue_xmit(skb);
  	rcu_read_unlock();
  	return len;
include/asm-generic/socket.h +0 -0
@@ -1134,6 +1143,10 @@ static int packet_snd(struct socket *sock,
  	int vnet_hdr_len;
Quoted 8 lines

include/asm-generic/socket.h static int packet_snd(struct socket *sock, · line 1149

Quoted 6 lines
include/asm-generic/socket.h +4 -0
  	struct packet_sock *po = pkt_sk(sk);
  	unsigned short gso_type = 0;
+	int kludge = 0;
+
+	if (unlikely(sk->sk_flags&  SOCK_DONT_DO_LL_FCS))
+		kludge = 4; /* We're doing our own Ethernet FCS */

kludge ? You mean fcs_len or something ? ;)

Err, yeah :)

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#7 lore raw

Re: [RFC 4/5] net: Support sending frame with specified FCS.

Quoted 8 lines · Ben Greear
Quoted 4 lines · Eric Dumazet

Please take a look at :

arch/*/include/asm/socket.h for many arches.

Do I need to update each file, or just make sure the value in asm-generic/socket.h is unique for all of them?

You need to update them all.

Check commit 3b885787ea4112 (adding SO_RXQ_OVFL) for reference

#8 lore raw

RFC 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
index 3310c3d..011a95f 100644
@@ -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