Skip to content

Commit 4bdbf57

Browse files
committed
libshare: nfs: correctly pass through ipv6 addresses in bracket notation
Closes: #11171, #1894 Signed-off-by: Felix Dörre <[email protected]>
1 parent ca14e08 commit 4bdbf57

File tree

6 files changed

+125
-8
lines changed

6 files changed

+125
-8
lines changed

lib/libshare/os/linux/nfs.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
136136
{
137137
int error;
138138
const char *access;
139-
char *host_dup, *host, *next;
139+
char *host_dup, *host, *next, *v6Literal;
140140
nfs_host_cookie_t *udata = (nfs_host_cookie_t *)pcookie;
141+
int cidr_len;
141142

142143
#ifdef DEBUG
143144
fprintf(stderr, "foreach_nfs_host_cb: key=%s, value=%s\n", opt, value);
@@ -160,10 +161,46 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
160161
host = host_dup;
161162

162163
do {
163-
next = strchr(host, ':');
164-
if (next != NULL) {
165-
*next = '\0';
166-
next++;
164+
if (*host == '[') {
165+
host++;
166+
v6Literal = strchr(host, ']');
167+
if (v6Literal == NULL) {
168+
free(host_dup);
169+
return (SA_SYNTAX_ERR);
170+
}
171+
if (v6Literal[1] == '\0') {
172+
*v6Literal = '\0';
173+
next = NULL;
174+
} else if (v6Literal[1] == '/') {
175+
next = strchr(v6Literal + 2, ':');
176+
if (next == NULL) {
177+
cidr_len =
178+
strlen(v6Literal + 1);
179+
memmove(v6Literal,
180+
v6Literal + 1,
181+
cidr_len);
182+
v6Literal[cidr_len] = '\0';
183+
} else {
184+
cidr_len = next - v6Literal - 1;
185+
memmove(v6Literal,
186+
v6Literal + 1,
187+
cidr_len);
188+
v6Literal[cidr_len] = '\0';
189+
next++;
190+
}
191+
} else if (v6Literal[1] == ':') {
192+
*v6Literal = '\0';
193+
next = v6Literal + 2;
194+
} else {
195+
free(host_dup);
196+
return (SA_SYNTAX_ERR);
197+
}
198+
} else {
199+
next = strchr(host, ':');
200+
if (next != NULL) {
201+
*next = '\0';
202+
next++;
203+
}
167204
}
168205

169206
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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: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 "1\\.2\\.3\\.4/24(" <<< "$output" > /dev/null
78+
79+
log_pass "NFS share ip addresse propagated correctly."

0 commit comments

Comments
 (0)