[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1459753769-4290-1-git-send-email-zlpnobody@163.com>
Date: Mon, 4 Apr 2016 00:09:29 -0700
From: Liping Zhang <zlpnobody@....com>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org, Liping Zhang <liping.zhang@...eadtrum.com>
Subject: [PATCH] net: socket: return a proper error code when source address becomes nonlocal
From: Liping Zhang <liping.zhang@...eadtrum.com>
1. Socket can use bind(directly) or connect(indirectly) to bind to a local
ip address, and later if the network becomes down, that cause the source
address becomes nonlocal, then send() call will fail and return EINVAL.
But this error code is confusing, acctually we did not pass any invalid
arguments. Furthermore, send() maybe return ok at first, it now returns
fail just because of a temporary network problem, i.e. when the network
recovery, send() call will become ok. Return EADDRNOTAVAIL instead of
EINVAL in such situation is better.
2. We can use IPV6_PKTINFO to specify the ipv6 source address when call
sendmsg() to send packet, but if the address is not available, call will
fail and EINVAL is returned. This error code is not very appropriate,
it failed maybe just because of a temporary network problem. Also
RFC3542, section 6.6 describe an example returns EADDRNOTAVAIL:
"ipi6_ifindex specifies an interface but the address ipi6_addr is not
available for use on that interface.". So return EADDRNOTAVAIL instead
of EINVAL here.
Signed-off-by: Liping Zhang <liping.zhang@...eadtrum.com>
---
net/ipv4/route.c | 6 ++++--
net/ipv6/datagram.c | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 02c6229..857f7b3 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2149,11 +2149,13 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
rcu_read_lock();
if (fl4->saddr) {
- rth = ERR_PTR(-EINVAL);
+ rth = ERR_PTR(-EADDRNOTAVAIL);
if (ipv4_is_multicast(fl4->saddr) ||
ipv4_is_lbcast(fl4->saddr) ||
- ipv4_is_zeronet(fl4->saddr))
+ ipv4_is_zeronet(fl4->saddr)) {
+ rth = ERR_PTR(-EINVAL);
goto out;
+ }
/* I removed check for oif == dev_out->oif here.
It was wrong for two reasons:
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 4281621..04d62e8 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -746,7 +746,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
strict ? dev : NULL, 0) &&
!ipv6_chk_acast_addr_src(net, dev,
&src_info->ipi6_addr))
- err = -EINVAL;
+ err = -EADDRNOTAVAIL;
else
fl6->saddr = src_info->ipi6_addr;
}
--
1.7.9.5
Powered by blists - more mailing lists