diff options
author | Max Krummenacher <max.krummenacher@toradex.com> | 2020-02-24 13:05:16 +0100 |
---|---|---|
committer | Max Krummenacher <max.krummenacher@toradex.com> | 2020-02-24 13:05:16 +0100 |
commit | 8be6754822fc0025f963e8216cf5cfe5cf01965d (patch) | |
tree | 76fce8f223ed0e9986d2f7ee8477182606f00862 /include/linux/can | |
parent | 93bf1d7cbe98985ba4540b6889011ebbb742da5b (diff) | |
parent | 76e5c6fd6d163f1aa63969cc982e79be1fee87a7 (diff) |
Merge tag 'v4.4.214' into toradex_vf_4.4-next
This is the 4.4.214 stable release
Diffstat (limited to 'include/linux/can')
-rw-r--r-- | include/linux/can/dev.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index f7178f44825b..d2a497950639 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -17,6 +17,7 @@ #include <linux/can/error.h> #include <linux/can/led.h> #include <linux/can/netlink.h> +#include <linux/can/skb.h> #include <linux/netdevice.h> /* @@ -81,6 +82,36 @@ struct can_priv { #define get_can_dlc(i) (min_t(__u8, (i), CAN_MAX_DLC)) #define get_canfd_dlc(i) (min_t(__u8, (i), CANFD_MAX_DLC)) +/* Check for outgoing skbs that have not been created by the CAN subsystem */ +static inline bool can_skb_headroom_valid(struct net_device *dev, + struct sk_buff *skb) +{ + /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ + if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) + return false; + + /* af_packet does not apply CAN skb specific settings */ + if (skb->ip_summed == CHECKSUM_NONE) { + /* init headroom */ + can_skb_prv(skb)->ifindex = dev->ifindex; + can_skb_prv(skb)->skbcnt = 0; + + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* preform proper loopback on capable devices */ + if (dev->flags & IFF_ECHO) + skb->pkt_type = PACKET_LOOPBACK; + else + skb->pkt_type = PACKET_HOST; + + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + } + + return true; +} + /* Drop a given socketbuffer if it does not contain a valid CAN frame. */ static inline bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) @@ -98,6 +129,9 @@ static inline bool can_dropped_invalid_skb(struct net_device *dev, } else goto inval_skb; + if (!can_skb_headroom_valid(dev, skb)) + goto inval_skb; + return false; inval_skb: |