Commit 5203cd28 authored by Jason Wang's avatar Jason Wang Committed by David S. Miller

net: core: introduce skb_probe_transport_header()

Sometimes, we need probe and set the transport header for packets (e.g from
untrusted source). This patch introduces a new helper
skb_probe_transport_header() which tries to probe and set the l4 header through
skb_flow_dissect(), if not just set the transport header to the hint passed by
caller.

Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e5d5deca
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/hrtimer.h> #include <linux/hrtimer.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/netdev_features.h> #include <linux/netdev_features.h>
#include <net/flow_keys.h>
/* Don't change this without changing skb_csum_unnecessary! */ /* Don't change this without changing skb_csum_unnecessary! */
#define CHECKSUM_NONE 0 #define CHECKSUM_NONE 0
...@@ -1559,6 +1560,19 @@ static inline void skb_set_transport_header(struct sk_buff *skb, ...@@ -1559,6 +1560,19 @@ static inline void skb_set_transport_header(struct sk_buff *skb,
skb->transport_header += offset; skb->transport_header += offset;
} }
static inline void skb_probe_transport_header(struct sk_buff *skb,
const int offset_hint)
{
struct flow_keys keys;
if (skb_transport_header_was_set(skb))
return;
else if (skb_flow_dissect(skb, &keys))
skb_set_transport_header(skb, keys.thoff);
else
skb_set_transport_header(skb, offset_hint);
}
static inline unsigned char *skb_network_header(const struct sk_buff *skb) static inline unsigned char *skb_network_header(const struct sk_buff *skb)
{ {
return skb->head + skb->network_header; return skb->head + skb->network_header;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment