* [RFC 0/5] Ethernet low-level frame debugging support.
@ 2011-06-18 0:09 greearb
2011-06-18 0:09 ` [RFC 1/5] net: Support ethtool ops for rx of errored frames greearb
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
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(-)
--
1.7.3.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC 1/5] net: Support ethtool ops for rx of errored frames.
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
@ 2011-06-18 0:09 ` greearb
2011-06-18 0:09 ` [RFC 2/5] net: Add pkt-type PACKET_INVALID greearb
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
This can be useful when sniffing dodgy networks.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
: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(-)
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 675ddc0..fb0fac9 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -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 */
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 0e01860..443a63c 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -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;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC 2/5] net: Add pkt-type PACKET_INVALID
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
2011-06-18 0:09 ` [RFC 1/5] net: Support ethtool ops for rx of errored frames greearb
@ 2011-06-18 0:09 ` greearb
2011-06-18 0:09 ` [RFC 3/5] e100: Support receiving errored frames greearb
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
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.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 7b31863... 86f06e4... M include/linux/if_packet.h
include/linux/if_packet.h | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/linux/if_packet.h b/include/linux/if_packet.h
index 7b31863..86f06e4 100644
--- a/include/linux/if_packet.h
+++ b/include/linux/if_packet.h
@@ -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 */
--
1.7.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC 3/5] e100: Support receiving errored frames.
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
2011-06-18 0:09 ` [RFC 1/5] net: Support ethtool ops for rx of errored frames greearb
2011-06-18 0:09 ` [RFC 2/5] net: Add pkt-type PACKET_INVALID greearb
@ 2011-06-18 0:09 ` greearb
2011-06-18 0:09 ` [RFC 4/5] net: Support sending frame with specified FCS greearb
2011-06-18 0:09 ` [RFC 5/5] e1000e: Support sending frame with custom FCS greearb
4 siblings, 0 replies; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
This can be helpful when sniffing dodgy networks.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 647d8c6... aad303d... M drivers/net/e100.c
drivers/net/e100.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 647d8c6..aad303d 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC 4/5] net: Support sending frame with specified FCS.
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
` (2 preceding siblings ...)
2011-06-18 0:09 ` [RFC 3/5] e100: Support receiving errored frames greearb
@ 2011-06-18 0:09 ` greearb
2011-06-18 5:54 ` Eric Dumazet
2011-06-18 0:09 ` [RFC 5/5] e1000e: Support sending frame with custom FCS greearb
4 siblings, 1 reply; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
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.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
: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(-)
diff --git a/include/asm-generic/socket.h b/include/asm-generic/socket.h
index 9a6115e..22193a2 100644
--- a/include/asm-generic/socket.h
+++ b/include/asm-generic/socket.h
@@ -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 */
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index c0a4f3a..05b15be 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -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 */
diff --git a/include/net/sock.h b/include/net/sock.h
index f2046e4..d7e0d88 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -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)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 46cbd28..a552560 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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);
diff --git a/net/core/sock.c b/net/core/sock.c
index 6e81978..0c5f827 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c0c3cda..0d29d68 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -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
*/
--
1.7.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC 5/5] e1000e: Support sending frame with custom FCS.
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
` (3 preceding siblings ...)
2011-06-18 0:09 ` [RFC 4/5] net: Support sending frame with specified FCS greearb
@ 2011-06-18 0:09 ` greearb
4 siblings, 0 replies; 9+ messages in thread
From: greearb @ 2011-06-18 0:09 UTC (permalink / raw)
To: netdev; +Cc: Ben Greear
From: Ben Greear <greearb@candelatech.com>
This is good for testing by injecting frames with invalid
FCS onto a network.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 3310c3d... 011a95f... M drivers/net/e1000e/netdev.c
drivers/net/e1000e/netdev.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 3310c3d..011a95f 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -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) {
--
1.7.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC 4/5] net: Support sending frame with specified FCS.
2011-06-18 0:09 ` [RFC 4/5] net: Support sending frame with specified FCS greearb
@ 2011-06-18 5:54 ` Eric Dumazet
2011-06-18 14:29 ` Ben Greear
0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2011-06-18 5:54 UTC (permalink / raw)
To: greearb; +Cc: netdev
Le vendredi 17 juin 2011 à 17:09 -0700, greearb@candelatech.com a
écrit :
> From: Ben Greear <greearb@candelatech.com>
>
> 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.
>
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> ---
> :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(-)
>
> diff --git a/include/asm-generic/socket.h b/include/asm-generic/socket.h
> index 9a6115e..22193a2 100644
> --- a/include/asm-generic/socket.h
> +++ b/include/asm-generic/socket.h
> @@ -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.
> #endif /* __ASM_GENERIC_SOCKET_H */
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index c0a4f3a..05b15be 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -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 */
> diff --git a/include/net/sock.h b/include/net/sock.h
> index f2046e4..d7e0d88 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -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)
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 46cbd28..a552560 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -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);
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 6e81978..0c5f827 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -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);
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index c0c3cda..0d29d68 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -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;
> +
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.
> 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 ? ;)
>
> /*
> * 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;
same remark here : ether_crc is already 0 here.
> +
> /*
> * Now send it
> */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC 4/5] net: Support sending frame with specified FCS.
2011-06-18 5:54 ` Eric Dumazet
@ 2011-06-18 14:29 ` Ben Greear
2011-06-18 14:44 ` Eric Dumazet
0 siblings, 1 reply; 9+ messages in thread
From: Ben Greear @ 2011-06-18 14:29 UTC (permalink / raw)
To: Eric Dumazet; +Cc: netdev
On 06/17/2011 10:54 PM, Eric Dumazet wrote:
> Le vendredi 17 juin 2011 à 17:09 -0700, greearb@candelatech.com a
> écrit :
>> From: Ben Greear<greearb@candelatech.com>
>>
>> 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.
>> diff --git a/include/asm-generic/socket.h b/include/asm-generic/socket.h
>> index 9a6115e..22193a2 100644
>> --- a/include/asm-generic/socket.h
>> +++ b/include/asm-generic/socket.h
>> @@ -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.
Do I need to update each file, or just make sure the value in
asm-generic/socket.h is unique for all of them?
>> + 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.
> 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.
>> 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 ? ;)
Err, yeah :)
Thanks,
Ben
--
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc http://www.candelatech.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC 4/5] net: Support sending frame with specified FCS.
2011-06-18 14:29 ` Ben Greear
@ 2011-06-18 14:44 ` Eric Dumazet
0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2011-06-18 14:44 UTC (permalink / raw)
To: Ben Greear; +Cc: netdev
Le samedi 18 juin 2011 à 07:29 -0700, Ben Greear a écrit :
> On 06/17/2011 10:54 PM, Eric Dumazet wrote:
> >
> > 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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-06-18 14:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-18 0:09 [RFC 0/5] Ethernet low-level frame debugging support greearb
2011-06-18 0:09 ` [RFC 1/5] net: Support ethtool ops for rx of errored frames greearb
2011-06-18 0:09 ` [RFC 2/5] net: Add pkt-type PACKET_INVALID greearb
2011-06-18 0:09 ` [RFC 3/5] e100: Support receiving errored frames greearb
2011-06-18 0:09 ` [RFC 4/5] net: Support sending frame with specified FCS greearb
2011-06-18 5:54 ` Eric Dumazet
2011-06-18 14:29 ` Ben Greear
2011-06-18 14:44 ` Eric Dumazet
2011-06-18 0:09 ` [RFC 5/5] e1000e: Support sending frame with custom FCS greearb
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).