[PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE3686d

5 messages, 3 authors, 2016-09-13 · open the first message on its own page

[PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

From: Eric Dumazet <hidden>
Date: 2016-09-08 04:52:59

From: Eric Dumazet <redacted>

In commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as
ancillary data") Francesco added IP_TOS values specified as integer.

However, kernel sends to userspace (at recvmsg() time) an IP_TOS value
in a single byte, when IP_RECVTOS is set on the socket.

It can be very useful to reflect all ancillary options as given by the
kernel in a subsequent sendmsg(), instead of aborting the sendmsg() with
EINVAL after Francesco patch.

So this patch extends IP_TOS ancillary to accept an u8, so that an UDP
server can simply reuse same ancillary block without having to mangle
it.

Jesper can then augment
https://github.com/netoptimizer/network-testing/blob/master/src/udp_example02.c
to add TOS reflection ;)

Fixes: f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as ancillary data")
Signed-off-by: Eric Dumazet <redacted>
Cc: Francesco Fusco <redacted> 
Cc: Jesper Dangaard Brouer <redacted>
---
 net/ipv4/ip_sockglue.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 71a52f4d4cffba2db9353f43dc817689bf4fab10..af4919792b6a812041dcb18ff30aa8b27482c7a2 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -284,9 +284,12 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
 			ipc->ttl = val;
 			break;
 		case IP_TOS:
-			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
+			if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)))
+				val = *(int *)CMSG_DATA(cmsg);
+			else if (cmsg->cmsg_len == CMSG_LEN(sizeof(u8)))
+				val = *(u8 *)CMSG_DATA(cmsg);
+			else
 				return -EINVAL;
-			val = *(int *)CMSG_DATA(cmsg);
 			if (val < 0 || val > 255)
 				return -EINVAL;
 			ipc->tos = val;

Re: [PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

From: Jesper Dangaard Brouer <hidden>
Date: 2016-09-08 09:15:25

On Wed, 07 Sep 2016 21:52:56 -0700
Eric Dumazet [off-list ref] wrote:
From: Eric Dumazet <redacted>

In commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as
ancillary data") Francesco added IP_TOS values specified as integer.

However, kernel sends to userspace (at recvmsg() time) an IP_TOS value
in a single byte, when IP_RECVTOS is set on the socket.

It can be very useful to reflect all ancillary options as given by the
kernel in a subsequent sendmsg(), instead of aborting the sendmsg() with
EINVAL after Francesco patch.

So this patch extends IP_TOS ancillary to accept an u8, so that an UDP
server can simply reuse same ancillary block without having to mangle
it.

Jesper can then augment
https://github.com/netoptimizer/network-testing/blob/master/src/udp_example02.c
to add TOS reflection ;)
This is actually your old program ;-)
Do I need to change anything, as I'm just bouncing the packet back with sendmsg() ?

Fixes: f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as ancillary data")
Signed-off-by: Eric Dumazet <redacted>
Cc: Francesco Fusco <redacted> 
Cc: Jesper Dangaard Brouer <redacted>
Looks like a good fix,

Acked-by: Jesper Dangaard Brouer <redacted>
quoted hunk
---
 net/ipv4/ip_sockglue.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 71a52f4d4cffba2db9353f43dc817689bf4fab10..af4919792b6a812041dcb18ff30aa8b27482c7a2 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -284,9 +284,12 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
 			ipc->ttl = val;
 			break;
 		case IP_TOS:
-			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
+			if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)))
+				val = *(int *)CMSG_DATA(cmsg);
+			else if (cmsg->cmsg_len == CMSG_LEN(sizeof(u8)))
+				val = *(u8 *)CMSG_DATA(cmsg);
+			else
 				return -EINVAL;
-			val = *(int *)CMSG_DATA(cmsg);
 			if (val < 0 || val > 255)
 				return -EINVAL;
 			ipc->tos = val;


-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer

