diff options
author | Jason Wang <jasowang@redhat.com> | 2013-03-26 19:11:21 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-03-27 12:48:31 -0400 |
commit | 5203cd28db6dc05c3618a602cf4cf81203d00257 (patch) | |
tree | 062761308de223744f78111cbbd2ab37772a03d4 | |
parent | e5d5decaedf41f5b03e6819789cc3ba8744d9f54 (diff) |
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: Jason Wang <jasowang@redhat.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/skbuff.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 497412165b1c..fa88b966cb8e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/hrtimer.h> | 32 | #include <linux/hrtimer.h> |
33 | #include <linux/dma-mapping.h> | 33 | #include <linux/dma-mapping.h> |
34 | #include <linux/netdev_features.h> | 34 | #include <linux/netdev_features.h> |
35 | #include <net/flow_keys.h> | ||
35 | 36 | ||
36 | /* Don't change this without changing skb_csum_unnecessary! */ | 37 | /* Don't change this without changing skb_csum_unnecessary! */ |
37 | #define CHECKSUM_NONE 0 | 38 | #define CHECKSUM_NONE 0 |
@@ -1559,6 +1560,19 @@ static inline void skb_set_transport_header(struct sk_buff *skb, | |||
1559 | skb->transport_header += offset; | 1560 | skb->transport_header += offset; |
1560 | } | 1561 | } |
1561 | 1562 | ||
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 | |||
1562 | static inline unsigned char *skb_network_header(const struct sk_buff *skb) | 1576 | static inline unsigned char *skb_network_header(const struct sk_buff *skb) |
1563 | { | 1577 | { |
1564 | return skb->head + skb->network_header; | 1578 | return skb->head + skb->network_header; |