[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <bf4afe3484836972f94c1b7738845ba69d7008f5.1677526810.git.dxu@dxuuu.xyz>
Date: Mon, 27 Feb 2023 12:51:03 -0700
From: Daniel Xu <dxu@...uu.xyz>
To: kuba@...nel.org, edumazet@...gle.com,
willemdebruijn.kernel@...il.com, davem@...emloft.net,
pabeni@...hat.com, dsahern@...nel.org
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org
Subject: [PATCH bpf-next v2 1/8] ip: frags: Return actual error codes from ip_check_defrag()
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@...uu.xyz>
---
drivers/net/macvlan.c | 2 +-
net/ipv4/ip_fragment.c | 13 ++++++++-----
net/packet/af_packet.c | 2 +-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 99a971929c8e..b8310e13d7e1 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -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);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 69c00ffdcf3e..959d2c4260ea 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -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;
@@ -535,15 +536,17 @@ 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)) {
+ err = pskb_trim_rcsum(skb, netoff + len);
+ if (err) {
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;
+ err = ip_defrag(net, skb, user);
+ if (err)
+ return ERR_PTR(err);
skb_clear_hash(skb);
}
}
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index d4e76e2ae153..1ef94828c8da 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1470,7 +1470,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) {
--
2.39.1
Powered by blists - more mailing lists