Re: [PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

From: Eric Dumazet <hidden>
Date: 2016-09-08 13:31:16

On Thu, 2016-09-08 at 11:15 +0200, Jesper Dangaard Brouer wrote:
On Wed, 07 Sep 2016 21:52:56 -0700
Eric Dumazet [off-list ref] wrote:
quoted
From: Eric Dumazet <redacted>

In commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as
ancillary data") Francesco added IP_TOS values specified as integer.

However, kernel sends to userspace (at recvmsg() time) an IP_TOS value
in a single byte, when IP_RECVTOS is set on the socket.

It can be very useful to reflect all ancillary options as given by the
kernel in a subsequent sendmsg(), instead of aborting the sendmsg() with
EINVAL after Francesco patch.

So this patch extends IP_TOS ancillary to accept an u8, so that an UDP
server can simply reuse same ancillary block without having to mangle
it.

Jesper can then augment
https://github.com/netoptimizer/network-testing/blob/master/src/udp_example02.c
to add TOS reflection ;)
This is actually your old program ;-)
Do I need to change anything, as I'm just bouncing the packet back with sendmsg() ?
I guess you want to add an option and if this option is requested by the
user, add :

	setsockopt(fd, SOL_IP, IP_PKTINFO, &on, sizeof(on));
+	if (tos_reflect)
+		setsockopt(fd, SOL_IP, IP_RECVTOS, &on, sizeof(on));

before the loop doing the recvmsg()/sendmsg() calls.

Thanks !
 

Re: [PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

From: David Miller <davem@davemloft.net>
Date: 2016-09-09 00:46:28

From: Eric Dumazet <redacted>
Date: Wed, 07 Sep 2016 21:52:56 -0700
From: Eric Dumazet <redacted>

In commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as
ancillary data") Francesco added IP_TOS values specified as integer.

However, kernel sends to userspace (at recvmsg() time) an IP_TOS value
in a single byte, when IP_RECVTOS is set on the socket.

It can be very useful to reflect all ancillary options as given by the
kernel in a subsequent sendmsg(), instead of aborting the sendmsg() with
EINVAL after Francesco patch.

So this patch extends IP_TOS ancillary to accept an u8, so that an UDP
server can simply reuse same ancillary block without having to mangle
it.

Jesper can then augment
https://github.com/netoptimizer/network-testing/blob/master/src/udp_example02.c
to add TOS reflection ;)

Fixes: f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as ancillary data")
Signed-off-by: Eric Dumazet <redacted>
Applied, thanks Eric.

Re: [PATCH net-next] ipv4: accept u8 in IP_TOS ancillary data

From: Jesper Dangaard Brouer <hidden>
Date: 2016-09-13 07:07:37

On Thu, 08 Sep 2016 06:31:14 -0700
Eric Dumazet [off-list ref] wrote:
On Thu, 2016-09-08 at 11:15 +0200, Jesper Dangaard Brouer wrote:
quoted
On Wed, 07 Sep 2016 21:52:56 -0700
Eric Dumazet [off-list ref] wrote:
  
quoted
From: Eric Dumazet <redacted>

In commit f02db315b8d8 ("ipv4: IP_TOS and IP_TTL can be specified as
ancillary data") Francesco added IP_TOS values specified as integer.

However, kernel sends to userspace (at recvmsg() time) an IP_TOS value
in a single byte, when IP_RECVTOS is set on the socket.

It can be very useful to reflect all ancillary options as given by the
kernel in a subsequent sendmsg(), instead of aborting the sendmsg() with
EINVAL after Francesco patch.

So this patch extends IP_TOS ancillary to accept an u8, so that an UDP
server can simply reuse same ancillary block without having to mangle
it.

Jesper can then augment
https://github.com/netoptimizer/network-testing/blob/master/src/udp_example02.c
to add TOS reflection ;)  
This is actually your old program ;-)
Do I need to change anything, as I'm just bouncing the packet back with sendmsg() ?  
I guess you want to add an option and if this option is requested by the
user, add :

	setsockopt(fd, SOL_IP, IP_PKTINFO, &on, sizeof(on));
+	if (tos_reflect)
+		setsockopt(fd, SOL_IP, IP_RECVTOS, &on, sizeof(on));

before the loop doing the recvmsg()/sendmsg() calls.
Hi Eric,

I've implemented what you suggested:
 https://github.com/netoptimizer/network-testing/commit/0758ad77a96ecb1

Now QA can use this tool to verify the kernel commit ;-)

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help