ieee802154: 6lowpan: add generic lowpan header check
This patch introduce an earlier check if a 6LoWPAN frame can be valid. This contains at first for checking if the header contains a dispatch byte and isn't the nalp dispatch value, which means it isn't a 6LoWPAN packet. Also we add a check if we can derference the dispatch value by checking if skb->len is unequal zero. Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com> Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
This commit is contained in:
parent
72a5e6bb51
commit
faf7d36e5e
1 changed files with 27 additions and 1 deletions
|
@ -15,8 +15,11 @@
|
||||||
|
|
||||||
#include "6lowpan_i.h"
|
#include "6lowpan_i.h"
|
||||||
|
|
||||||
|
#define LOWPAN_DISPATCH_FIRST 0xc0
|
||||||
#define LOWPAN_DISPATCH_FRAG_MASK 0xf8
|
#define LOWPAN_DISPATCH_FRAG_MASK 0xf8
|
||||||
|
|
||||||
|
#define LOWPAN_DISPATCH_NALP 0x00
|
||||||
|
|
||||||
static int lowpan_give_skb_to_device(struct sk_buff *skb)
|
static int lowpan_give_skb_to_device(struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
skb->protocol = htons(ETH_P_IPV6);
|
skb->protocol = htons(ETH_P_IPV6);
|
||||||
|
@ -162,13 +165,36 @@ static int lowpan_invoke_rx_handlers(struct sk_buff *skb)
|
||||||
#undef CALL_RXH
|
#undef CALL_RXH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool lowpan_is_nalp(u8 dispatch)
|
||||||
|
{
|
||||||
|
return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* lowpan_rx_h_check checks on generic 6LoWPAN requirements
|
||||||
|
* in MAC and 6LoWPAN header.
|
||||||
|
*
|
||||||
|
* Don't manipulate the skb here, it could be shared buffer.
|
||||||
|
*/
|
||||||
|
static inline bool lowpan_rx_h_check(struct sk_buff *skb)
|
||||||
|
{
|
||||||
|
/* check if we can dereference the dispatch */
|
||||||
|
if (unlikely(!skb->len))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (lowpan_is_nalp(*skb_network_header(skb)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
|
static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
|
||||||
struct packet_type *pt, struct net_device *orig_wdev)
|
struct packet_type *pt, struct net_device *orig_wdev)
|
||||||
{
|
{
|
||||||
struct net_device *ldev;
|
struct net_device *ldev;
|
||||||
|
|
||||||
if (wdev->type != ARPHRD_IEEE802154 ||
|
if (wdev->type != ARPHRD_IEEE802154 ||
|
||||||
skb->pkt_type == PACKET_OTHERHOST)
|
skb->pkt_type == PACKET_OTHERHOST ||
|
||||||
|
!lowpan_rx_h_check(skb))
|
||||||
return NET_RX_DROP;
|
return NET_RX_DROP;
|
||||||
|
|
||||||
ldev = wdev->ieee802154_ptr->lowpan_dev;
|
ldev = wdev->ieee802154_ptr->lowpan_dev;
|
||||||
|
|
Loading…
Reference in a new issue