Skip to content

Commit 4388ce0

Browse files
neilbrownTrond Myklebust
authored andcommitted
SUNRPC: support abstract unix socket addresses
An "abtract" address for an AF_UNIX socket start with a nul and can contain any bytes for the given length, but traditionally doesn't contain other nuls. When reported, the leading nul is replaced by '@'. sunrpc currently rejects connections to these addresses and reports them as an empty string. To provide support for future use of these addresses, allow them for outgoing connections and report them more usefully. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 86e2e1f commit 4388ce0

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

net/sunrpc/clnt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,12 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
565565
servername[0] = '\0';
566566
switch (args->address->sa_family) {
567567
case AF_LOCAL:
568-
snprintf(servername, sizeof(servername), "%s",
569-
sun->sun_path);
568+
if (sun->sun_path[0])
569+
snprintf(servername, sizeof(servername), "%s",
570+
sun->sun_path);
571+
else
572+
snprintf(servername, sizeof(servername), "@%s",
573+
sun->sun_path+1);
570574
break;
571575
case AF_INET:
572576
snprintf(servername, sizeof(servername), "%pI4",

net/sunrpc/xprtsock.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
253253
switch (sap->sa_family) {
254254
case AF_LOCAL:
255255
sun = xs_addr_un(xprt);
256-
strscpy(buf, sun->sun_path, sizeof(buf));
256+
if (sun->sun_path[0]) {
257+
strscpy(buf, sun->sun_path, sizeof(buf));
258+
} else {
259+
buf[0] = '@';
260+
strscpy(buf+1, sun->sun_path+1, sizeof(buf)-1);
261+
}
257262
xprt->address_strings[RPC_DISPLAY_ADDR] =
258263
kstrdup(buf, GFP_KERNEL);
259264
break;
@@ -2858,7 +2863,7 @@ static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
28582863

28592864
switch (sun->sun_family) {
28602865
case AF_LOCAL:
2861-
if (sun->sun_path[0] != '/') {
2866+
if (sun->sun_path[0] != '/' && sun->sun_path[0] != '\0') {
28622867
dprintk("RPC: bad AF_LOCAL address: %s\n",
28632868
sun->sun_path);
28642869
ret = ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)