Skip to content

Commit

Permalink
busybox: Fix ping6
Browse files Browse the repository at this point in the history
Add nonblocking option for socket

JIRA: COG-42
  • Loading branch information
mateuszkobak authored and anglov committed Sep 30, 2024
1 parent 59f131d commit 45f9437
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions busybox/09-ping-signal.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
networking/ping.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
networking/ping.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/networking/ping.c b/networking/ping.c
index 94fb007..dc45f94 100644
index 94fb007..179d9e6 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -25,6 +25,7 @@
Expand Down Expand Up @@ -45,3 +45,34 @@ index 94fb007..dc45f94 100644
if (c < 0) {
if (errno != EINTR)
bb_perror_msg("recvfrom");
@@ -743,6 +750,7 @@ static void ping4(len_and_sockaddr *lsa)
static void ping6(len_and_sockaddr *lsa)
{
int sockopt;
+ int flags;
struct msghdr msg;
struct sockaddr_in6 from;
struct iovec iov;
@@ -775,6 +783,9 @@ static void ping6(len_and_sockaddr *lsa)
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);

+ flags = fcntl(pingsock,F_GETFL,0);
+ fcntl(pingsock, F_SETFL, flags | O_NONBLOCK);
+
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
BUILD_BUG_ON(offsetof(struct icmp6_hdr, icmp6_cksum) != 2);
setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
@@ -803,8 +814,10 @@ static void ping6(len_and_sockaddr *lsa)
struct cmsghdr *mp;
int hoplimit = -1;
msg.msg_controllen = sizeof(control_buf);
-
- c = recvmsg(pingsock, &msg, 0);
+ do {
+ usleep(500);
+ c = recvmsg(pingsock, &msg, 0);
+ } while(c < 0 && errno == EAGAIN);
if (c < 0) {
if (errno != EINTR)
bb_perror_msg("recvfrom");

0 comments on commit 45f9437

Please sign in to comment.