Skip to contentSkip to conversation

SUNRPC: support get_srcaddr and get_srcport for rpcrdma

RFC PATCH In review Kinglong Mee 2 participants 2 messages Oct 16, 2024 – Oct 19, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 5/5 SUNRPC: support get_srcaddr and get_srcport for rpcrdma

---
 net/sunrpc/xprtrdma/transport.c | 51 +++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
net/sunrpc/xprtrdma/transport.c +51 -0
index fee3b562932b..e2860632102a 100644
@@ -442,6 +442,55 @@ xprt_rdma_set_port(struct rpc_xprt *xprt, u16 port)
 	xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 }
 
+/**
+ * xprt_rdma_get_srcaddr - get the rdma local address, without port
+ * @xprt: controlling RPC transport
+ * @buf: address buffer
+ * @buflen: the buffer length
+ */
+static int
+xprt_rdma_get_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen)
+{
+	struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
+	struct rpcrdma_ep *ep = r_xprt->rx_ep;
+	struct sockaddr *sap;
+	int ret = -1;
+
+	if (ep && ep->re_id && (ep->re_connect_status == 1)) {
+		sap = (struct sockaddr *)&ep->re_id->route.addr.src_addr;
+		ret = snprintf(buf, buflen, "%pISc", sap);
+	}
+
+	return ret;
+}
+
+/**
+ * xprt_rdma_get_srcaddr - get the rdma local address, without port
+ * @xprt: controlling RPC transport
+ */
+static unsigned short
+xprt_rdma_get_srcport(struct rpc_xprt *xprt)
+{
+	struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
+	struct rpcrdma_ep *ep = r_xprt->rx_ep;
+	struct sockaddr *sap;
+	unsigned short ret = 0;
+
+	if (ep && ep->re_id && (ep->re_connect_status == 1)) {
+		sap = (struct sockaddr *)&ep->re_id->route.addr.src_addr;
+		switch (sap->sa_family) {
+		case AF_INET6:
+			ret = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
+			break;
+		case AF_INET:
+			ret = ntohs(((struct sockaddr_in *)sap)->sin_port);
+			break;
+		}
+	}
+
+	return ret;
+}
+
 /**
  * xprt_rdma_timer - invoked when an RPC times out
  * @xprt: controlling RPC transport
@@ -768,6 +817,8 @@ static const struct rpc_xprt_ops xprt_rdma_procs = {
 	.rpcbind		= rpcb_getport_async,	/* sunrpc/rpcb_clnt.c */
 	.set_port		= xprt_rdma_set_port,
 	.connect		= xprt_rdma_connect,
+	.get_srcaddr		= xprt_rdma_get_srcaddr,
+	.get_srcport		= xprt_rdma_get_srcport,
 	.buf_alloc		= xprt_rdma_allocate,
 	.buf_free		= xprt_rdma_free,
 	.send_request		= xprt_rdma_send_request,
Signature · 1 line
2.47.0
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Kinglong,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on trondmy-nfs/linux-next]
[also build test WARNING on linus/master v6.12-rc3 next-20241018] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kinglong-Mee/SUNRPC-move-macro-for-resvport-to-address-header/20241016-195523
base:   git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
patch link:    https://lore.kernel.org/r/a25b8ee2-46c2-4468-8ebd-edbc40fc7417%40gmail.com
patch subject: [RFC PATCH 5/5] SUNRPC: support get_srcaddr and get_srcport for rpcrdma
config: x86_64-rhel-8.3-func (https://download.01.org/0day-ci/archive/20241019/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241019/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> net/sunrpc/xprtrdma/transport.c:473: warning: expecting prototype for xprt_rdma_get_srcaddr(). Prototype was for xprt_rdma_get_srcport() instead

vim +473 net/sunrpc/xprtrdma/transport.c

466
467 /**
468 * xprt_rdma_get_srcaddr - get the rdma local address, without port
469 * @xprt: controlling RPC transport
470 */
471 static unsigned short
472 xprt_rdma_get_srcport(struct rpc_xprt *xprt)

 > 473	{

474 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
475 struct rpcrdma_ep *ep = r_xprt->rx_ep;
476 struct sockaddr *sap;
477 unsigned short ret = 0;
478
479 if (ep && ep->re_id && (ep->re_connect_status == 1)) {
480 sap = (struct sockaddr *)&ep->re_id->route.addr.src_addr;
481 switch (sap->sa_family) {
482 case AF_INET6:
483 ret = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
484 break;
485 case AF_INET:
486 ret = ntohs(((struct sockaddr_in *)sap)->sin_port);
487 break;
488 }
489 }
490
491 return ret;
492 }
493

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki