Skip to contentSkip to conversation

svc: Fix the UDP address logic

RFC PATCH In review Tom Tucker 3 participants 9 messages Oct 22, 2007 – Oct 23, 2007

Subsystems (3)
lore
Share & tools
lore

Tom Tucker

author
#0 lore raw

RFC PATCH 1/1 svc: Fix the UDP address logic

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions (e.g. getlocalname, getremotename) could have been added but this would have resulted in additional caching and copying of the addresses around.

The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing.

The xpt_local address should also be set on listening endpoints, for tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.

This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +10 -6
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
 					    struct cmsghdr *cmh)
 {
-	struct svc_sock *svsk =
-		container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+	struct svc_xprt *xprt = rqstp->rq_xprt;
+	struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
 	switch (svsk->sk_sk->sk_family) {
 	case AF_INET: {
 		struct in_pktinfo *pki = CMSG_DATA(cmh);
-		rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+		struct sockaddr_in *sin =
+			(struct sockaddr_in *)&xprt->xpt_local;
+		sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
 		break;
 		}
 	case AF_INET6: {
 		struct in6_pktinfo *pki = CMSG_DATA(cmh);
-		ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+		struct sockaddr_in6 *sin6 =
+			(struct sockaddr_in6 *)&xprt->xpt_local;
+		ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
 		break;
 		}
 	}
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	struct cmsghdr *cmh = &buffer.hdr;
 	int		err, len;
 	struct msghdr msg = {
-		.msg_name = svc_addr(rqstp),
+		.msg_name = &svsk->sk_xprt.xpt_remote,
 		.msg_control = cmh,
 		.msg_controllen = sizeof(buffer),
 		.msg_flags = MSG_DONTWAIT,
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 		svc_xprt_received(&svsk->sk_xprt);
 		return -EAGAIN;
 	}
-	rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+	svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);
 	if (skb->tstamp.tv64 == 0) {
 		skb->tstamp = ktime_get_real();
 		/* Don't enable netstamp, sunrpc doesn't

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw
Quoted 6 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

ok.

Quoted 2 lines

Since I confused myself, it's probably a good idea to describe how this is supposed to work. [...]

This is useful text, any chance you can put it into a comment or a text file describing the xprt switch interface?

Greg.

Signature · 12 lines
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
Apparently, I'm Bedevere.  Which MPHG character are you?
I don't speak for SGI.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
author
#2 lore raw
Quoted 12 lines · Greg Banks
Quoted 6 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

ok.

Quoted 8 lines
Quoted 3 lines

Since I confused myself, it's probably a good idea to describe how this is supposed to work. [...]

This is useful text, any chance you can put it into a comment or a text file describing the xprt switch interface?

I think it would be most useful if I wrote a document describing the transport switch and the requirements of a transport driver. The text file would be for the Documentation directory. I'll try to get to it in the next week.

Quoted 2 lines

Greg.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#3 lore raw
Quoted 11 lines · Tom Tucker
Quoted 6 lines · Greg Banks

On Mon, Oct 22, 2007 at 04:01:48PM -0500, Tom Tucker wrote:

This is useful text, any chance you can put it into a comment or a text file describing the xprt switch interface?

I think it would be most useful if I wrote a document describing the transport switch and the requirements of a transport driver. The text file would be for the Documentation directory. I'll try to get to it in the next week.

Great!

Greg.

Signature · 12 lines
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
Apparently, I'm Bedevere.  Which MPHG character are you?
I don't speak for SGI.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#4 lore raw
In reply to Tom Tucker
Quoted 65 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions
(e.g. getlocalname, getremotename) could have been added but this would
have resulted in additional caching and copying of the addresses around.

The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing.

The xpt_local address should also be set on listening endpoints, for
tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.

This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +9 -5
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
 					    struct cmsghdr *cmh)
 {
-	struct svc_sock *svsk =
-		container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+	struct svc_xprt *xprt = rqstp->rq_xprt;
+	struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
 	switch (svsk->sk_sk->sk_family) {
 	case AF_INET: {
 		struct in_pktinfo *pki = CMSG_DATA(cmh);
-		rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+		struct sockaddr_in *sin =
+			(struct sockaddr_in *)&xprt->xpt_local;
+		sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
 		break;
 		}
 	case AF_INET6: {
 		struct in6_pktinfo *pki = CMSG_DATA(cmh);
-		ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+		struct sockaddr_in6 *sin6 =
+			(struct sockaddr_in6 *)&xprt->xpt_local;
+		ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
 		break;
 		}
 	}
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	struct cmsghdr *cmh = &buffer.hdr;
 	int		err, len;
 	struct msghdr msg = {
-		.msg_name = svc_addr(rqstp),
+		.msg_name = &svsk->sk_xprt.xpt_remote,
 		.msg_control = cmh,
 		.msg_controllen = sizeof(buffer),
 		.msg_flags = MSG_DONTWAIT,

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 548

Quoted 5 lines
net/sunrpc/svcsock.c +1 -1
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 		svc_xprt_received(&svsk->sk_xprt);
 		return -EAGAIN;
 	}
-	rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+	svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);

This worries me a bit. Why isn't rq_addrlen involved here? the xpt_remote field should be a sockaddr_storage, and the remote_len field should be the actual length of the address, not the size of the storage space.

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 551

Quoted 3 lines
net/sunrpc/svcsock.c +0 -0
 	if (skb->tstamp.tv64 == 0) {
 		skb->tstamp = ktime_get_real();
 		/* Don't enable netstamp, sunrpc doesn't

begin:vcard
fn:Chuck Lever
n:Lever;Chuck
org:Oracle Corporation;Corporate Architecture: Linux Projects Group adr:;;1015 Granger Avenue;Ann Arbor;MI;48104;USA email;internet:chuck dot lever at nospam oracle dot com title:Principal Member of Staff
tel;work:+1 248 614 5091
x-mozilla-html:FALSE
version:2.1
end:vcard

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#5 lore raw
Quoted 69 lines · Chuck Lever
Quoted 68 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions (e.g. getlocalname, getremotename) could have been added but this would have resulted in additional caching and copying of the addresses around. The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing. The xpt_local address should also be set on listening endpoints, for tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.
This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +8 -4
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
                         struct cmsghdr *cmh)
 {
-    struct svc_sock *svsk =
-        container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+    struct svc_xprt *xprt = rqstp->rq_xprt;
+    struct svc_sock *svsk = container_of(xprt, struct svc_sock, 
 sk_xprt);
     switch (svsk->sk_sk->sk_family) {
     case AF_INET: {
         struct in_pktinfo *pki = CMSG_DATA(cmh);
-        rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+        struct sockaddr_in *sin =
+            (struct sockaddr_in *)&xprt->xpt_local;
+        sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
         break;
         }
     case AF_INET6: {
         struct in6_pktinfo *pki = CMSG_DATA(cmh);
-        ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+        struct sockaddr_in6 *sin6 =
+            (struct sockaddr_in6 *)&xprt->xpt_local;
+        ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
         break;
         }
     }
net/sunrpc/svcsock.c +1 -1
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
     struct cmsghdr *cmh = &buffer.hdr;
     int        err, len;
     struct msghdr msg = {
-        .msg_name = svc_addr(rqstp),
+        .msg_name = &svsk->sk_xprt.xpt_remote,
         .msg_control = cmh,
         .msg_controllen = sizeof(buffer),
         .msg_flags = MSG_DONTWAIT,
Quoted 8 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 548

Quoted 6 lines
net/sunrpc/svcsock.c +1 -1
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
         svc_xprt_received(&svsk->sk_xprt);
         return -EAGAIN;
     }
-    rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+    svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);

This worries me a bit. Why isn't rq_addrlen involved here?

rq_addrlen gets set in the generic code (see svc_recv). The source of the address is the transport, not the rqstp structure. The rqstp structure caches it for use when responding to the request in svc_process. Ironically, I think the HA case that Greg referred to is the only reason we can't get rid of rq_addr/rq_daddr altogether and access the address data directly from svc_xprt. Since this address may change for UDP, we have to store it in the rqstp structure and use it to reply because another request could arrive in the interim and change the address data in svc_xprt.

Quoted 1 line

the xpt_remote field should be a sockaddr_storage,

...it is.

Quoted 2 lines

and the remote_len field should be the actual length of the address, not the size of the storage space.

Perhaps it should be, but a) kernel_recvmsg doesn't give us a length, b) to determine it would require a switch, the degenerate case for which is sizeof(storage), and c) in it's current usage, big-enough is good-enough. A weaker point is "that's the way it's always been" ;-)

Tom

Quoted 4 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 551

Quoted 4 lines
net/sunrpc/svcsock.c +0 -0
     if (skb->tstamp.tv64 == 0) {
         skb->tstamp = ktime_get_real();
         /* Don't enable netstamp, sunrpc doesn't

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#6 lore raw
Quoted 71 lines · Tom Tucker
Quoted 62 lines · Chuck Lever
Quoted 61 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions
(e.g. getlocalname, getremotename) could have been added but this would
have resulted in additional caching and copying of the addresses around.
The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing. The xpt_local address should also be set on listening endpoints, for tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.
This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +8 -4
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
                         struct cmsghdr *cmh)
 {
-    struct svc_sock *svsk =
-        container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+    struct svc_xprt *xprt = rqstp->rq_xprt;
+    struct svc_sock *svsk = container_of(xprt, struct svc_sock, 
 sk_xprt);
     switch (svsk->sk_sk->sk_family) {
     case AF_INET: {
         struct in_pktinfo *pki = CMSG_DATA(cmh);
-        rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+        struct sockaddr_in *sin =
+            (struct sockaddr_in *)&xprt->xpt_local;
+        sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
         break;
         }
     case AF_INET6: {
         struct in6_pktinfo *pki = CMSG_DATA(cmh);
-        ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+        struct sockaddr_in6 *sin6 =
+            (struct sockaddr_in6 *)&xprt->xpt_local;
+        ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
         break;
         }
     }
net/sunrpc/svcsock.c +1 -1
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
     struct cmsghdr *cmh = &buffer.hdr;
     int        err, len;
     struct msghdr msg = {
-        .msg_name = svc_addr(rqstp),
+        .msg_name = &svsk->sk_xprt.xpt_remote,
         .msg_control = cmh,
         .msg_controllen = sizeof(buffer),
         .msg_flags = MSG_DONTWAIT,
Quoted 8 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 548

Quoted 6 lines
net/sunrpc/svcsock.c +1 -1
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
         svc_xprt_received(&svsk->sk_xprt);
         return -EAGAIN;
     }
-    rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+    svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);

This worries me a bit. Why isn't rq_addrlen involved here?

Quoted 5 lines

rq_addrlen gets set in the generic code (see svc_recv). The source of the address is the transport, not the rqstp structure. The rqstp structure caches it for use when responding to the request in svc_process. Ironically, I think the HA case that Greg referred to is the only reason we can't get rid of rq_addr/rq_daddr altogether and access the address data directly from svc_xprt. Since this address may change for UDP, we have to store it in the rqstp structure and use it to reply because another request could arrive in the interim and change the address data in svc_xprt.

Quoted 1 line

the xpt_remote field should be a sockaddr_storage,

...it is.

Quoted 1 line

and the remote_len field should be the actual length of the address, not the size of the storage space.

Perhaps it should be, but a) kernel_recvmsg doesn't give us a length, b) to determine it would require a switch, the degenerate case for which is sizeof(storage),

I don't agree: there is no degenerate case, and sizeof(storage) should never ever be used.

Quoted 1 line

and c) in it's current usage, big-enough is good-enough. A weaker point is "that's the way it's always been" ;-)

Please change it to use an appropriate address length. Using sizeof(struct sockaddr_storage) is broken, or at the very least inefficient (this struct is huge). The use of sizeof() here is inconsistent with the design of the IPv6 changes I made last year.

begin:vcard
fn:Chuck Lever
n:Lever;Chuck
org:Oracle Corporation;Corporate Architecture: Linux Projects Group adr:;;1015 Granger Avenue;Ann Arbor;MI;48104;USA email;internet:chuck dot lever at nospam oracle dot com title:Principal Member of Staff
tel;work:+1 248 614 5091
x-mozilla-html:FALSE
version:2.1
end:vcard

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#7 lore raw
Quoted 103 lines · Chuck Lever
Quoted 91 lines · Tom Tucker
Quoted 73 lines · Chuck Lever
Quoted 72 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug
was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions
(e.g. getlocalname, getremotename) could have been added but this would
have resulted in additional caching and copying of the addresses around.
The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing. The xpt_local address should also be set on listening endpoints, for tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.
This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +8 -4
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
                         struct cmsghdr *cmh)
 {
-    struct svc_sock *svsk =
-        container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+    struct svc_xprt *xprt = rqstp->rq_xprt;
+    struct svc_sock *svsk = container_of(xprt, struct svc_sock, 
 sk_xprt);
     switch (svsk->sk_sk->sk_family) {
     case AF_INET: {
         struct in_pktinfo *pki = CMSG_DATA(cmh);
-        rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+        struct sockaddr_in *sin =
+            (struct sockaddr_in *)&xprt->xpt_local;
+        sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
         break;
         }
     case AF_INET6: {
         struct in6_pktinfo *pki = CMSG_DATA(cmh);
-        ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+        struct sockaddr_in6 *sin6 =
+            (struct sockaddr_in6 *)&xprt->xpt_local;
+        ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
         break;
         }
     }
net/sunrpc/svcsock.c +1 -1
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
     struct cmsghdr *cmh = &buffer.hdr;
     int        err, len;
     struct msghdr msg = {
-        .msg_name = svc_addr(rqstp),
+        .msg_name = &svsk->sk_xprt.xpt_remote,
         .msg_control = cmh,
         .msg_controllen = sizeof(buffer),
         .msg_flags = MSG_DONTWAIT,
Quoted 8 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 548

Quoted 6 lines
net/sunrpc/svcsock.c +1 -1
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
         svc_xprt_received(&svsk->sk_xprt);
         return -EAGAIN;
     }
-    rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+    svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);

This worries me a bit. Why isn't rq_addrlen involved here?

rq_addrlen gets set in the generic code (see svc_recv). The source of the address is the transport, not the rqstp structure. The rqstp structure caches it for use when responding to the request in svc_process. Ironically, I think the HA case that Greg referred to is the only reason we can't get rid of rq_addr/rq_daddr altogether and access the address data directly from svc_xprt. Since this address may change for UDP, we have to store it in the rqstp structure and use it to reply because another request could arrive in the interim and change the address data in svc_xprt.

Quoted 7 lines
Quoted 1 line

the xpt_remote field should be a sockaddr_storage,

...it is.

Quoted 2 lines

and the remote_len field should be the actual length of the address, not the size of the storage space.

Perhaps it should be, but a) kernel_recvmsg doesn't give us a length,
b) to determine it would require a switch, the degenerate case for which is sizeof(storage),

I don't agree: there is no degenerate case, and sizeof(storage) should never ever be used.

Quoted 6 lines
Quoted 2 lines

and c) in it's current usage, big-enough is good-enough. A weaker point is "that's the way it's always been" ;-)

Please change it to use an appropriate address length. Using sizeof(struct sockaddr_storage) is broken, or at the very least inefficient (this struct is huge).

Yes, for TCP/UDP 128B is getting copied when it really only needs to be 16 or 28.

Quoted 2 lines

The use of sizeof() here is inconsistent with the design of the IPv6 changes I made last year.

Fair enough, but in practical terms that means if ss_family is not AF_INET or AF_INET6, we'll return an error or is there something I'm missing?

Tom

Quoted 1 line

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#8 lore raw
Quoted 77 lines · Tom Tucker
Quoted 76 lines · Chuck Lever
Quoted 75 lines · Tom Tucker
Quoted 62 lines · Chuck Lever
Quoted 61 lines · Tom Tucker

When the address information was moved to the svc_xprt structure, a bug was introduced to UDP that caused an incorrect address to be used when responding to RPC on the UDP transport. This was the result of failing to completely implement the generic address logic for the UDP transport.

Thanks to Greg for pointing this out...

Since I confused myself, it's probably a good idea to describe how this is supposed to work. The transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of xpo_recvfrom processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions
(e.g. getlocalname, getremotename) could have been added but this would
have resulted in additional caching and copying of the addresses around.
The generic svc_recv code copies the addresses from the svc_xprt structure into the rqstp structure as part of svc_recv processing. The xpt_local address should also be set on listening endpoints, for tcp/rdma this is done as part of endpoint creation and for new connections in xpo_accept processing.
This patch was tested with Connectathon over V3 on UDP.

---

 net/sunrpc/svcsock.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/sunrpc/svcsock.c +8 -4
index e1a27ee..0f8a3d5 100644
@@ -473,17 +473,21 @@ svc_write_space(struct sock *sk)
 static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
                         struct cmsghdr *cmh)
 {
-    struct svc_sock *svsk =
-        container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+    struct svc_xprt *xprt = rqstp->rq_xprt;
+    struct svc_sock *svsk = container_of(xprt, struct svc_sock, 
 sk_xprt);
     switch (svsk->sk_sk->sk_family) {
     case AF_INET: {
         struct in_pktinfo *pki = CMSG_DATA(cmh);
-        rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
+        struct sockaddr_in *sin =
+            (struct sockaddr_in *)&xprt->xpt_local;
+        sin->sin_addr.s_addr = pki->ipi_spec_dst.s_addr;
         break;
         }
     case AF_INET6: {
         struct in6_pktinfo *pki = CMSG_DATA(cmh);
-        ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
+        struct sockaddr_in6 *sin6 =
+            (struct sockaddr_in6 *)&xprt->xpt_local;
+        ipv6_addr_copy(&sin6->sin6_addr, &pki->ipi6_addr);
         break;
         }
     }
net/sunrpc/svcsock.c +1 -1
@@ -506,7 +510,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
     struct cmsghdr *cmh = &buffer.hdr;
     int        err, len;
     struct msghdr msg = {
-        .msg_name = svc_addr(rqstp),
+        .msg_name = &svsk->sk_xprt.xpt_remote,
         .msg_control = cmh,
         .msg_controllen = sizeof(buffer),
         .msg_flags = MSG_DONTWAIT,
Quoted 8 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 548

Quoted 6 lines
net/sunrpc/svcsock.c +1 -1
@@ -541,7 +545,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
         svc_xprt_received(&svsk->sk_xprt);
         return -EAGAIN;
     }
-    rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+    svsk->sk_xprt.xpt_remotelen = sizeof(svsk->sk_xprt.xpt_remote);

This worries me a bit. Why isn't rq_addrlen involved here?

rq_addrlen gets set in the generic code (see svc_recv). The source of the address is the transport, not the rqstp structure. The rqstp structure caches it for use when responding to the request in svc_process. Ironically, I think the HA case that Greg referred to is the only reason we can't get rid of rq_addr/rq_daddr altogether and access the address data directly from svc_xprt. Since this address may change for UDP, we have to store it in the rqstp structure and use it to reply because another request could arrive in the interim and change the address data in svc_xprt.

Quoted 1 line

the xpt_remote field should be a sockaddr_storage,

...it is.

Quoted 1 line

and the remote_len field should be the actual length of the address, not the size of the storage space.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Perhaps it should be, but a) kernel_recvmsg doesn't give us a length, b) to determine it would require a switch, the degenerate case for which is sizeof(storage),

I don't agree: there is no degenerate case, and sizeof(storage) should never ever be used.

Quoted 1 line

and c) in it's current usage, big-enough is good-enough. A weaker point is "that's the way it's always been" ;-)

Please change it to use an appropriate address length. Using sizeof(struct sockaddr_storage) is broken, or at the very least inefficient (this struct is huge).

Yes, for TCP/UDP 128B is getting copied when it really only needs to be 16 or 28.

I didn't think this was the case before the transport switch was introduced, but perhaps there have been some patch mix-ups, or oversights on my part.

The purpose of the address length field is to limit the number of bytes that you need to copy. It's used when the address is treated as a blob of bytes rather than when it is accessed as a union of structures discriminated by ss_family.

Quoted 2 lines
Quoted 1 line

The use of sizeof() here is inconsistent with the design of the IPv6 changes I made last year.

Fair enough, but in practical terms that means if ss_family is not AF_INET or AF_INET6, we'll return an error or is there something I'm missing?

Yes, I think an error should be thrown in that case. I notice that in some places, we have "default: BUG();" which I think is excessive.

begin:vcard
fn:Chuck Lever
n:Lever;Chuck
org:Oracle Corporation;Corporate Architecture: Linux Projects Group adr:;;1015 Granger Avenue;Ann Arbor;MI;48104;USA email;internet:chuck dot lever at nospam oracle dot com title:Principal Member of Staff
tel;work:+1 248 614 5091
x-mozilla-html:FALSE
version:2.1
end:vcard

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs