Skip to content

Commit

Permalink
ip: frags: Return actual error codes from ip_check_defrag()
Browse files Browse the repository at this point in the history
Once we wrap ip_check_defrag() in a kfunc, it may be useful for progs to
know the exact error condition ip_check_defrag() encountered.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
  • Loading branch information
danobi authored and intel-lab-lkp committed Dec 14, 2022
1 parent b148c8b commit ff214d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drivers/net/macvlan.c
Expand Up @@ -456,7 +456,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
unsigned int hash;

skb = ip_check_defrag(dev_net(skb->dev), skb, IP_DEFRAG_MACVLAN);
if (!skb)
if (IS_ERR(skb))
return RX_HANDLER_CONSUMED;
*pskb = skb;
eth = eth_hdr(skb);
Expand Down
11 changes: 6 additions & 5 deletions net/ipv4/ip_fragment.c
Expand Up @@ -514,6 +514,7 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
struct iphdr iph;
int netoff;
u32 len;
int err;

if (skb->protocol != htons(ETH_P_IP))
return skb;
Expand All @@ -535,15 +536,15 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
if (skb) {
if (!pskb_may_pull(skb, netoff + iph.ihl * 4)) {
kfree_skb(skb);
return NULL;
return ERR_PTR(-ENOMEM);
}
if (pskb_trim_rcsum(skb, netoff + len)) {
if ((err = pskb_trim_rcsum(skb, netoff + len))) {
kfree_skb(skb);
return NULL;
return ERR_PTR(err);
}
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
if (ip_defrag(net, skb, user))
return NULL;
if ((err = ip_defrag(net, skb, user)))
return ERR_PTR(err);
skb_clear_hash(skb);
}
}
Expand Down
2 changes: 1 addition & 1 deletion net/packet/af_packet.c
Expand Up @@ -1472,7 +1472,7 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,

if (fanout_has_flag(f, PACKET_FANOUT_FLAG_DEFRAG)) {
skb = ip_check_defrag(net, skb, IP_DEFRAG_AF_PACKET);
if (!skb)
if (IS_ERR(skb))
return 0;
}
switch (f->type) {
Expand Down

0 comments on commit ff214d3

Please sign in to comment.