Skip to content

Commit

Permalink
udp_example02: socket option IP_RECVTOS for TOS reflection on sendmsg…
Browse files Browse the repository at this point in the history
…() test

Enable this test/socket-option with cmdline argument -t for "tos".

Add option for testing kernel bug introduced in kernel commit:
 f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as ancillary data")
 https://git.kernel.org/torvalds/c/f02db315b8d8

When enabling IP_RECVTOS:
 setsockopt(fd, SOL_IP, IP_RECVTOS, &on, sizeof(on))

Then reflecting/reusing the received ancillary data in the sendmsg() call
will fail after kernel commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can
be specified as ancillary data").

Eric Dumazet fixed this in kernel commit:
 e895cdce6831 ("ipv4: accept u8 in IP_TOS ancillary data")
 https://git.kernel.org/davem/net-next/c/e895cdce6831

Eric suggested I added this test option, to allow testing the kernel fix.

Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
  • Loading branch information
netoptimizer committed Sep 13, 2016
1 parent 6449f6b commit 0758ad7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/udp_example02.c
Expand Up @@ -22,6 +22,7 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <stdlib.h> /* atoi(3) */
#include <stdbool.h>

#include "common_socket.h"

Expand Down Expand Up @@ -63,10 +64,12 @@ int main(int argc, char *argv[])
struct in_pktinfo pktinfo;
int c, count = 1000000;
uint16_t listen_port = PORT;
bool tos_reflect = false;

while ((c = getopt(argc, argv, "c:l:")) != -1) {
while ((c = getopt(argc, argv, "tc:l:")) != -1) {
if (c == 'c') count = atoi(optarg);
if (c == 'l') listen_port = atoi(optarg);
if (c == 't') tos_reflect = true;
}
printf("Listen port %d\n", listen_port);
memset(&addr, 0, sizeof(addr));
Expand All @@ -77,6 +80,8 @@ int main(int argc, char *argv[])
return 1;
}
setsockopt(fd, SOL_IP, IP_PKTINFO, &on, sizeof(on));
if (tos_reflect)
setsockopt(fd, SOL_IP, IP_RECVTOS, &on, sizeof(on));

while (1) {
memset(&msghdr, 0, sizeof(msghdr));
Expand Down

0 comments on commit 0758ad7

Please sign in to comment.