Skip to content

Commit 1fb2d41

Browse files
edumazetkuba-moo
authored andcommitted
net: add pskb_may_pull_reason() helper
pskb_may_pull() can fail for two different reasons. Provide pskb_may_pull_reason() helper to distinguish between these reasons. It returns: SKB_NOT_DROPPED_YET : Success SKB_DROP_REASON_PKT_TOO_SMALL : packet too small SKB_DROP_REASON_NOMEM : skb->head could not be resized Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dc68eaf commit 1fb2d41

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

include/linux/skbuff.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,13 +2631,24 @@ void *skb_pull_data(struct sk_buff *skb, size_t len);
26312631

26322632
void *__pskb_pull_tail(struct sk_buff *skb, int delta);
26332633

2634-
static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
2634+
static inline enum skb_drop_reason
2635+
pskb_may_pull_reason(struct sk_buff *skb, unsigned int len)
26352636
{
26362637
if (likely(len <= skb_headlen(skb)))
2637-
return true;
2638+
return SKB_NOT_DROPPED_YET;
2639+
26382640
if (unlikely(len > skb->len))
2639-
return false;
2640-
return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL;
2641+
return SKB_DROP_REASON_PKT_TOO_SMALL;
2642+
2643+
if (unlikely(!__pskb_pull_tail(skb, len - skb_headlen(skb))))
2644+
return SKB_DROP_REASON_NOMEM;
2645+
2646+
return SKB_NOT_DROPPED_YET;
2647+
}
2648+
2649+
static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
2650+
{
2651+
return pskb_may_pull_reason(skb, len) == SKB_NOT_DROPPED_YET;
26412652
}
26422653

26432654
static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)

0 commit comments

Comments
 (0)