can: Unify droping of invalid tx skbs and netdev stats
To prevent the CAN drivers to operate on invalid socketbuffers the skbs are now checked and silently dropped at the xmit-function consistently. Also the netdev stats are consistently using the CAN data length code (dlc) for [rx|tx]_bytes now. Signed-off-by: Oliver Hartkopp <oliver@hartkopp.net> Acked-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
d218d11133
commit
3ccd4c6167
@ -47,6 +47,7 @@
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/dev.h>
|
||||
#include <net/rtnetlink.h>
|
||||
|
||||
static __initdata const char banner[] =
|
||||
@ -70,10 +71,11 @@ MODULE_PARM_DESC(echo, "Echo sent frames (for testing). Default: 0 (Off)");
|
||||
|
||||
static void vcan_rx(struct sk_buff *skb, struct net_device *dev)
|
||||
{
|
||||
struct can_frame *cf = (struct can_frame *)skb->data;
|
||||
struct net_device_stats *stats = &dev->stats;
|
||||
|
||||
stats->rx_packets++;
|
||||
stats->rx_bytes += skb->len;
|
||||
stats->rx_bytes += cf->can_dlc;
|
||||
|
||||
skb->protocol = htons(ETH_P_CAN);
|
||||
skb->pkt_type = PACKET_BROADCAST;
|
||||
@ -85,11 +87,15 @@ static void vcan_rx(struct sk_buff *skb, struct net_device *dev)
|
||||
|
||||
static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
|
||||
{
|
||||
struct can_frame *cf = (struct can_frame *)skb->data;
|
||||
struct net_device_stats *stats = &dev->stats;
|
||||
int loop;
|
||||
|
||||
if (can_dropped_invalid_skb(dev, skb))
|
||||
return NETDEV_TX_OK;
|
||||
|
||||
stats->tx_packets++;
|
||||
stats->tx_bytes += skb->len;
|
||||
stats->tx_bytes += cf->can_dlc;
|
||||
|
||||
/* set flag whether this packet has to be looped back */
|
||||
loop = skb->pkt_type == PACKET_LOOPBACK;
|
||||
@ -103,7 +109,7 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
|
||||
* CAN core already did the echo for us
|
||||
*/
|
||||
stats->rx_packets++;
|
||||
stats->rx_bytes += skb->len;
|
||||
stats->rx_bytes += cf->can_dlc;
|
||||
}
|
||||
kfree_skb(skb);
|
||||
return NETDEV_TX_OK;
|
||||
|
Reference in New Issue
Block a user