Skip to content

Commit 9e41d5d

Browse files
felixdoerrebehlendorf
authored andcommitted
libshare: nfs: pass through ipv6 addresses in bracket notation
Recognize when the host part of a sharenfs attribute is an ipv6 Literal and pass that through without modification. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Felix Dörre <[email protected]> Closes: #11171 Closes #11939 Closes: #1894
1 parent ae75a78 commit 9e41d5d

File tree

6 files changed

+126
-8
lines changed

6 files changed

+126
-8
lines changed

lib/libshare/os/linux/nfs.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
180180
{
181181
int error;
182182
const char *access;
183-
char *host_dup, *host, *next;
183+
char *host_dup, *host, *next, *v6Literal;
184184
nfs_host_cookie_t *udata = (nfs_host_cookie_t *)pcookie;
185+
int cidr_len;
185186

186187
#ifdef DEBUG
187188
fprintf(stderr, "foreach_nfs_host_cb: key=%s, value=%s\n", opt, value);
@@ -204,10 +205,46 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
204205
host = host_dup;
205206

206207
do {
207-
next = strchr(host, ':');
208-
if (next != NULL) {
209-
*next = '\0';
210-
next++;
208+
if (*host == '[') {
209+
host++;
210+
v6Literal = strchr(host, ']');
211+
if (v6Literal == NULL) {
212+
free(host_dup);
213+
return (SA_SYNTAX_ERR);
214+
}
215+
if (v6Literal[1] == '\0') {
216+
*v6Literal = '\0';
217+
next = NULL;
218+
} else if (v6Literal[1] == '/') {
219+
next = strchr(v6Literal + 2, ':');
220+
if (next == NULL) {
221+
cidr_len =
222+
strlen(v6Literal + 1);
223+
memmove(v6Literal,
224+
v6Literal + 1,
225+
cidr_len);
226+
v6Literal[cidr_len] = '\0';
227+
} else {
228+
cidr_len = next - v6Literal - 1;
229+
memmove(v6Literal,
230+
v6Literal + 1,
231+
cidr_len);
232+
v6Literal[cidr_len] = '\0';
233+
next++;
234+
}
235+
} else if (v6Literal[1] == ':') {
236+
*v6Literal = '\0';
237+
next = v6Literal + 2;
238+
} else {
239+
free(host_dup);
240+
return (SA_SYNTAX_ERR);
241+
}
242+
} else {
243+
next = strchr(host, ':');
244+
if (next != NULL) {
245+
*next = '\0';
246+
next++;
247+
}
211248
}
212249

213250
error = udata->callback(udata->filename,

man/man8/zfs.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ access for a set of IP addresses and to enable root access for system
545545
on the
546546
.Ar tank/home
547547
file system:
548-
.Dl # Nm zfs Cm set Sy sharenfs Ns = Ns ' Ns Ar rw Ns [email protected]/16,root= Ns Ar neo Ns ' tank/home
548+
.Dl # Nm zfs Cm set Sy sharenfs Ns = Ns ' Ns Ar rw Ns [email protected]/16:[::1],root= Ns Ar neo Ns ' tank/home
549549
.Pp
550550
If you are using DNS for host name resolution,
551551
specify the fully-qualified hostname.

tests/runfiles/linux.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tags = ['functional', 'cli_root', 'zfs_mount']
5353

5454
[tests/functional/cli_root/zfs_share:Linux]
5555
tests = ['zfs_share_005_pos', 'zfs_share_007_neg', 'zfs_share_009_neg',
56-
'zfs_share_012_pos']
56+
'zfs_share_012_pos', 'zfs_share_013_pos']
5757
tags = ['functional', 'cli_root', 'zfs_share']
5858

5959
[tests/functional/cli_root/zfs_sysfs:Linux]

tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dist_pkgdata_SCRIPTS = \
1414
zfs_share_010_neg.ksh \
1515
zfs_share_011_pos.ksh \
1616
zfs_share_012_pos.ksh \
17+
zfs_share_013_pos.ksh \
1718
zfs_share_concurrent_shares.ksh
1819

1920
dist_pkgdata_DATA = \

tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function cleanup {
5151

5252
set -A badopts \
5353
"r0" "r0=machine1" "r0=machine1:machine2" \
54-
"-g" "-b" "-c" "-d" "--invalid" \
54+
"-g" "-b" "-c" "-d" "--invalid" "rw=[::1]a:[::2]" "rw=[::1" \
5555
"$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL\$TESTCTR\$TESTFS1"
5656

5757
log_assert "Verify that invalid share parameters and options are caught."
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright (c) 2020, Felix Dörre
25+
#
26+
27+
. $STF_SUITE/include/libtest.shlib
28+
29+
#
30+
# DESCRIPTION:
31+
# Verify that NFS share options including ipv6 literals are parsed and propagated correctly.
32+
#
33+
34+
verify_runnable "global"
35+
36+
function cleanup
37+
{
38+
log_must zfs set sharenfs=off $TESTPOOL/$TESTFS
39+
is_shared $TESTPOOL/$TESTFS && \
40+
log_must unshare_fs $TESTPOOL/$TESTFS
41+
}
42+
43+
log_onexit cleanup
44+
45+
cleanup
46+
47+
log_must zfs set sharenfs="rw=[::1]" $TESTPOOL/$TESTFS
48+
output=$(showshares_nfs 2>&1)
49+
log_must grep "::1(" <<< "$output" > /dev/null
50+
51+
log_must zfs set sharenfs="rw=[2::3]" $TESTPOOL/$TESTFS
52+
output=$(showshares_nfs 2>&1)
53+
log_must grep "2::3(" <<< "$output" > /dev/null
54+
55+
log_must zfs set sharenfs="rw=[::1]:[2::3]" $TESTPOOL/$TESTFS
56+
output=$(showshares_nfs 2>&1)
57+
log_must grep "::1(" <<< "$output" > /dev/null
58+
log_must grep "2::3(" <<< "$output" > /dev/null
59+
60+
log_must zfs set sharenfs="rw=[::1]/64" $TESTPOOL/$TESTFS
61+
output=$(showshares_nfs 2>&1)
62+
log_must grep "::1/64(" <<< "$output" > /dev/null
63+
64+
log_must zfs set sharenfs="rw=[2::3]/128" $TESTPOOL/$TESTFS
65+
output=$(showshares_nfs 2>&1)
66+
log_must grep "2::3/128(" <<< "$output" > /dev/null
67+
68+
log_must zfs set sharenfs="rw=[::1]/32:[2::3]/128" $TESTPOOL/$TESTFS
69+
output=$(showshares_nfs 2>&1)
70+
log_must grep "::1/32(" <<< "$output" > /dev/null
71+
log_must grep "2::3/128(" <<< "$output" > /dev/null
72+
73+
log_must zfs set sharenfs="rw=[::1]:[2::3]/64:[2a01:1234:1234:1234:aa34:234:1234:1234]:1.2.3.4/24" $TESTPOOL/$TESTFS
74+
output=$(showshares_nfs 2>&1)
75+
log_must grep "::1(" <<< "$output" > /dev/null
76+
log_must grep "2::3/64(" <<< "$output" > /dev/null
77+
log_must grep "2a01:1234:1234:1234:aa34:234:1234:1234(" <<< "$output" > /dev/null
78+
log_must grep "1\\.2\\.3\\.4/24(" <<< "$output" > /dev/null
79+
80+
log_pass "NFS share ip address propagated correctly."

0 commit comments

Comments
 (0)