summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch')
-rw-r--r--meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch94
1 files changed, 94 insertions, 0 deletions
diff --git a/meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch b/meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch
new file mode 100644
index 0000000000..3b8a8244da
--- /dev/null
+++ b/meta/recipes-extended/iputils/iputils/0005-arping-use-additional-timerfd-to-control-when-timeou.patch
@@ -0,0 +1,94 @@
1From 60a27c76174c0ae23bdafde2bad4fdd18a44a7ea Mon Sep 17 00:00:00 2001
2From: Sami Kerola <kerolasa@iki.fi>
3Date: Sat, 7 Mar 2020 22:03:21 +0000
4Subject: [PATCH] arping: use additional timerfd to control when timeout
5 happens
6
7Trying to determine timeout by adding up interval values is pointlessly
8complicating. With separate timer everything just works.
9
10Addresses: https://github.com/iputils/iputils/issues/259
11Fixes: 1df5350bdc952b14901fde356b17b78c2bcd4cff
12Signed-off-by: Sami Kerola <kerolasa@iki.fi>
13Upstream-Status: Backport [https://github.com/iputils/iputils/commit/e594ca52afde89746b7d79c875fe9d6aea1850ac]
14Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
15---
16 arping.c | 29 ++++++++++++++++++++++++++---
17 1 file changed, 26 insertions(+), 3 deletions(-)
18
19diff --git a/arping.c b/arping.c
20index 61db3a6..7284351 100644
21--- a/arping.c
22+++ b/arping.c
23@@ -670,6 +670,7 @@ static int event_loop(struct run_state *ctl)
24 enum {
25 POLLFD_SIGNAL = 0,
26 POLLFD_TIMER,
27+ POLLFD_TIMEOUT,
28 POLLFD_SOCKET,
29 POLLFD_COUNT
30 };
31@@ -686,6 +687,13 @@ static int event_loop(struct run_state *ctl)
32 .it_value.tv_sec = ctl->interval,
33 .it_value.tv_nsec = 0
34 };
35+ int timeoutfd;
36+ struct itimerspec timeoutfd_vals = {
37+ .it_interval.tv_sec = ctl->timeout,
38+ .it_interval.tv_nsec = 0,
39+ .it_value.tv_sec = ctl->timeout,
40+ .it_value.tv_nsec = 0
41+ };
42 uint64_t exp, total_expires = 1;
43
44 unsigned char packet[4096];
45@@ -709,7 +717,7 @@ static int event_loop(struct run_state *ctl)
46 pfds[POLLFD_SIGNAL].fd = sfd;
47 pfds[POLLFD_SIGNAL].events = POLLIN | POLLERR | POLLHUP;
48
49- /* timerfd */
50+ /* interval timerfd */
51 tfd = timerfd_create(CLOCK_MONOTONIC, 0);
52 if (tfd == -1) {
53 error(0, errno, "timerfd_create failed");
54@@ -722,6 +730,19 @@ static int event_loop(struct run_state *ctl)
55 pfds[POLLFD_TIMER].fd = tfd;
56 pfds[POLLFD_TIMER].events = POLLIN | POLLERR | POLLHUP;
57
58+ /* timeout timerfd */
59+ timeoutfd = timerfd_create(CLOCK_MONOTONIC, 0);
60+ if (tfd == -1) {
61+ error(0, errno, "timerfd_create failed");
62+ return 1;
63+ }
64+ if (timerfd_settime(timeoutfd, 0, &timeoutfd_vals, NULL)) {
65+ error(0, errno, "timerfd_settime failed");
66+ return 1;
67+ }
68+ pfds[POLLFD_TIMEOUT].fd = timeoutfd;
69+ pfds[POLLFD_TIMEOUT].events = POLLIN | POLLERR | POLLHUP;
70+
71 /* socket */
72 pfds[POLLFD_SOCKET].fd = ctl->socketfd;
73 pfds[POLLFD_SOCKET].events = POLLIN | POLLERR | POLLHUP;
74@@ -764,13 +785,15 @@ static int event_loop(struct run_state *ctl)
75 continue;
76 }
77 total_expires += exp;
78- if ((0 < ctl->count && (uint64_t)ctl->count < total_expires) ||
79- (ctl->quit_on_reply && ctl->timeout < (long)total_expires)) {
80+ if (0 < ctl->count && (uint64_t)ctl->count < total_expires) {
81 exit_loop = 1;
82 continue;
83 }
84 send_pack(ctl);
85 break;
86+ case POLLFD_TIMEOUT:
87+ exit_loop = 1;
88+ break;
89 case POLLFD_SOCKET:
90 if ((s =
91 recvfrom(ctl->socketfd, packet, sizeof(packet), 0,
92--
932.18.4
94