Skip to content

Commit beba464

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 f9bece9 commit beba464

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

lib/libshare/os/linux/nfs.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ 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;
141141

142142
#ifdef DEBUG
@@ -160,7 +160,37 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
160160
host = host_dup;
161161

162162
do {
163-
next = strchr(host, ':');
163+
if (*host == '[') {
164+
host++;
165+
v6Literal = strchr(host, ']');
166+
if (v6Literal == NULL) {
167+
free(host_dup);
168+
return (SA_SYNTAX_ERR);
169+
}
170+
if (v6Literal[1] == '\0') {
171+
*v6Literal = '\0';
172+
next = NULL;
173+
} else if (v6Literal[1] == '/') {
174+
next = strchr(v6Literal + 2, ':');
175+
if (next == NULL) {
176+
memmove(v6Literal,
177+
v6Literal + 1,
178+
strlen(v6Literal + 1));
179+
} else {
180+
memmove(v6Literal,
181+
v6Literal + 1,
182+
next - v6Literal);
183+
}
184+
} else if (v6Literal[1] == ':') {
185+
*v6Literal = '\0';
186+
next = v6Literal + 2;
187+
} else {
188+
free(host_dup);
189+
return (SA_SYNTAX_ERR);
190+
}
191+
} else {
192+
next = strchr(host, ':');
193+
}
164194
if (next != NULL) {
165195
*next = '\0';
166196
next++;

man/man8/zfs.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ on the
549549
.Em tank/home
550550
file system.
551551
.Bd -literal
552-
# zfs set sharenfs='[email protected]/16,root=neo' tank/home
552+
# zfs set sharenfs='[email protected]/16:[::1],root=neo' tank/home
553553
.Ed
554554
.Pp
555555
If you are using

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function cleanup
5252

5353
if is_linux; then
5454
set -A shareopts \
55-
"ro" "rw" "rw,insecure" "rw,async" "ro,crossmnt"
55+
"ro" "rw" "rw,insecure" "rw,async" "ro,crossmnt" "rw=[::1]"
5656
else
5757
set -A shareopts \
5858
"ro" "ro=machine1" "ro=machine1:machine2" \

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."

0 commit comments

Comments
 (0)