tidbits: net-ping: add ping tidbit using raw socket
cover tidbits: net-ping: add ping tidbit using raw socket
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support IPPROTO_ICMP sockets.
Using the in-band network stack, you can use: sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.
Hannes Diethelm (1):
tidbits: net-ping: add ping tidbit using raw socket
tidbits/meson.build | 6 + tidbits/oob-net-ping.c | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+) create mode 100644 tidbits/oob-net-ping.c
Signature · 1 line
2.47.3
PATCH 1/1 tidbits: net-ping: add ping tidbit using raw socket
This tidbit allows to ping any host and measure the response time.
--- tidbits/meson.build | 6 + tidbits/oob-net-ping.c | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+) create mode 100644 tidbits/oob-net-ping.c
tidbits/meson.build +6 -0
@@ -6,6 +6,12 @@ executable('oob-net-icmp', dependencies: libevl_dep ) +executable('oob-net-ping', + 'oob-net-ping.c', + install: true, + dependencies: libevl_dep +) + executable('oob-net-udp', 'oob-net-udp.c', install: true,
tidbits/oob-net-ping.c new file +480 -0
480 lines not on this page · raw message
Signature · 1 line
2.47.3
Quoted 9 lines · Hannes Diethelm
This tidbit allows to ping any host and measure the response time.
Signed-off-by Hannes Diethelm <[email protected]>--- tidbits/meson.build | 6 + tidbits/oob-net-ping.c | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+) create mode 100644 tidbits/oob-net-ping.c
Thanks. We need this to build on 32bit systems:
tidbits/oob-net-ping.c +1 -1
@@ -215,7 +215,7 @@ static size_t build_icmp_request(uint8_t *o_frame, size_t icmplen, icmphdr->checksum = cksum;if (verbosity >1 ) { -evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%ld\n" , +evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%zu\n" ,sizeof (*iphdr),sizeof (struct icmphdr ),ntohs (iphdr->ip_len), datalen);print_ip_header (iphdr);
What about turning this code into the (currently missing) 'evl-ping' utility? I believe it is of general interest to any user.
Signature · 1 line
Philippe.
Am 05.07.26 um 16:57 schrieb Philippe Gerum:
Quoted 26 lines
Quoted 9 lines · Hannes Diethelm
This tidbit allows to ping any host and measure the response time.
Signed-off-by Hannes Diethelm <[email protected]>--- tidbits/meson.build | 6 + tidbits/oob-net-ping.c | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+)create mode 100644
tidbits/oob-net-ping.cThanks. We need this to build on 32bit systems:
tidbits/oob-net-ping.c +1
-1@@ -215,7 +215,7 @@ static size_t build_icmp_request(uint8_t *o_frame, size_t icmplen, icmphdr->checksum = cksum;if (verbosity >1 ) { -evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%ld\n" , +evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%zu\n" ,sizeof (*iphdr),sizeof (struct icmphdr ),ntohs (iphdr->ip_len), datalen);print_ip_header (iphdr);
Quoted 3 lines
What about turning this code into the (currently missing) 'evl-ping' utility? I believe it is of general interest to any user.
Thanks, I will fix this.
Why not. So I would move the code in the tools place and rename it? Meanwhile, I was continuing work, so statistics are available, ping style.
oob-ping:
2 packets transmitted, 2 received, 0% packet loss, time 1633ms rtt min/avg/max/mdev = 226.8/248.3/269.9/21.6 us
ping:
3 packets transmitted, 3 received, 0% packet loss, time 2030ms rtt min/avg/max/mdev = 0.118/0.142/0.159/0.017 ms
The only difference is, that I use us instead of ms. That could confuse some users. What do you think, stay at us or use ms?
BTW: This is in a VM, that's the reason for the bad timing.
Quoted 29 lines · Hannes Diethelm
Am 05.07.26 um 16:57 schrieb Philippe Gerum:
Quoted 22 lines
Quoted 9 lines · Hannes Diethelm
This tidbit allows to ping any host and measure the response time.
Signed-off-by Hannes Diethelm <[email protected]>--- tidbits/meson.build | 6 + tidbits/oob-net-ping.c | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+)create mode 100644
tidbits/oob-net-ping.cThanks. We need this to build on 32bit systems:
tidbits/oob-net-ping.c +1
-1@@ -215,7 +215,7 @@ static size_t build_icmp_request(uint8_t *o_frame, size_t icmplen, icmphdr->checksum = cksum;if (verbosity >1 ) { -evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%ld\n" , +evl_printf ("ip_len=%zd, icmp_len=%zd, ip_len=%d, datalen=%zu\n" ,sizeof (*iphdr),sizeof (struct icmphdr ),ntohs (iphdr->ip_len), datalen);print_ip_header (iphdr);Quoted 3 lines
What about turning this code into the (currently missing) 'evl-ping' utility? I believe it is of general interest to any user.
Thanks, I will fix this.
Quoted 7 lines
Why not. So I would move the code in the tools place and rename it? Meanwhile, I was continuing work, so statistics are available, ping style.
oob-ping:
2 packets transmitted, 2 received, 0% packet loss, time 1633ms rtt min/avg/max/mdev = 226.8/248.3/269.9/21.6 us
Yep, that's nice. We would make good use of this program as a standard evl utility.
Quoted 7 lines
ping:
3 packets transmitted, 3 received, 0% packet loss, time 2030ms rtt min/avg/max/mdev = 0.118/0.142/0.159/0.017 msThe only difference is, that I use us instead of ms. That could confuse some users. What do you think, stay at us or use ms?
I would stick with the standard ping convention (ms), maybe adding an option to display delays in microseconds.
Quoted 1 line
BTW: This is in a VM, that's the reason for the bad timing.
Noted.
Signature · 1 line
Philippe.
Quoted 9 lines · Hannes Diethelm
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support
IPPROTO_ICMPsockets.Using the in-band network stack, you can use: sockfd =
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.
This said, we have an ICMP protocol module in the evl stack since recently, which only responds to ICMP_ECHO requests ATM, directly from kernel space. Extending IPPROTO_ICMP by implementing the oob_sendmsg() handler for it there has become an option.
Signature · 1 line
Philippe.
Am 05.07.26 um 17:01 schrieb Philippe Gerum:
Quoted 12 lines
Quoted 9 lines · Hannes Diethelm
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support
IPPROTO_ICMPsockets.Using the in-band network stack, you can use: sockfd =
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.
Quoted 5 lines
This said, we have an ICMP protocol module in the evl stack since recently, which only responds to
ICMP_ECHOrequests ATM, directly from kernel space. ExtendingIPPROTO_ICMPby implementing theoob_sendmsg()handler for it there has become an option.
That would make the ping tool way simpler. I can also wait until this is available and create a new patch. It's mostly done just to figure out that IPPROTO_ICMP is not available.
Quoted 12 lines · Hannes Diethelm
Am 05.07.26 um 17:01 schrieb Philippe Gerum:
Quoted 11 lines
Quoted 9 lines · Hannes Diethelm
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support
IPPROTO_ICMPsockets.Using the in-band network stack, you can use: sockfd =
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.
Quoted 8 lines
Quoted 5 lines
This said, we have an ICMP protocol module in the evl stack since recently, which only responds to
ICMP_ECHOrequests ATM, directly from kernel space. ExtendingIPPROTO_ICMPby implementing theoob_sendmsg()handler for it there has become an option.That would make the ping tool way simpler. I can also wait until this is available and create a new patch. It's mostly done just to figure out that
IPPROTO_ICMPis not available.
Ok, I believe having IPPROTO_ICMP would be the best approach. I'll let you know when this is available.
Signature · 1 line
Philippe.
Am 05.07.26 um 18:49 schrieb Philippe Gerum:
Quoted 20 lines
Quoted 18 lines · Hannes Diethelm
Am 05.07.26 um 17:01 schrieb Philippe Gerum:
Quoted 16 lines
Quoted 9 lines · Hannes Diethelm
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support
IPPROTO_ICMPsockets.Using the in-band network stack, you can use: sockfd =
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.This said, we have an ICMP protocol module in the evl stack since recently, which only responds to
ICMP_ECHOrequests ATM, directly from kernel space. ExtendingIPPROTO_ICMPby implementing theoob_sendmsg()handler for it there has become an option.
Quoted 6 lines
Quoted 2 lines
That would make the ping tool way simpler. I can also wait until this is available and create a new patch. It's mostly done just to figure out that
IPPROTO_ICMPis not available.Ok, I believe having
IPPROTO_ICMPwould be the best approach. I'll let you know when this is available.
Meanwhile, I changed to ms and corrected the "%zu". Attached 4 variants:oob-net-ping.c - The variant from the patch, improved oob-net-ping-nonraw.c - OOB with IPPROTO_ICMP (Not tested due to obvious reasons) ping-raw.c - POSIX rawping-nonraw.c - POSIX with IPPROTO_ICMP
This might help you debug the IPPROTO_ICMP implementation.
While sometimes having issues with EVL, I created also POSIX variants so see if it is my issue.
I can create also a patch if you prefer for one of the two OOB variants.
There where issues with -O3 in ip_checksum(). With -O0, it works.
The only difference I see between working and faulty is that with 16bit-aligned (raw) it fails and with 32bit-aligned (nonraw) it works. -O3 debugging doesn't really work, in assembly its nearly unreadable with -O3 and as soon as I add a printf() in the while loop, the checksum is good. I have no clue might be UB or a compiler bug. Took me some time to debug. I have gcc (Debian 14.2.0-19) 14.2.0
Of course, as soon as I create a test program with only ip_checksum() and exactly the same data, it works also, just combined with the code, it breaks down.
This version creates faulty check-sums:
static uint16_t ip_checksum(void *buf, int len)
{
uint16_t *p = buf; /* buf is assumed to be 16bit-aligned. */
uint32_t sum = 0;
int count = len;
while (count > 1) {
sum += *p++;
count -= sizeof(*p);
}
if (count > 0)
sum += *(uint8_t *)p;
while (sum >> 16)
sum = (sum & 0xffff) + (sum >> 16);
return ~sum & 0xffff;
}While this works:
static uint16_t ip_checksum(void *buf, int len)
{
void *p = buf;
uint32_t sum = 0;
int count = len;
while (count > 1) {
sum += (uint16_t)(*(uint8_t *)p) + ((uint16_t)(*(uint8_t *)(p + 1)) << 8);
p += 2;
count -= 2;
}
if (count > 0)
sum += *(uint8_t *)p;
while (sum >> 16)
sum = (sum & 0xffff) + (sum >> 16);
return ~sum & 0xffff;
}Am 06.07.26 um 00:17 schrieb Hannes Diethelm:
Quoted 87 lines
Am 05.07.26 um 18:49 schrieb Philippe Gerum:
Quoted 20 lines
Quoted 18 lines · Hannes Diethelm
Am 05.07.26 um 17:01 schrieb Philippe Gerum:
Quoted 16 lines
Quoted 9 lines · Hannes Diethelm
This patch is the result from experimenting with evl networking. I use it to do basic connection tests from the out of band network and check the timing.
It is a bit complex due to evl doesn't support
IPPROTO_ICMPsockets.Using the in-band network stack, you can use: sockfd =
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); and then only send the icmp part of the message. However, such a support is not really needed, it works fine without.This said, we have an ICMP protocol module in the evl stack since recently, which only responds to
ICMP_ECHOrequests ATM, directly from kernel space. ExtendingIPPROTO_ICMPby implementing theoob_sendmsg()handler for it there has become an option.Quoted 6 lines
Quoted 2 lines
That would make the ping tool way simpler. I can also wait until this is available and create a new patch. It's mostly done just to figure out that
IPPROTO_ICMPis not available.Ok, I believe having
IPPROTO_ICMPwould be the best approach. I'll let you know when this is available.Meanwhile, I changed to ms and corrected the "%zu". Attached 4 variants:
oob-net-ping.c- The variant from the patch, improvedoob-net-ping-nonraw.c- OOB withIPPROTO_ICMP(Not tested due to obvious reasons)ping-raw.c- POSIX rawping-nonraw.c- POSIX withIPPROTO_ICMPThis might help you debug the
IPPROTO_ICMPimplementation.While sometimes having issues with EVL, I created also POSIX variants so see if it is my issue.
I can create also a patch if you prefer for one of the two OOB variants.
There where issues with -O3 in
ip_checksum(). With -O0, it works.The only difference I see between working and faulty is that with 16bit- aligned (raw) it fails and with 32bit-aligned (nonraw) it works. -O3 debugging doesn't really work, in assembly its nearly unreadable with -O3 and as soon as I add a
printf()in the while loop, the checksum is good. I have no clue might be UB or a compiler bug. Took me some time to debug. I have gcc (Debian 14.2.0-19) 14.2.0Of course, as soon as I create a test program with only
ip_checksum()and exactly the same data, it works also, just combined with the code, it breaks down.This version creates faulty check-sums:
staticuint16_tip_checksum(void *buf, int len)
{
uint16_t *p = buf; /* buf is assumed to be 16bit-aligned. */uint32_tsum = 0;
int count = len;while (count > 1) {
sum += *p++;
count -=sizeof(*p);
}if (count > 0)
sum += *(uint8_t *)p;while (sum >> 16)
sum = (sum &0xffff) + (sum >> 16);return ~sum &
0xffff;
}While this works:
staticuint16_tip_checksum(void *buf, int len)
{
void *p = buf;
uint32_t sum = 0;
int count = len;while (count > 1) {
sum += (uint16_t)(*(uint8_t *)p) + ((uint16_t)(*(uint8_t *)(p +
1)) << 8);
p += 2;
count -= 2;
}
Quoted 8 lines
if (count > 0)
sum += *(uint8_t *)p;while (sum >> 16)
sum = (sum &0xffff) + (sum >> 16);return ~sum &
0xffff;
}
Disregard the issue with ip_checksum(). -fsanitize=undefined gave the clue. It was indeed UB, just not where I expected it. Fixing it right now:
ping-raw.c:206:16: runtime error: member access within misaligned address 0x7f4bbbd00a3e for type 'struct ip', which requires 4 byte alignment 0x7f4bbbd00a3e: note: pointer points here
6f 6a 08 00 45 00 00 54 c3 84 40 00 40 01 00 00 c0 a8 7a f6 c0 a8 7a 01 00 00 00 00 00 00 00 00
^