Skip to contentSkip to conversation

sunrpc: Connect to a new IP address provided by the user

RFC PATCH New [email protected] 1 participant 1 message Jan 11, 2021

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

RFC PATCH v2 7/7 sunrpc: Connect to a new IP address provided by the user

From: Anna Schumaker <[email protected]>

We preserve the same port number, rather than providing a way to change it. This keeps the implementation simpler for now.

---
v2: Whoops, I forgot to commit the actual connection code to this patch!

---
 net/sunrpc/sysfs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
net/sunrpc/sysfs.c +15 -0
index 537d83635670..5bf8d293ab7c 100644
@@ -4,6 +4,7 @@
  */
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/addr.h>
+#include <linux/sunrpc/xprtsock.h>
 #include <net/sock.h>
 #include "sysfs.h"
 
@@ -70,6 +71,20 @@ static ssize_t rpc_netns_address_show(struct kobject *kobj,
 static ssize_t rpc_netns_address_store(struct kobject *kobj,
 		struct kobj_attribute *attr, const char *buf, size_t count)
 {
+	struct rpc_netns_client *c = container_of(kobj,
+				struct rpc_netns_client, kobject);
+	struct rpc_clnt *clnt = c->clnt;
+	struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt);
+	struct sockaddr *saddr = (struct sockaddr *)&xprt->addr;
+	int port = rpc_get_port(saddr);
+
+	xprt->addrlen = rpc_pton(xprt->xprt_net, buf, count - 1, saddr, sizeof(*saddr));
+	rpc_set_port(saddr, port);
+
+	kfree(xprt->address_strings[RPC_DISPLAY_ADDR]);
+	xprt->address_strings[RPC_DISPLAY_ADDR] = kstrndup(buf, count - 1, GFP_KERNEL);
+
+	xprt->ops->connect(xprt, NULL);
 	return count;
 }
 
Signature · 1 line
2.29.2