Skip to content

Commit 5203cd2

Browse files
jasowangdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Jason Wang <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e5d5dec commit 5203cd2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

include/linux/skbuff.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/hrtimer.h>
3333
#include <linux/dma-mapping.h>
3434
#include <linux/netdev_features.h>
35+
#include <net/flow_keys.h>
3536

3637
/* Don't change this without changing skb_csum_unnecessary! */
3738
#define CHECKSUM_NONE 0
@@ -1559,6 +1560,19 @@ static inline void skb_set_transport_header(struct sk_buff *skb,
15591560
skb->transport_header += offset;
15601561
}
15611562

1563+
static inline void skb_probe_transport_header(struct sk_buff *skb,
1564+
const int offset_hint)
1565+
{
1566+
struct flow_keys keys;
1567+
1568+
if (skb_transport_header_was_set(skb))
1569+
return;
1570+
else if (skb_flow_dissect(skb, &keys))
1571+
skb_set_transport_header(skb, keys.thoff);
1572+
else
1573+
skb_set_transport_header(skb, offset_hint);
1574+
}
1575+
15621576
static inline unsigned char *skb_network_header(const struct sk_buff *skb)
15631577
{
15641578
return skb->head + skb->network_header;

0 commit comments

Comments
 (0)