public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: yang.yang29@zte.com.cn, davem@davemloft.net
Cc: dsahern@kernel.org, edumazet@google.com, kuba@kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/ipv4: return the real errno instead of -EINVAL
Date: Fri, 4 Aug 2023 21:49:19 +0100	[thread overview]
Message-ID: <3e38a143-b683-6368-8e76-277394155bc6@linux.dev> (raw)
In-Reply-To: <202308041648338823694@zte.com.cn>

On 04/08/2023 09:48, yang.yang29@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> For now, no matter what error pointer ip_neigh_for_gw() returns,
> ip_finish_output2() always return -EINVAL, which may mislead the upper
> users.
> 
> For exemple, an application uses sendto to send an UDP packet, but when the
> neighbor table overflows, sendto() will get a value of -EINVAL, and it will
> cause users to waste a lot of time checking parameters for errors.
> 
> Return the real errno instead of -EINVAL.
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
> Cc: Si Hao <si.hao@zte.com.cn>
> Cc: Dai Shixin <dai.shixin@zte.com.cn>
> Cc: Jiang Xuexin <jiang.xuexin@zte.com.cn>
> ---
>   net/ipv4/ip_output.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
> index 6ba1a0fafbaa..2d7cf083dff9 100644
> --- a/net/ipv4/ip_output.c
> +++ b/net/ipv4/ip_output.c
> @@ -201,6 +201,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
>   	unsigned int hh_len = LL_RESERVED_SPACE(dev);
>   	struct neighbour *neigh;
>   	bool is_v6gw = false;
> +	int res;
> 
>   	if (rt->rt_type == RTN_MULTICAST) {
>   		IP_UPD_PO_STATS(net, IPSTATS_MIB_OUTMCAST, skb->len);
> @@ -214,8 +215,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
>   	}
> 
>   	if (lwtunnel_xmit_redirect(dst->lwtstate)) {
> -		int res = lwtunnel_xmit(skb);
> -
> +		res = lwtunnel_xmit(skb);
>   		if (res < 0 || res == LWTUNNEL_XMIT_DONE)
>   			return res;
>   	}
> @@ -223,8 +223,6 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
>   	rcu_read_lock();
>   	neigh = ip_neigh_for_gw(rt, skb, &is_v6gw);
>   	if (!IS_ERR(neigh)) {
> -		int res;
> -
>   		sock_confirm_neigh(skb, neigh);
>   		/* if crossing protocols, can not use the cached header */
>   		res = neigh_output(neigh, skb, is_v6gw);
> @@ -236,7 +234,8 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
>   	net_dbg_ratelimited("%s: No header cache and no neighbour!\n",
>   			    __func__);
>   	kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL);
> -	return -EINVAL;
> +	res = PTR_ERR(neigh);
> +	return res;

I believe this part could be written as

-	return -EINVAL;
+	return PTR_ERR(neigh);


and there is no need to change the code is other places. This will be
easier to track/backport.


>   }
> 
>   static int ip_finish_output_gso(struct net *net, struct sock *sk,


  reply	other threads:[~2023-08-04 20:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04  8:48 [PATCH] net/ipv4: return the real errno instead of -EINVAL yang.yang29
2023-08-04 20:49 ` Vadim Fedorenko [this message]
2023-08-07  2:05   ` xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e38a143-b683-6368-8e76-277394155bc6@linux.dev \
    --to=vadim.fedorenko@linux.dev \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yang.yang29@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox