Page MenuHomeFreeBSD

D56759.diff
No OneTemporary

D56759.diff

diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1029,9 +1029,16 @@
*/
tv32.tv32_sec = (uint32_t)htonl(now.tv_sec);
tv32.tv32_nsec = (uint32_t)htonl(now.tv_nsec);
- if (options & F_TIME)
+ if (options & F_TIME) {
+ /*
+ * However, per RFC 792 the Originate Timestamp (otime)
+ * should be milliseconds since midnight UTC. Something,
+ * that CLOCK_MONOTONIC does not guarantee.
+ */
+ (void)clock_gettime(CLOCK_REALTIME, &now);
icp.icmp_otime = htonl((now.tv_sec % (24*60*60))
* 1000 + now.tv_nsec / 1000000);
+ }
if (timing)
bcopy((void *)&tv32,
(void *)&outpack[ICMP_MINLEN + phdr_len],
diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh
--- a/sbin/ping/tests/ping_test.sh
+++ b/sbin/ping/tests/ping_test.sh
@@ -253,6 +253,40 @@
ifconfig `cat tun.txt` destroy
}
+atf_test_case timestamp_origin
+timestamp_origin_head()
+{
+ atf_set "descr" "ICMP Originate Timestamp"
+}
+timestamp_origin_body()
+{
+ require_ipv4
+ # Run ping timestamp
+ out=$(ping -Mt -c1 127.0.0.1)
+
+ # Extract tso and tsr
+ tso=$(echo "$out" | sed -n 's/.*tso=\([0-9:]*\).*/\1/p')
+ tsr=$(echo "$out" | sed -n 's/.*tsr=\([0-9:]*\).*/\1/p')
+
+ atf_check test -n "$tso"
+ atf_check test -n "$tsr"
+
+ # Convert tso and tsr from HH:MM:SS to seconds
+ tso_s=`date -jf %H:%M:%S $tso`
+ tsr_s=`date -jf %H:%M:%S $tsr`
+
+ diff=$((tso_s - tsr_s))
+ # Tolerate negative time difference between the sender and receiver
+ if [ $diff -lt 0 ]; then
+ diff=$(( -diff ))
+ fi
+
+ # Tolerate 2 seconds difference
+ if [ $diff -gt 2 ]; then
+ atf_fail "tso ($tso) differs from tsr ($tsr) by $diff seconds"
+ fi
+}
+
atf_init_test_cases()
{
atf_add_test_case ping_c1_s56_t1
@@ -271,6 +305,7 @@
atf_add_test_case inject_opts
atf_add_test_case inject_pip
atf_add_test_case inject_reply
+ atf_add_test_case timestamp_origin
}
check_ping_statistics()

File Metadata

Mime Type
text/plain
Expires
Wed, Jul 22, 2:55 PM (7 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35365687
Default Alt Text
D56759.diff (1 KB)

Event Timeline