diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2014-03-17 10:36:01 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2014-03-17 10:37:37 -0400 |
commit | 4663c6481c294838260840d234fec7dfd3186451 (patch) | |
tree | 1558b2a1707766337ae0f50cc04b68b73420d754 /utils/exportfs/exportfs.c | |
parent | ebd488515f534ba8eaf2d91d0451d329e78023f0 (diff) | |
download | nfs-utils-4663c6481c294838260840d234fec7dfd3186451.tar.gz |
exportfs: Support raw IPv6 addresses with "client:/path"
Wrap IPv6 presentation addresses in square brackets. This echoes
the same syntax used when specifying IPv6 server addresses with the
mount.nfs command.
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=817557
Tested-by: Steve Dickson <steved@redaht.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/exportfs/exportfs.c')
-rw-r--r-- | utils/exportfs/exportfs.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index cb81611..bf07555 100644 --- a/utils/exportfs/exportfs.c +++ b/utils/exportfs/exportfs.c @@ -349,12 +349,42 @@ static int exportfs_generic(char *arg, char *options, int verbose) return 0; } +static int exportfs_ipv6(char *arg, char *options, int verbose) +{ + char *path, *c, hname[NI_MAXHOST + strlen("/128")]; + + arg++; + c = strchr(arg, ']'); + if (c == NULL) + return 1; + strncpy(hname, arg, c - arg); + + /* no colon means this is a wildcarded DNS hostname */ + if (strchr(hname, ':') == NULL) + return exportfs_generic(--arg, options, verbose); + + path = strstr(c, ":/"); + if (path == NULL) + return 1; + *path++ = '\0'; + + /* if there's anything between the closing brace and the + * path separator, it's probably a prefix length */ + strcat(hname, ++c); + + exportfs_parsed(hname, path, options, verbose); + return 0; +} + static void exportfs(char *arg, char *options, int verbose) { int failed; - failed = exportfs_generic(arg, options, verbose); + if (*arg == '[') + failed = exportfs_ipv6(arg, options, verbose); + else + failed = exportfs_generic(arg, options, verbose); if (failed) xlog(L_ERROR, "Invalid export syntax: %s", arg); } @@ -426,12 +456,42 @@ static int unexportfs_generic(char *arg, int verbose) return 0; } +static int unexportfs_ipv6(char *arg, int verbose) +{ + char *path, *c, hname[NI_MAXHOST + strlen("/128")]; + + arg++; + c = strchr(arg, ']'); + if (c == NULL) + return 1; + strncpy(hname, arg, c - arg); + + /* no colon means this is a wildcarded DNS hostname */ + if (strchr(hname, ':') == NULL) + return unexportfs_generic(--arg, verbose); + + path = strstr(c, ":/"); + if (path == NULL) + return 1; + *path++ = '\0'; + + /* if there's anything between the closing brace and the + * path separator, it's probably a prefix length */ + strcat(hname, ++c); + + unexportfs_parsed(hname, path, verbose); + return 0; +} + static void unexportfs(char *arg, int verbose) { int failed; - failed = unexportfs_generic(arg, verbose); + if (*arg == '[') + failed = unexportfs_ipv6(arg, verbose); + else + failed = unexportfs_generic(arg, verbose); if (failed) xlog(L_ERROR, "Invalid export syntax: %s", arg); } |